def __write__ (self): tmpfile = tempfile.mkstemp () fd, path = tmpfile tmp = os.fdopen(fd, 'w') count = 0 for line in self.lines: ## Ignore the first three comments: ## DO NOT EDIT THIS FILE - edit the master and reinstall. ## (/tmp/crontab.XXXXXX installed on Xxx Xxx x xx:xx:xx xxxx) ## (Cron version -- $Id$) if not (count < 3 and len(line) > 1 and line[0] == "#"): tmp.write (line) if line[len(line)-1] != '\n': tmp.write ("\n") count = count + 1 tmp.close () #replace crontab config with new one in file if self.root: # print config.getCrontabbin () + " -u " + self.ParentClass.user + " " + path os.system (config.getCrontabbin () + " " + path + " -u " + self.user) else: # print config.getCrontabbin () + " " + path os.system (config.getCrontabbin () + " " + path) os.unlink (path)
def read(self, easy=True): data = [] if self.root: execute = config.getCrontabbin() + " -l -u " + self.user else: execute = config.getCrontabbin() + " -l" linecount = 0 self.lines = os.popen(execute).readlines() for line in self.lines: #read line and get info array_or_false = self.parse(line) if array_or_false != False: if array_or_false[0] == 2: (minute, hour, day, month, weekday, command, comment, job_id, title, desc, output, display) = array_or_false[1] time = minute + " " + hour + " " + day + " " + month + " " + weekday #make the command smaller if the lenght is to long preview = self.__make_preview__(command) #add task to treemodel in mainWindow if easy: easy_s = self.__easy__(minute, hour, day, month, weekday) else: easy_s = "" if minute == "@reboot": data.append([ title, easy_s, preview, line, linecount, time, self, None, job_id, "", "", "", _("Recurrent"), "crontab", output, _("At reboot") ]) else: data.append([ title, easy_s, preview, line, linecount, time, self, None, job_id, "", "", "", _("Recurrent"), "crontab", output, time ]) linecount = linecount + 1 return data
def read (self, easy = True): data = [] if self.root: execute = config.getCrontabbin () + " -l -u " + self.user else: execute = config.getCrontabbin () + " -l" linecount = 0 self.lines = os.popen(execute).readlines() for line in self.lines: #read line and get info array_or_false = self.parse (line) if array_or_false != False: if array_or_false[0] == 2: (minute, hour, day, month, weekday, command, comment, job_id, title, desc, output, display) = array_or_false[1] time = minute + " " + hour + " " + day + " " + month + " " + weekday #make the command smaller if the lenght is to long preview = self.__make_preview__ (command) #add task to treemodel in mainWindow if easy: easy_s = self.__easy__ (minute, hour, day, month, weekday) else: easy_s = "" if minute == "@reboot": data.append([title, easy_s , preview, line, linecount, time, self, None, job_id, "", "","", _("Recurrent"), "crontab", output, _("At reboot")]) else: data.append([title, easy_s, preview, line, linecount, time, self, None, job_id, "", "","", _("Recurrent"), "crontab", output, time]) linecount = linecount + 1 return data