def update_cron_click(self, e):
#make a text file of all the cron jobs
cron_text = ''
startup_num = cron_list_pnl.startup_cron.GetItemCount()
for num in range(0, startup_num):
cron_line = ''
if cron_list_pnl.startup_cron.GetItemText(num, 1) == 'False':
cron_line += '#'
cron_line += '@reboot ' + cron_list_pnl.startup_cron.GetItemText(num, 3) # cron_task
cron_line += ' ' + cron_list_pnl.startup_cron.GetItemText(num, 4) # cron_extra_args
cron_line += ' ' + cron_list_pnl.startup_cron.GetItemText(num, 5) # cron_comment
cron_text += cron_line + '\n'
repeat_num = cron_list_pnl.repeat_cron.GetItemCount()
for num in range(0, repeat_num):
cron_line = ''
if cron_list_pnl.repeat_cron.GetItemText(num, 1) == 'False':
cron_line += '#'
cron_line += cron_list_pnl.repeat_cron.GetItemText(num, 2).strip(' ')
cron_line += ' ' + cron_list_pnl.repeat_cron.GetItemText(num, 3) # cron_task
cron_line += ' ' + cron_list_pnl.repeat_cron.GetItemText(num, 4) # cron_extra_args
cron_line += ' ' + cron_list_pnl.repeat_cron.GetItemText(num, 5) # cron_comment
cron_text += cron_line + '\n'
onetime_num = cron_list_pnl.timed_cron.GetItemCount()
for num in range(0, onetime_num):
cron_line = ''
if cron_list_pnl.timed_cron.GetItemText(num, 1) == 'False':
cron_line += '#'
cron_line += cron_list_pnl.timed_cron.GetItemText(num, 2).strip(' ')
cron_line += ' ' + cron_list_pnl.timed_cron.GetItemText(num, 3) # cron_task
cron_line += ' ' + cron_list_pnl.timed_cron.GetItemText(num, 4) # cron_extra_args
cron_line += ' ' + cron_list_pnl.timed_cron.GetItemText(num, 5) # cron_comment
cron_text += cron_line + '\n'
# ask the user if they're sure
msg_text = "Update cron to; \n\n" + cron_text
mbox = wx.MessageDialog(None, msg_text, "Are you sure?", wx.YES_NO|wx.ICON_QUESTION)
sure = mbox.ShowModal()
if sure == wx.ID_YES:
print "Updating remote cron"
# save cron text onto pigrow as text file then import into cron
sftp = ssh.open_sftp()
try:
tempfolder = '/home/pi/Pigrow/temp'
sftp.mkdir(tempfolder)
except IOError:
pass
f = sftp.open(tempfolder + '/remotecron.txt', 'w')
f.write(cron_text)
f.close()
try:
stdin, stdout, stderr = ssh.exec_command("crontab " + tempfolder + '/remotecron.txt')
responce = stdout.read()
error = stderr.read()
print responce, error
except Exception as e:
print("this ain't right, it just ain't right! " + str(e))
else:
print("Updating cron cancelled")
mbox.Destroy()
#refresh cron list
self.read_cron_click("event")
评论列表
文章目录