[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [augeas-devel] augtool: exit non-zero on match failure and idempotent inserts



Hi Clemens,

On Fri, 2010-01-15 at 10:01 +0100, Clemens Wehrmann wrote:
> 1. The build instructions at [1] didn't work for me on Ubuntu 9.10:
>   a. in a addition to readline, flex and bison (input fails on byacc) are 
> required when building from git, but neither documented in the instructions, 
> nor the configure script.

The instructions in the README are meant for building from a released
tarball - I will add a separate HACKING file to describe building from a
git checkout, where you do need those additional tools. (I'll attach
that file, too)

>   b. The gnulib-tool --lgpl=2 check in the bootstrap script fails on langinfo 
> (see [2])

That was an issue with gnulib that got fixed yesterday. So if you try
with an updated gnulib checkout, things will work now.

> 2. I would expect to be able to use "augtool match" as a more syntax-aware 
> "grep -q" replacement, but this is hampered because augtool does not allow 
> detection of match failure via the exit status like grep, one must awkwardly 
> parse the "  (no matches)" output designed more for human consumption.

Yeah, augtool isn't perfect for this, and the exit code for augtool
really only tells you if something went catastrophically wrong (like
running out of memory) It's not clear to me how augtool should react if
you issue multiple commands, e.g. by piping htem in from a file, and
some of them fail and some succeed.

I never really thought about using augtool as a structured grep, but I
like the idea a lot. How about writing a separate, specialized tool, say
augmatch for that purpose ? It would be much simpler than augtool, since
it wouldn't be interactive. I am thinking of something along the lines
of

        augmatch OPTIONS PATHEXPR
        
        Print all matches for PATHEXPR. The output consists of a path
        and the value of the corresponding node.
        
        OPTIONS
          -I DIR     search DIR for lenses
          -r ROOT    use ROOT as the filesystem root
          -l LENS    only use LENS
          -i GLOB    apply LENS to files matching GLOB
          -e GLOB    do not use LENS on files matching GLOB
          -q         print nothing, return 0 if at least one match, return 1 if no match
          -n         set the exit code to the number of matches

The main purpose of the -l/-i/-e options is to make startup fast - when
augtool starts without any options, it loads every file it knows about,
which can be unnecessarily slow. Being specific about which files you're
interested in avoids that overhead.

> 3. I would expect saving of a node without a lens to fail or yield an error, 
> but it doesn't: [3].

Yes, that is a bug. Can you file a bug in Trac[1] for it ?

> 4. Using augtool from scripts really requires a significant wrapper to handle 
> the frequent use case of idempotently adding a line:
>   * add a node (subtree) if it doesn't exist
>   * do nothing if it exists with the same values as set
>   * if an exiting node exists with deviating values complain and abort or, if 
> requested, set the values to the desired state.
>   * handle errors reliably

Yes, I'd be very interested in having any of the above in augtool. I
think to really support idempotent changes, augtool will need to support
an if statement; in general, you will make multiple changes if something
in the tree isn't what you expect (e.g., if there's no entry
in /etc/hosts for 192.168.0.1, you'll want to add several nodes)

I am thinking of a syntax like

        if PATHEXPR then
          .. statements (one per line) ..
        else
          .. statements ..
        end
        
So far, I've been thinking that people should just use their favorite
language (Python, Ruby, ...) to get that functionality, but I think it
makes sense to add that.

> Would the maintainers entertain a patch to add such functionality to augtool?

Yes, I would love patches for that.

David

[1] https://fedorahosted.org/augeas/report




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]