195
200
return True, "ok"
198
#TODO merge code of append and update
199
def append (self, runat, command, title, icon):
203
def append(self,job):
204
if not isinstance(job, Job):
205
raise Exception("Job should be an instance of Job")
200
206
tmpfile = tempfile.mkstemp ()
201
207
fd, path = tmpfile
202
208
tmp = os.fdopen(fd, 'w')
204
tmp.write("TITLE=" + title + "\n")
209
tmp.write(self.startLine)
211
tmp.write("TITLE=" + job.title + "\n")
206
213
tmp.write("TITLE=Untitled\n")
208
tmp.write("ICON=" + icon + "\n")
215
tmp.write("ICON=" + job.icon + "\n")
210
217
tmp.write("ICON=None\n")
212
tmp.write (command + "\n")
219
tmp.write (job.command + "\n")
218
if self.user != "root":
219
#changes the ownership
220
os.chown(path, self.uid, self.gid)
221
execute = config.getSubin() + " " + self.user + " -c \"" + config.getAtbin() + " " + runat + " -f " + path + " && exit\""
222
temp = commands.getoutput(execute)
224
execute = config.getAtbin() + " " + runat + " -f " + path
225
temp = commands.getoutput(execute)
227
execute = config.getAtbin() + " " + runat + " -f " + path
228
temp = commands.getoutput(execute)
224
runat = self.__convertdatetoAt(job.date)
229
if self.root == 1 and self.user != "root":
230
#changes the ownership
231
os.chown(path, self.uid, self.gid)
232
exec_pre = config.getSubin() + " " + self.user + " -c \""
233
exec_post = " && exit\""
235
execute = exec_pre + config.getAtbin() + " " + runat + " -f " + path + exec_post
236
temp = commands.getoutput(execute)
234
def update (self, job_id, runat, command, title, icon):
241
def update (self, job):
243
Update a job in the scheduler
244
@param runat: see the format in here /usr/share/doc/at/timespec.
246
if not isinstance(job, Job):
247
raise Exception("Job should be an instance of Job")
236
execute = config.getAtrmbin() + " " + str(job_id)
237
commands.getoutput(execute)
240
tmpfile = tempfile.mkstemp ()
242
tmp = os.fdopen(fd, 'w')
244
tmp.write("TITLE=" + title + "\n")
246
tmp.write("TITLE=Untitled\n")
248
tmp.write("ICON=" + icon + "\n")
250
tmp.write("ICON=None\n")
251
tmp.write (command + "\n")
255
if self.user != "root":
256
#changes the ownership
257
os.chown(path, self.uid, self.gid)
258
execute = config.getSubin() + " " + self.ParentClass.user + " -c \"" + config.getAtbin() + " " + runat + " -f " + path + " && exit\""
259
temp = commands.getoutput(execute)
262
execute = config.getAtbin() + " " + runat + " -f " + path
263
temp = commands.getoutput(execute)
268
def delete (self, jobid, iter):
270
execute = config.getAtrmbin()+ " " + str(jobid)
254
def delete (self, job):
255
if not isinstance(job, Job):
256
raise Exception("Job should be an instance of Job")
258
execute = config.getAtrmbin()+ " " + str(job.id)
271
259
commands.getoutput(execute)
300
def __convertdatetoAt(self,date):
302
@param date: the date in the time format
304
@return: the date in at format
307
if not isinstance(date, datetime) :
308
raise Exception("date should be a time object")
309
at_format = str(date.hour)+":"+str(date.minute)+" "+str(date.month)+"/"+str(date.day)+"/"+str(date.year)
312
313
def __prepare_script__ (self, script):
314
315
# It looks like at prepends a bunch of stuff to each script