Commit 14abdcee authored by Gaute Hope's avatar Gaute Hope

remove trailing whitespaces

parent e0b8db2e
2009-07-09 Gaute Hope <eg@gaute.vetsj.com>
* Bug 588091: By Paul Hodges <phodeges4@gmail.com>: Make sure return
types are correct in get_job_data of crontab.py
* Remove trailing whitespaces
2009-07-08 Gaute Hope <eg@gaute.vetsj.com>
* Bug 588091: By Paul Hodges <phodges4@gmail.com>: make sure display,
......
......@@ -33,7 +33,7 @@ import config
class At:
def __init__(self,root,user,uid,gid,user_home_dir,manual_poscorrect):
#default preview length
self.preview_len = 50
self.root = root
......@@ -49,17 +49,17 @@ class At:
# 3 Tue May 8 01:01:00 2007 a gaute
self.atRecordRegex = re.compile('^([\d]+)[\t]([\w]{3,3})[\s]([\w]{3,3})[\s]*([\d]+)[\s]([\d]{2,2}[:][\d]{2,2}[:][\d]{2,2})[\s]([\d]{4,4})[\s]([\w])[\s]([\w]+)')
# after you add a job, this line is printed to stderr
# job 10 at 2006-09-18 12:38
self.atRecordRegexAdd = re.compile('^job\s([0-9]+)\sat')
self.atRecordRegexAdded = re.compile('[^\s]+\s([0-9]+)\sat')
self.SCRIPT_DELIMITER = "###### ---- GNOME_SCHEDULE_SCRIPT_DELIMITER #####"
self.DISPLAY = "DISPLAY=%s; export DISPLAY;\n"
self.DISPLAY = self.DISPLAY + "XAUTHORITY=" + user_home_dir + "/.Xauthority; export XAUTHORITY;\n"
self.DISPLAY = self.DISPLAY + "XAUTHORITY=" + user_home_dir + "/.Xauthority; export XAUTHORITY;\n"
self.DISPLAY = self.DISPLAY + config.xwrapper_exec + " a\n"
self.DISPLAY = self.DISPLAY + """
xwrapper=$?;
......@@ -71,11 +71,11 @@ else
fi
"""
# If normally this variable is unset the user would not expect it
# If normally this variable is unset the user would not expect it
# to be set, which it will be because Gnome Schedule needs it.
# Therefore we unset it in the script.
# Therefore we unset it in the script.
self.POSIXLY_CORRECT_UNSET = "unset POSIXLY_CORRECT\n"
self.atdatafileversion = 5
self.atdata = self.user_home_dir + "/.gnome/gnome-schedule/at"
if os.path.exists (self.user_home_dir + "/.gnome") != True:
......@@ -89,7 +89,7 @@ fi
os.chown (self.atdata, self.uid, self.gid)
except:
print _("Failed to create data dir! Make sure ~/.gnome and ~/.gnome/gnome-schedule are writable.")
self.months = {
'Jan' : '1',
'Feb' : '2',
......@@ -104,7 +104,7 @@ fi
'Nov' : '11',
'Dec' : '12'
}
def set_rights(self,user,uid,gid, ud):
self.user = user
self.uid = uid
......@@ -123,36 +123,36 @@ fi
except:
print (_("Failed to create data dir: %s. Make sure ~/.gnome and ~/.gnome/gnome-schedule are writable.") % (self.atdata))
def get_type (self):
return "at"
def parse (self, line, output = True):
if (output == True):
if len (line) > 1 and line[0] != '#':
m = self.atRecordRegex.match(line)
if m != None:
if m != None:
# Time
time = m.groups ()[4][:-3]
# Date
day = m.groups ()[3]
month = m.groups ()[2]
for monthname in self.months:
month = month.replace (monthname, self.months[monthname])
if int (day) < 10:
day = "0" + day
if int (month) < 10:
month = "0" + month
date = day + "." + month + "." + m.groups ()[5]
job_id = m.groups ()[0]
class_id = m.groups ()[6]
user = m.groups ()[7]
success, title, desc, manual_poscorrect, output, display = self.get_job_data (int (job_id))
# manual_poscorrect is only used during preparation of script
......@@ -160,11 +160,11 @@ fi
# read lines and detect starter
script = os.popen(execute).read()
script, dangerous = self.__prepare_script__ (script, manual_poscorrect, output, display)
#removing ending newlines, but keep one
#if a date in the past is selected the record is removed by at, this creates an error, and generally if the script is of zero length
# TODO: complain about it as well
if len(script) < 2:
done = 1
else:
......@@ -177,7 +177,7 @@ fi
done = 1
return job_id, date, time, class_id, user, script, title, dangerous, output
elif (output == False):
if len (line) > 1 and line[0] != '#':
m = self.atRecordRegexAdd.search(line)
......@@ -198,7 +198,7 @@ fi
if os.access (f, os.R_OK):
fh = open (f, 'r')
d = fh.read ()
ver_p = d.find ("ver=")
if ver_p == -1:
ver = 1
......@@ -206,18 +206,18 @@ fi
ver_s = d[ver_p + 4:d.find ("\n")]
d = d[d.find ("\n") + 1:]
ver = int (ver_s)
title = d[6:d.find ("\n")]
d = d[d.find ("\n") + 1:]
# icons out
if ver < 2:
icon = d[5:d.find ("\n")]
d = d[d.find ("\n") + 1:]
desc = d[5:d.find ("\n")]
d = d[d.find ("\n") + 1:]
manual_poscorrect_b = False
if ver > 2:
manual_poscorrect = d[18:d.find ("\n")]
......@@ -226,7 +226,7 @@ fi
manual_poscorrect_b = True
elif manual_poscorrect == "false":
manual_poscorrect_b = False
if ver >= 5:
output_str = d[7:d.find ("\n")]
output = int (output_str)
......@@ -243,12 +243,12 @@ fi
display = ""
fh.close ()
return True, title, desc, manual_poscorrect_b, output, display
else:
else:
return False, "", "", False, 0, ""
def write_job_data (self, job_id, title, desc, output, display):
# Create and write data file
f = os.path.join (self.atdata, str(job_id))
......@@ -258,7 +258,7 @@ fi
fh.write ("ver=" + str(self.atdatafileversion) + "\n")
fh.write ("title=" + title + "\n")
fh.write ("desc=" + desc + "\n")
# This one doesn't need to be passed independently for each job since the job data is only updated together with a task being appended or updated (also new added), and the variable depends on each session. Not job.
if self.manual_poscorrect == True:
fh.write ("manual_poscorrect=true\n")
......@@ -271,12 +271,12 @@ fi
fh.close ()
os.chown (f, self.uid, self.gid)
os.chmod (f, 0600)
def checkfield (self, runat):
regexp1 = re.compile ("([0-9][0-9])([0-9][0-9])\ ([0-9][0-9])\.([0-9][0-9])\.([0-9][0-9][0-9][0-9])")
regexp2 = re.compile("([0-9][0-9])([0-9][0-9])")
regexp3 = re.compile("([0-9][0-9])\.([0-9][0-9])\.([0-9][0-9][0-9][0-9])")
runat_g1 = regexp1.match(runat)
runat_g2 = regexp2.match(runat)
runat_g3 = regexp3.match(runat)
......@@ -286,7 +286,7 @@ fi
cday = ctime[2]
chour = ctime[3]
cminute = ctime[4]
if runat_g1:
(hour, minute, day, month, year) = runat_g1.groups()
hour = int(hour)
......@@ -297,20 +297,20 @@ fi
if hour > 24 or hour < 0:
return False, "hour"
if minute > 60 or minute < 0:
return False, "minute"
if month > 12 or month < 0:
return False, "month"
if day > 31 or day < 0:
return False, "day"
if year < 0:
return False, "year"
if year >= cyear:
if year >= cyear:
if year == cyear:
syear = True
if (month >= cmonth):
......@@ -348,7 +348,7 @@ fi
minute = int(minute)
if hour > 24 or hour < 0:
return False, "hour"
if minute > 60 or minute < 0:
return False, "minute"
......@@ -369,14 +369,14 @@ fi
else:
#lowercase
runat = runat.lower()
#some timespecs:
days = ['sun','mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sunday','monday','tuesday','wednesday','thursday','friday','saturday']
relative_days = ['tomorrow','next week','today']
relative_hour = ['noon','teatime','midnight','next hour']
relative_minute = ['next minute']
relative_month = ['next month']
if runat in days:
pass
elif runat in relative_days:
......@@ -392,7 +392,7 @@ fi
return True, "ok"
def append (self, runat, command, title, output):
tmpfile = tempfile.mkstemp ()
fd, path = tmpfile
......@@ -405,10 +405,10 @@ fi
if output > 0:
display = os.getenv ('DISPLAY')
tmp.write (self.DISPLAY % display )
tmp.write (command + "\n")
tmp.close ()
temp = None
if self.root == 1:
......@@ -431,12 +431,12 @@ fi
t = self.parse (line, False)
if t != False:
job_id = t
#print job_id
desc = ""
self.write_job_data (job_id, title, desc, output, display)
os.unlink (path)
......@@ -448,7 +448,7 @@ fi
os.unlink (f)
execute = config.getAtrmbin()+ " " + str(job_id)
commands.getoutput(execute)
#add new
tmpfile = tempfile.mkstemp ()
fd, path = tmpfile
......@@ -485,14 +485,14 @@ fi
t = self.parse (line, False)
if t != False:
job_id = t
#print job_id
desc = ""
self.write_job_data (job_id, title, desc, output, display)
os.unlink (path)
def delete (self, job_id, iter):
if job_id:
......@@ -502,38 +502,38 @@ fi
os.unlink (f)
execute = config.getAtrmbin()+ " " + str(job_id)
commands.getoutput(execute)
def read (self):
data = []
#do 'atq'
execute = config.getAtqbin ()
self.lines = os.popen(execute).readlines()
for line in self.lines:
array_or_false = self.parse (line)
#print array_or_false
if array_or_false != False:
(job_id, date, time, class_id, user, lines, title, dangerous, output) = array_or_false
preview = self.__make_preview__ (lines)
if dangerous == 1:
preview = _("Warning! Unknown task: %(preview)s") % {'preview': preview}
#chopping of script delimiter
lines.strip ()
timestring = "%s %s" % (date, time)
date_o = datetime.datetime.strptime (date + " " + time, "%d.%m.%Y %H:%M")
timestring_show = _("On %(timestring)s") % { 'timestring' : date_o.strftime ("%c") }
# TODO: looks like it could be one append
if self.root == 1:
if self.user == user:
data.append([title, timestring_show, preview, lines, int(job_id), timestring, self, None, date, class_id, user, time, _("Once"), "at", output, timestring])
else:
else:
#print "Record omitted, not current user"
pass
else:
......@@ -541,12 +541,12 @@ fi
#print _("added %(id)s") % { "id": job_id }
else:
print _("Warning: a line in atq's output didn't parse")
print _("Warning: a line in atq's output didn't parse")
return data
def __prepare_script__ (self, script, manual_poscorrect, output, display):
# It looks like at prepends a bunch of stuff to each script
# Luckily it delimits that using two newlines
# So assuming that at never prepends two newlines unless
......@@ -554,7 +554,7 @@ fi
# once the first two lines have been found
# Later: It now seems like this is incorrect, and may vary upon distribution. I therefore determine the prepended stuff by making a test job and then removing the length of it. in gentoo it adds to newlines at the end of the script
# If the script is created by Gnome Schedule the script is seperated by a delimiter.
dangerous = 0
......@@ -593,15 +593,15 @@ fi
else:
title = "Untitled"
# If the string contains ICON=
iconstart = script.find ("ICON=")
iconstart = script.find ("ICON=")
if iconstart != -1:
iconend = script.find ("\n", iconstart)
icon = script[(iconstart + 5):iconend]
prelen = prelen + len(icon) + 6
else:
icon = None
icon = None
script = script[prelen:]
......@@ -644,4 +644,4 @@ fi
result = result + "..."
return result
......@@ -39,11 +39,11 @@ class AtEditor:
self.backend = backend
self.scheduler = scheduler
self.template = template
self.widget = self.xml.get_widget("at_editor")
self.xml.signal_connect("on_at_editor_delete", self.on_button_cancel_clicked)
self.mode = 0 # 0 = add, 1 = edit, 2 = template
self.button_save = self.xml.get_widget ("at_button_save")
......@@ -61,15 +61,15 @@ class AtEditor:
self.spin_year = self.xml.get_widget ("at_spin_year")
self.spin_month = self.xml.get_widget ("at_spin_month")
self.spin_day = self.xml.get_widget ("at_spin_day")
self.title_box = self.xml.get_widget ("title_box")
self.image_icon = gtk.Image ()
self.image_icon.set_from_pixbuf (self.ParentClass.bigiconat)
self.title_box.pack_start (self.image_icon, False, False, 0)
self.title_box.reorder_child (self.image_icon, 0)
self.image_icon.show ()
self.cal_button = self.xml.get_widget ("cal_button")
self.cal_hbox = gtk.HBox ()
self.calicon = gtk.Image ()
......@@ -81,17 +81,17 @@ class AtEditor:
self.cal_hbox.add (self.arrow)
self.cal_button.add (self.cal_hbox)
self.cal_button.show_all ()
self.xml.signal_connect ("on_cal_button_toggled", self.on_cal_button_toggled)
self.xml.signal_connect ("on_cb_xoutput_toggled", self.on_cb_xoutput_toggled)
self.cal_loaded = False
self.x, self.y = self.widget.get_position ()
self.height, self.width = self.widget.get_size ()
self.cal_active = True
self.xml.signal_connect ("on_at_editor_size_changed", self.on_at_editor_size_changed)
self.xml.signal_connect("on_at_button_cancel_clicked", self.on_button_cancel_clicked)
self.xml.signal_connect("on_at_button_save_clicked", self.on_button_save_clicked)
......@@ -102,21 +102,21 @@ class AtEditor:
self.xml.signal_connect("on_at_button_cancel_clicked", self.on_button_cancel_clicked)
self.xml.signal_connect ("on_at_button_template_clicked", self.on_button_template_clicked)
self.check_spin_running = False
self.xml.signal_connect("on_at_spin_hour_changed", self.on_spin_hour_changed)
self.xml.signal_connect("on_at_spin_minute_changed", self.on_spin_minute_changed)
self.xml.signal_connect ("on_at_spin_year_changed", self.on_spin_year_changed)
self.xml.signal_connect ("on_at_spin_month_changed", self.on_spin_month_changed)
self.xml.signal_connect ("on_at_spin_day_changed", self.on_spin_day_changed)
ctime = time.localtime()
year = ctime[0]
self.spin_year.set_range (year, year + 5847) # TODO: Year +5847 compatability
self.timeout_handler_id = gobject.timeout_add(60 * 1000, self.__check_spins__)
def showadd (self, transient):
self.button_save.set_label (gtk.STOCK_ADD)
self.__reset__ ()
......@@ -130,16 +130,16 @@ class AtEditor:
self.widget.show_all ()
self.output = 0
self.cb_xoutput.set_active (0)
self.__update_textboxes__()
def showadd_template (self, transient, title, command, output):
self.button_save.set_label (gtk.STOCK_ADD)
self.__reset__ ()
self.title = title
self.command = command
self.mode = 0 # add new task
self.output = output
self.output = output
self.cb_xoutput.set_active (output)
self.widget.set_title(_("Create a New Scheduled Task"))
self.widget.set_transient_for(transient)
......@@ -147,9 +147,9 @@ class AtEditor:
self.__setup_calendar__ ()
self.button_add_template.show ()
self.widget.show_all ()
self.__update_textboxes__()
def showedit_template (self, transient, id, title, command, output):
self.button_save.set_label (gtk.STOCK_ADD)
self.__reset__ ()
......@@ -157,45 +157,45 @@ class AtEditor:
self.title = title
self.command = command
self.mode = 2 # edit template
self.output = output
self.output = output
self.cb_xoutput.set_active (output)
self.widget.set_title(_("Edit template"))
self.widget.set_transient_for(transient)
self.widget.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
self.__setup_calendar__ ()
self.widget.show_all ()
# hide time settings
self.at_vbox_time.hide ()
# save and cancel buttons
self.button_save.set_label (gtk.STOCK_SAVE)
self.button_add_template.hide ()
self.__update_textboxes__()
def shownew_template (self, transient):
self.button_save.set_label (gtk.STOCK_ADD)
self.__reset__ ()
self.tid = 0
self.mode = 2 # edit template
self.output = 0
self.output = 0
self.cb_xoutput.set_active (0)
self.widget.set_title(_("New template"))
self.widget.set_transient_for(transient)
self.widget.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
self.__setup_calendar__ ()
self.widget.show_all ()
# hide time settings
self.at_vbox_time.hide ()
# save and cancel buttons
self.button_save.set_label (gtk.STOCK_ADD)
self.button_add_template.hide ()
self.__update_textboxes__()
def showedit (self, transient, record, job_id, iter):
self.button_save.set_label (gtk.STOCK_APPLY)
self.mode = 1 # edit task
......@@ -213,8 +213,8 @@ class AtEditor:
while i == 0:
self.command = self.command[1:]
i = self.command.find ('\n', 0)
#parse
#parse
(hour, minute, day, month, year) = self.__parse_time__(self.time, self.date)
self.runat = hour + minute + " " + day + "." + month + "." + year
self.spin_year.set_value (int (year))
......@@ -224,7 +224,7 @@ class AtEditor:
self.spin_hour.set_value(int(hour))
self.spin_minute.set_value(int(minute))
self.widget.set_title(_("Edit a Scheduled Task"))
self.__update_textboxes__ ()
self.parentiter = iter
self.widget.set_transient_for(transient)
......@@ -233,18 +233,18 @@ class AtEditor:
self.button_add_template.show ()
self.widget.show_all ()
def on_cal_lost_focus (self, *args):
self.__hide_calendar__ ()
def on_at_editor_size_changed (self, *args):
if self.cal_button.get_active ():
x, y = self.widget.get_position ()
height, width = self.widget.get_size ()
if ((x != self.x) or (y != self.y) or (height != self.height) or (width != self.width)):
self.__hide_calendar__ ()
def on_cb_xoutput_toggled (self, *args):
if self.cb_xoutput.get_active ():
self.output = 1
......@@ -256,21 +256,21 @@ class AtEditor:
self.__show_calendar__ ()
else:
self.__hide_calendar__ ()
def __setup_calendar__ (self):
if self.cal_loaded == False:
self.xml.signal_connect ("on_cal_lost_focus", self.on_cal_lost_focus)
self.xml.signal_connect ("on_cal_window_destroy", self.__destroy_calendar__) # its actually not destroyed, but deleted
self.xml.signal_connect ("on_cal_day_selected_dc", self.on_cal_day_selected_dc)
self.xml.signal_connect ("on_cal_day_selected", self.on_cal_day_selected)
self.cal_window = self.xml.get_widget ("cal_window")
self.calendar = self.xml.get_widget ("calendar")
self.cal_window.hide_all ()
self.cal_loaded = True
def __destroy_calendar__ (self):
self.cal_window.hide_all ()
return True
......@@ -281,10 +281,10 @@ class AtEditor:
self.spin_year.set_value (int (year))
self.spin_month.set_value (int (month) + 1)
self.spin_day.set_value (int (day))
def on_cal_day_selected_dc (self, *args):
self.__hide_calendar__ ()
def __show_calendar__ (self):
x, y = self.widget.window.get_origin ()
button_rect = self.cal_button.get_allocation ()
......@@ -299,13 +299,13 @@ class AtEditor:
self.calendar.select_day (self.spin_day.get_value_as_int ())
self.cal_active = True
self.cal_window.show_all ()
def __hide_calendar__ (self):
self.cal_window.hide_all ()
self.cal_button.set_active (False)
self.widget.set_modal (True)
def on_worded_label_event (self, *args):
#TODO highlight on mouseover
pass
......@@ -319,9 +319,9 @@ class AtEditor:
#TODO show at_script_menuons: install t
# don't forget to attach eventhandling to this popup
pass
def on_text_task_change (self, *args):
start = self.text_task_buffer.get_start_iter()
end = self.text_task_buffer.get_end_iter()
......@@ -331,14 +331,14 @@ class AtEditor:
def on_entry_title_changed (self, *args):
self.title = self.entry_title.get_text()
def on_spin_day_changed (self, *args):
self.__check_spins__ ()
def on_spin_day_changed (self, *args):
self.__check_spins__ ()
self.__update_time_cal__()
def on_spin_month_changed (self, *args):
self.__check_spins__ ()
self.__update_time_cal__()
def on_spin_year_changed (self, *args):
self.__check_spins__ ()
self.__update_time_cal__()
......@@ -355,30 +355,30 @@ class AtEditor:
# Is additionally run every minute
if self.check_spin_running != True:
self.check_spin_running = True
ctime = time.localtime()
year = ctime[0]
month = ctime[1]
day = ctime[2]
hour = ctime[3]
minute = ctime[4]
cyear = False
cmonth = False
cday = False
chour = False
syear = self.spin_year.get_value_as_int ()
if (syear == year):
cyear = True
smonth = self.spin_month.get_value_as_int ()
mi, ma = self