[augeas-devel] [PATCH] Add a lens for cron and an associated test.

Raphael Pinson raphink at gmail.com
Wed Apr 8 12:01:54 UTC 2009


---
 lenses/cron.aug            |  142 ++++++++++++++++++++++++++++++++++++++++++++
 lenses/tests/test_cron.aug |   42 +++++++++++++
 2 files changed, 184 insertions(+), 0 deletions(-)
 create mode 100644 lenses/cron.aug
 create mode 100644 lenses/tests/test_cron.aug

diff --git a/lenses/cron.aug b/lenses/cron.aug
new file mode 100644
index 0000000..2d1ec94
--- /dev/null
+++ b/lenses/cron.aug
@@ -0,0 +1,142 @@
+(*
+Module: Cron
+ Parses /etc/cron.d/*, /etc/crontab
+
+Author: Raphael Pinson <raphink at gmail.com>
+
+About: Reference
+ This lens tries to keep as close as possible to `man 5 crontab` where
+ possible.
+
+About: License
+  This file is licensed under the GPL.
+
+About: Lens Usage
+  Sample usage of this lens in augtool
+
+    * Get the identifier of the devices with a "Clone" option:
+      > match "/files/etc/X11/xorg.conf/Device[Option = 'Clone']/Identifier"
+
+About: Configuration files
+  This lens applies to /etc/cron.d/* and /etc/crontab. See <filter>.
+*)
+
+module Cron =
+  autoload xfm
+
+(************************************************************************
+ * Group:                 USEFUL PRIMITIVES
+ *************************************************************************)
+
+(* Group: Generic primitives *)
+
+(* Variable: eol *)
+let eol     = Util.eol
+
+(* Variable: indent *)
+let indent  = Util.indent
+
+(* Variable: comment *)
+let comment = Util.comment
+
+(* Variable: empty *)
+let empty   = Util.empty
+
+(* Variable: num *)
+let num        = /[0-9\*][0-9\/,-\*]*/
+
+(* Variable: alpha *)
+let alpha      = /[A-Za-z]{3}/
+
+(* Variable: alphanum *)
+let alphanum   = num | alpha
+
+
+(* Group: Separators *)
+
+(* Variable: sep_spc *)
+let sep_spc = Util.del_ws_spc
+
+(* Variable: sep_eq *)
+let sep_eq  = Util.del_str "="
+
+
+
+(************************************************************************
+ * Group:                       ENTRIES
+ *************************************************************************)
+
+
+(************************************************************************
+ * View: shellvar
+ *   A shell variable in crontab
+ *************************************************************************)
+
+let shellvar = [ key /[A-Z][A-Za-z0-9]*/ . sep_eq
+                 . Shellvars.simple_value . eol ]
+
+
+(* View: minute *)
+let minute     = [ label "minute"       . store num ]
+
+(* View: hour *)
+let hour       = [ label "hour"         . store num ]
+
+(* View: dayofmonth *)
+let dayofmonth = [ label "dayofmonth" . store num ]
+
+(* View: month *)
+let month      = [ label "month"        . store alphanum ]
+
+(* View: dayofweek *)
+let dayofweek  = [ label "dayofweek"  . store alphanum ]
+
+
+(* View: user *)
+let user       = [ label "user"         . store Rx.word ]
+
+(* View: command *)
+let command    = [ label "command"      . store Rx.space_in ] 
+
+
+(************************************************************************
+ * View: time
+ *   Time in the format "minute hour dayofmonth month dayofweek"
+ *************************************************************************)
+let time        = minute . sep_spc . hour  . sep_spc . dayofmonth
+                         . sep_spc . month . sep_spc . dayofweek
+
+(* Variable: the valid values for schedules *)
+let schedule_re = "reboot" | "yearly" | "annually" | "monthly"
+                | "weekly" | "daily"  | "midnight" | "hourly"
+
+(************************************************************************
+ * View: schedule
+ *   Time in the format "@keyword"
+ *************************************************************************)
+let schedule    = [ label "schedule" . Util.del_str "@"
+                   . store schedule_re ]
+
+
+(************************************************************************
+ * View: entry
+ *   A crontab entry
+ *************************************************************************)
+
+let entry       = [ label "entry" . indent
+                   . ( time | schedule )
+                   . sep_spc . user
+                   . sep_spc . command . eol ]
+
+
+(*
+ * View: lns
+ *   The cron lens
+ *)
+let lns = ( empty | comment | shellvar | entry )*
+
+
+(* Variable: filter *)
+let filter = (incl "/etc/cron.d/*" . incl "/etc/crontab")
+
+let xfm = transform lns filter
diff --git a/lenses/tests/test_cron.aug b/lenses/tests/test_cron.aug
new file mode 100644
index 0000000..fd759e5
--- /dev/null
+++ b/lenses/tests/test_cron.aug
@@ -0,0 +1,42 @@
+module Test_cron =
+
+   let conf = "# /etc/cron.d/anacron: crontab entries for the anacron package
+
+SHELL=/bin/sh
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+
+	30 7      * * *   root	test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null
+  00 */3    15-25/2 May 1-5   user   somecommand
+# a comment
+ at yearly				foo    a command
+"
+
+   test Cron.lns get conf = 
+      { "#comment" = "/etc/cron.d/anacron: crontab entries for the anacron package" }
+      {}
+      { "SHELL" = "/bin/sh" }
+      { "PATH"  = "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" }
+      {}
+      { "entry"
+          { "minute"       = "30"   }
+          { "hour"         = "7"    }
+          { "dayofmonth"   = "*"    }
+          { "month"        = "*"    }
+          { "dayofweek"    = "*"    }
+          { "user"         = "root" }
+          { "command"      = "test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null" } }
+      { "entry"
+          { "minute"       = "00"      }
+          { "hour"         = "*/3"     }
+          { "dayofmonth"   = "15-25/2" }
+          { "month"        = "May"     }
+          { "dayofweek"    = "1-5"     }
+          { "user"         = "user"    }
+          { "command"      = "somecommand" } }
+      { "#comment" = "a comment" }
+      { "entry"
+          { "schedule"     = "yearly"  }
+          { "user"         = "foo"     }
+          { "command"      = "a command" } }
+          
+
-- 
1.5.6.3




More information about the augeas-devel mailing list