Forum: CFEngine Help
Subject: Re: filecopy, transform with grep.
Author: davidlee
Link to topic: https://cfengine.com/forum/read.php?3,22985,23006#msg-23006

Nakarin,

Many thanks for your answer, which I appreciate.  I'll give your suggestion a 
try.

But looking more widely: two points; the first, short but pertinent; the 
second, technical and constituting the remainder of this message.  And both are 
primarily addressed to the developers.

1. How do I sell this to "sceptical but prepared to be convinced if the 
arguments are rock-solid" colleagues?

"Hey, guys, for this one simple, very clear 'grep' all we need is a twenty-two 
line bloat of obscure cfengine-speak."  I would find it hard to make such a 
statement sound convincing.  Who, really, could make a convincing defence of 
the current necessity for such a verbose solution?  (And that solution is 
itself potentially technically flawed: see below.)

2.  I realise that cf-3.1.4 might need such bloat.  But this indicates a design 
flaw in the current cfengine. It seems to have the components, but just hasn't 
thought about gluing them together.  It could get a major improvement, and 
quite easily, by the developers giving a little though to this aspect.

All it needs is a specification like the following to be implemented:
==========
files:
  "/path/to/resultfile"
      create => true,
      transformer_pipe => "/path/to/program  /path/to/sourcefile"; 
==========
Much, much clearer, don't you think?  Four lines instead of twenty-two.   Put 
the two side-by-side and compare for clarity.

"transformer_pipe" (a working name, feel free to think of another) would work 
like "edit_line"/"delete_line"/"insert_line" etc.; it captures its standard 
output as the potential new "resultfile" in a similar way to how "edit_line" 
builds its potential new file; if this potential new "resultfile" differs from 
the original, cfengine updates it, just as "edit_line" would.

Clean, concise; consistent with other parts of cfengine.  No need for any of 
the "do_update" stuff; it's just like "edit_line".  No need for (non-)existence 
checks; the "create" is just as in "copy_from" etc.  No need for all that 
painful stuff about handling an intermediate file (and the potential locking 
problems, race conditions, etc.); use what cfengine already does in "edit_line".

An alternative design might be of the abstract form:
==========
files:
  "/path/to/resultfile"
      create => true,
      transformer => "...";  # almost as existing 'transformer'
      transformer_stdout => {"true"|"false"}; # default "false"; as per 
existing cfengine.
==========
Existing uses of "transformer" would be unchanged.

Our particular "grep" example would become:
==========
files:
  "/path/to/resultfile"
      create => true,
      transformer => "/bin/grep -v $(fq.uqhost)"; # command outputs to STDOUT
      transformer_stdout => "true";  # capture STDOUT as potential new file
==========

(Might there also be a place for a "transformer_stdin"?)

So, how about it?  Is there any reason why such an improvement could be 
considered bad?

_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to