Parsing the crontab (the regular expression) and writing it

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

 



I there Gaute (and the people on the fedora-config list),

I fixed the regular expression. It now matches for example this one
correctly (which is of course just a meaningless test):

* * * * * echo `date`; echo "test" 2> /var/log/all # New scheduled task


This is the regular expression that I am using:

'([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s([^#\n$]*)(\s#\s([^\n$]*)|$)'

I read it as:

- group the five first white-space delimited fields. These fields
represent what we will call the Frequency. And we will try to parse that
to a simple string like "Every minute", "Every day". if that parsing
fails we will show the "Advanced" view which is just a simple
concatenation of the fields with spaces between them. When the
"Advanced" check in the menus is checked, we will always show that
"Advanced" view...as in that case we assume that a Unix wizard is using
the application (and a Unix wizards doesn't what to see the simplified
strings, I guess).

	([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)


- group a field. The field ends when a # or a \n or the last character
of the line is matched. This is what we will call the command.

	\s([^#\n$]*)


- Optionally group a field that is being prefixed by '\s#\s' and that
ends when a \n or the last character of the line is matched. This is
what we will call the Title.

	(\s#\s([^\n$]*)|$)


Gaute, I have also fixed writing the crontab. When the Ok button in the
addWindow.py is used, it will call or the appendLine or the updateLine
metods of our crontab-class. These methods will sync the inmemory and
the ondisk version of our configuration.

I have decided not to use a pipe for the writing. The simple reason is,
like you told me, that when you are editing the crontab of another user
(as root), piping the new crontab into the 'crontab' command just
doesn't work.

So using mkstemp(), which is a method to create a secure temporary file,
I am creating a temporary file and writing our inmemory-version to it.
Then I use that to create a command (crontab -u username tempfile) and I
start the command using os.system (command).

I do this on every single change. This is default behavior of the GNOME
desktop (to commit configuration changes asap). I do know that we are
not using gconf and perhaps it's not a good idea in that case, still I
think that it's best to commit every change asap...to be consistent with
the rest of the GNOME desktop. If our code is correct, it should not
make stuff invalid. It doesn't matter if we write it once or one
thousand times, the 1001th time it still should be correct. Duh.

This renders correctness of the regular expression very important.


ps. I am sending this to the Fedora Config list too, so that maybe other
people can share idea's on this rather difficult issue (the crontab
regular expression). I can imagine that others have written regular
expressions to parse the crontab in a previous life. I would like to
hear about that :p, if possible. ps. I don't think it's offtopic to use
this list for development-communication of system-config-schedule? Or is
it?


All this is in CVS and available for your coding and reviewing pleasure.



On Tue, 2004-06-08 at 10:26 +0200, Philip Van Hoof wrote:
> On Mon, 2004-06-07 at 19:10 +0200, Philip Van Hoof wrote:
> > We have set up our own temporary location (as we really do need a CVS
> > service asap). We can backup/restore the repository once a better
> > location is ready.
> > 
> > http://cvs.freax.be/cgi-bin/cvsweb/system-config-schedule/
> > 
> > I have not set-up an anonymous login (nor will) for the simple reason:
> > security of my own server.
> 
> For people who are interested in the package and want to test it ASAP,
> my current viewcvs.cgi-setup will allow you to create a tar.gz package
> of the module:
> 
> http://cvs.freax.be/cgi-bin/viewcvs.cgi/system-config-schedule/system-config-schedule.tar.gz?tarball=1
> 
> > Note to people on the list: You can ask me for an account if you want to
> > contribute very soon.
> 
> ps. I did the same for the system-config-samba changes (bug 110804 on
> bugzilla.redhat.com) I recently made:
> 
> http://cvs.freax.be/cgi-bin/viewcvs.cgi/system-config-samba/system-config-samba.tar.gz?tarball=1
> 
> 
> Have fun
> 
> 
> 
> -- 
> Philip Van Hoof, Software Developer @ Cronos
> home: me at freax dot org
> work: Philip dot VanHoof at cronos dot be
> http://www.freax.be, http://www.freax.eu.org
> 
> 
-- 
Philip Van Hoof, Software Developer @ Cronos
home: me at freax dot org
work: Philip dot VanHoof at cronos dot be
http://www.freax.be, http://www.freax.eu.org


-- 
Fedora-config-list mailing list
Fedora-config-list@xxxxxxxxxx
http://www.redhat.com/mailman/listinfo/fedora-config-list

[Index of Archives]     [Fedora Users]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Big List of Linux Books]     [Gimp]     [Yosemite News]