cfengine-develop
[Top][All Lists]
Advanced

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

Re: [Cfengine-develop] Re: Homework


From: Andrew Stribblehill
Subject: Re: [Cfengine-develop] Re: Homework
Date: Wed, 5 Mar 2003 10:24:17 +0000
User-agent: Mutt/1.5.3i

Quoting Bas van der Vlies <address@hidden> (2003-03-04 08:21:57 GMT):
> I agree with Martin. I do not want a perl language with all kind of
> special chars to tell what kind of variable it is. It make the cfengine
> code less readable. I just trying it to avoid this style of programming 
> ;-). If we want to use arrays/list we must say that this variable is a 
> list. We can invent our own language (Like Chris suggested) or use the
> python style for lists (I am also a python programmer).

Zope has a <dtml-over> tag for iteration over a list, and <dtml-with>
to put an associative array into the current namespace. It is used
thus:

<dtml-over "mySimpleList">
  <a href="&dtml-item;">This item</a>
</dtml-over>

<dtml-over "myListOfDicts">
  <dtml-with "item">
    <a href="&dtml-webpage;">&dtml-description;</a>
  </dtml-with>
</dtml-over>


By analogy, Cfengine could have something like this:

control:
  rootCrontabs = [ { minute="05" command="gratuitousMonitor" },
                   { minute="10" command="pkill gratuitousMonitor" } ]

editfiles:
  linux::
    over rootCrontabs
      with item
        { /etc/cron.d/local
          AppendIfNoSuchLine "$(minute) * * * * root $(command)"
        }

Thinking about implementation details just for a moment, the 'over'
and 'with' keywords would overlay a namespace onto the base one so
you'd have:

namespace of 'item'
namespace of rootCrontabs which contains 'item' and maybe 'itemNumber'
base namespace (contains, for ecample, sysadm)

in order of visibility. This is also pleasant because if, for
example, you didn't want to define some properties for some
associative arrays, you could just use the default one lower down the
namespace stack:


control:
  minute = "10"
  hour = "*"
  day = "*"
  month = "*"
  dow = "*"
  user = "root"
  rootCrontabs = [ { command="hello" },
                   { minute="13" command="goodbye"}

editfiles:
  linux::
    over rootCrontabs with item
      { /etc/cron.d/local
      AppendIfNoSuchLine "$(minute) $(hour) $(day) $(month) ". \
        "$(dow) $(user) $(command)"
      }

Something else we need to look at is string interpolation. How to
stop it happening, how to cause it to be interpolated multiple times?

Perl has '' to mean don't interpolate; Python allows either '' or ""
and doesn't interpolate unless you give it an associative array to
work on, i.e.
  "Charlie had %(num) pigeon%(plural)" % {num="1", plural=""}

-- 
VIKING NORTH UTSIRE SOUTH UTSIRE FORTIES
SOUTHEAST 7 TO SEVERE GALE 9, OCCASIONALLY STORM 10 IN VIKING,
VEERING MAINLY SOUTH 5 TO 7. RAIN. MODERATE OR POOR, BECOMING GOOD
LATER




reply via email to

[Prev in Thread] Current Thread [Next in Thread]