33
The crontab manager class . It's designated to be instanciated for a certain user and group
31
36
def __init__(self,root,user,uid,gid):
38
@param root: 0 if the user is not root, 1 otherwise
39
@param user: The user name ( in string ) use pwd module to get those infos (userdb = pwd.getpwnam(user) )
32
44
#default preview length
33
45
self.preview_len = 50
89
101
def get_type (self):
103
@return: the string "crontab"
92
107
def checkfield (self, expr, type):
93
"""Verifies format of Crontab timefields
109
Verifies format of Crontab timefields
95
111
Checks a single Crontab time expression.
96
112
At first possibly contained alias names will be replaced by their
172
188
self.__write__ ()
175
def delete (self, linenumber, iter):
191
def delete (self, linenumber):
193
Delete a crontab entry by line number
194
@param linenumber: the linenumber to delete
177
197
newlines = list ()
178
198
for line in self.lines:
188
208
def append (self, minute, hour, day, month, weekday, command, nooutput, title, icon = None):
210
The method to add an entry to crontab (see man 5 crontab )
216
@param command: The command to execute
217
@param nooutput: True if we don't want any output (False for normal behaviour)
218
@param title: The title of the task (might be used for a search )
219
@param icon: an icon path to associate
189
222
record = minute + " " + hour + " " + day + " " + month + " " + weekday + " " + command
204
237
# TODO: let write trow an exception if failed
205
238
self.__write__ ()
208
#read tasks in crontab
241
def humanRead(self,title=None):
243
Return the task list in a human readable form
244
@param title: a regexp that should match the title of the tasks to get, if title is None every thing is return
246
@return: an array with the list of corresponding tasks [linenumber, title, human_readable_string, command]
248
datas = self.read(title)
250
d[2] = self.__easy__(d[2][0],d[2][1],d[2][2],d[2][3],d[2][4])
255
#read tasks in crontab
256
def read (self,t_title=None):
258
Return the task list in a human readable form
259
@param title: a regexp that should match the title of the tasks to get, if title is None every thing is return
261
@return: an array with the list of corresponding tasks [[linenumber, title, (minute, hour, day, month, weekday), command], ]
264
r = re.compile(t_title)
268
execute = config.getCrontabbin () + " -l -u " + self.user
270
execute = config.getCrontabbin () + " -l"
273
self.lines = os.popen(execute).readlines()
274
for line in self.lines:
275
#read line and get info
276
cron_infos = self.parse (line)
278
(minute, hour, day, month, weekday, command, title, icon) = cron_infos
282
if m : data.append([linecount,title, (minute, hour, day, month, weekday),command])
284
data.append([linecount,title, (minute, hour, day, month, weekday),command])
290
#read tasks in crontab
291
def legacy_read (self):
257
339
#get info out of task line
258
340
def parse (self, line):
342
min hour day month wday command comment/title-icon or end
343
The regexp: ('([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s([^#\n$]*)(\s#\s([^\n$]*)|$)')
344
A record: * * * * * echo $a >/dev/null 2>&1 # Untitled, /usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png
346
Parse a crontab line and return it as a tuple
347
@param line: The crontab line
348
@return: (minute, hour, day, month, weekday, command, title, icon) or None for empty line and comment
349
@raise Exception: if the line is neither a comment nor empty and is invalid
259
351
if len (line) > 1 and line[0] != '#':
261
min hour day month wday command comment/title-icon or end
262
The regexp: ('([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s([^#\n$]*)(\s#\s([^\n$]*)|$)')
263
A record: * * * * * echo $a >/dev/null 2>&1 # Untitled, /usr/share/icons/gnome/48x48/mimetypes/gnome-mime-application.png
265
353
m = self.crontabRecordRegex.match(line)
267
355
#print m.groups()
291
379
return minute, hour, day, month, weekday, command, title, icon
294
print _("ERROR: Failed to parse crontab record")
296
# TODO: throw exception
382
raise Exception( _("ERROR: Failed to parse crontab record : [ %s ]") % line)
299
388
def __easy__ (self, minute, hour, day, month, weekday):