def check_getLineNumbers(self): """ getLineNumbers """ c = crontab.Crontab() c.filename = os.path.join("..", os.path.basename(c.filename) + ".sample") c.open() assert c.getLineNumbers() > 0
def check_deleteItem(self): """ deleteItem """ c = crontab.Crontab() c.filename = os.path.join("..", os.path.basename(c.filename) + ".sample") c.open() lineNumber = c.newItem() c.deleteItem(lineNumber) self.assertRaises(KeyError, c.getItem, lineNumber)
def check_newItem(self): """ newItem """ c = crontab.Crontab() c.filename = os.path.join("..", os.path.basename(c.filename) + ".sample") c.open() lineNumber = c.newItem() assert lineNumber > 0 self.assertEqual(len(c.getItem(lineNumber)), 7)
def check_getItem(self): """ getItem """ c = crontab.Crontab() c.filename = os.path.join("..", os.path.basename(c.filename) + ".sample") c.open() for lineNumber in c.getLineNumbers(): item = c.getItem(lineNumber) self.assertEqual(len(item), 7)
def __init__(self, parent): self._init_ctrls(parent) self.crontab = crontab.Crontab() try: self.crontab.open() except IOError: pass self.setTitleFromFilename() self.currentItem = 0 self.populateList()
def check_changeItem(self): """ changeItem """ c = crontab.Crontab() c.filename = os.path.join("..", os.path.basename(c.filename) + ".sample") c.open() lineNumber = c.newItem() c.changeItem(lineNumber, "1", "2", "3", "4", "5", "cmd", "parameters") self.assertEqual(c.getItem(lineNumber), ("1", "2", "3", "4", "5", "cmd", "parameters"))
def check_open(self): """ open """ f = open("abc.txt", "wb") f.write("this is a bad line\n") f.close() c = crontab.Crontab() c.filename = "abc.txt" self.assertRaises(crontab.pycron.InvalidLineException, c.open) os.remove("abc.txt") self.assertRaises(IOError, c.open)
def check_changed(self): """ changed """ c = crontab.Crontab() c.filename = os.path.join("..", os.path.basename(c.filename) + ".sample") c.open() self.assertEqual(c.changed, False) lineNumber = c.getLineNumbers()[0] item = c.getItem(lineNumber) c.changeItem(lineNumber, *item) #same values --> no change self.assertEqual(c.changed, False) c.changeItem(lineNumber, *c.getItem(c.newItem())) self.assertEqual(c.changed, True)
sys.stderr.write(_("File exists already.") + "\n") sys.exit(1) if stdo: of = sys.stdout else: try: of = open(outf, 'wb') except: sys.stderr.write( _("Could not open file for writing: %s" % outf) + "\n") sys.exit(1) d = GnomeScheduleDB() c = crontab.Crontab(is_root, user, uid, gid, home_dir) tasks = c.read(easy=False) crontabc = 0 cl = [] for task in tasks: sys.stderr.write(_("Exporting crontab task: %s" % task[0]) + "\n") crontabc = crontabc + 1 cl.append([task[0], task[5], task[2], task[3], task[14]]) d.setcrontab(cl) # AT a = at.At(is_root, user, uid, gid, home_dir, manual_poscorrect) tasks = a.read() atc = 0 al = []
def __init__(self, debug_flag=None, inapplet=False, manual_poscorrect=False): self.debug_flag = debug_flag self.inapplet = inapplet self.manual_poscorrect = manual_poscorrect self.__loadIcon__() self.__loadGlade__() self.editor = None self.schedule = None self.noevents = False # Common string representation for the different output modes self.output_strings = [ _("Default behaviour"), _("Suppress output"), _("X application"), _("X application: suppress output"), ] #start the backend where all the user configuration is stored self.backend = data.ConfigBackend(self, "gconf") self.template = template.Template(self, self.backend) ##configure the window self.widget = self.xml.get_widget("mainWindow") self.widget.connect("delete_event", self.__quit__) self.widget.connect("destroy_event", self.__quit__) self.widget.set_icon(self.iconPixbuf) #load state (x, y, h, w) = self.backend.get_window_state() if (x and y): self.widget.move(x, y) if (h and w): self.widget.resize(h, w) self.widget.set_resizable(True) ## ##configure statusbar self.statusbar = self.xml.get_widget("statusbar") self.statusbarUser = self.statusbar.get_context_id("user") ## ##configure the toolbar self.toolbar = self.xml.get_widget("toolbar") self.add_button = gtk.MenuToolButton(gtk.STOCK_NEW) self.add_button_menu = gtk.Menu() self.add_button_menu_add_crontab = gtk.MenuItem() self.add_button_menu_add_at = gtk.MenuItem() self.add_button_menu_add_template = gtk.MenuItem() self.recurrenthbox = gtk.HBox() icon = gtk.Image() icon.set_from_pixbuf(self.iconcrontab) label = gtk.Label(_("Recurrent task")) icon.set_alignment(0, 0.5) label.set_justify(gtk.JUSTIFY_LEFT) label.set_alignment(0, 0.5) self.recurrenthbox.pack_start(icon, False, False, 2) self.recurrenthbox.pack_start(label, True, True, 2) self.add_button_menu_add_crontab.add(self.recurrenthbox) self.onetimehbox = gtk.HBox() icon = gtk.Image() icon.set_from_pixbuf(self.iconat) label = gtk.Label(_("One-time task")) icon.set_alignment(0, 0.5) label.set_justify(gtk.JUSTIFY_LEFT) label.set_alignment(0, 0.5) self.onetimehbox.pack_start(icon, False, False, 2) self.onetimehbox.pack_start(label, True, True, 2) self.add_button_menu_add_at.add(self.onetimehbox) self.templatehbox = gtk.HBox() icon = gtk.Image() icon.set_from_pixbuf(self.icontemplate) label = gtk.Label(_("From template")) icon.set_alignment(0, 0.5) label.set_justify(gtk.JUSTIFY_LEFT) label.set_alignment(0, 0.5) self.templatehbox.pack_start(icon, False, False, 2) self.templatehbox.pack_start(label, True, True, 2) self.add_button_menu_add_template.add(self.templatehbox) self.add_button_menu.append(self.add_button_menu_add_crontab) self.add_button_menu.append(self.add_button_menu_add_at) self.add_button_menu.append(self.add_button_menu_add_template) self.add_button.set_menu(self.add_button_menu) self.toolbar.insert(self.add_button, 0) self.add_button.set_is_important(True) tip = gtk.Tooltips() tip.enable() self.add_button.set_tooltip(tip, _("Add a new task"), tip_private=None) self.add_button.show_all() self.add_button_menu.show_all() self.add_button_menu_add_crontab.show_all() self.add_button_menu_add_at.show_all() self.add_button.connect("clicked", self.on_add_button_clicked) self.add_button_menu_add_crontab.connect("activate", self.on_add_crontab_task) self.add_button_menu_add_at.connect("activate", self.on_add_at_task) self.add_button_menu_add_template.connect("activate", self.on_add_from_template) self.prop_button = self.xml.get_widget("prop_button") self.del_button = self.xml.get_widget("del_button") self.run_button = self.xml.get_widget("run_button") self.help_button = self.xml.get_widget("help_button") self.btnSetUser = self.xml.get_widget("btnSetUser") self.btnExit = self.xml.get_widget("btnExit") self.about_button = self.xml.get_widget("about_button") self.edit_mode_button = self.xml.get_widget("edit_mode_button") self.button_template = self.xml.get_widget("button_m_template") icon = gtk.Image() icon.set_from_pixbuf(self.normalicontemplate) self.button_template.set_icon_widget(icon) icon.show() self.prop_button.set_sensitive(False) self.del_button.set_sensitive(False) self.run_button.set_sensitive(False) self.xml.signal_connect("on_prop_button_clicked", self.on_prop_button_clicked) self.xml.signal_connect("on_del_button_clicked", self.on_del_button_clicked) self.xml.signal_connect("on_help_button_clicked", self.on_help_button_clicked) self.xml.signal_connect("on_btnSetUser_clicked", self.on_btnSetUser_clicked) self.xml.signal_connect("on_about_menu_activate", self.on_about_menu_activate) self.xml.signal_connect("on_edit_mode_button_clicked", self.on_advanced_menu_activate) self.xml.signal_connect("on_btnExit_clicked", self.__quit__) self.xml.signal_connect("on_mainWindow_delete_event", self.__quit__) self.xml.signal_connect("on_run_button_clicked", self.on_run_button_clicked) self.xml.signal_connect("on_button_m_template_clicked", self.on_template_manager_button) ##inittializing the treeview and treemodel ## somethins not rite here..: ## [0 Title, 1 Frequency, 2 Command, 3 Crontab record, 4 ID, 5 Time, 6 Icon, 7 scheduled instance, 8 icon path, 9 date, 10 class_id, 11 user, 12 time, 13 type, 14 crontab/at, 15 advanced time string] ##for at this would be like: # ["untitled", "12:50 2004-06-25", "preview", "script", "job_id", "12:50", icon, at instance, icon_path, "2004-06-25", "a", "drzap", "at"] ##for crontab it would be: # ["untitled", "every hour", "ls /", "0 * * * * ls / # untitled", "5", "0 * * * *", icon, crontab instance,icon_path, 1(job_id), "", "", "crontab"] self.treemodel = gtk.ListStore( gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING) self.treeview = self.xml.get_widget("treeview") self.xml.signal_connect("on_treeview_button_press_event", self.on_treeview_button_press_event) self.xml.signal_connect("on_treeview_key_press_event", self.on_treeview_key_pressed) self.treeview.set_model(self.treemodel) self.treeview.get_selection().connect("changed", self.on_TreeViewSelectRow) #enable or disable advanced depending on user config self.noevents = True if self.backend.get_advanced_option(): self.switchView("advanced") self.edit_mode_button.set_active(True) else: self.switchView("simple") self.edit_mode_button.set_active(False) self.noevents = False self.__initUser__() ##create crontab self.crontab = crontab.Crontab(self.root, self.user, self.uid, self.gid, self.user_home_dir) self.crontab_editor = crontabEditor.CrontabEditor( self, self.backend, self.crontab, self.template) ## ##create at self.at = at.At(self.root, self.user, self.uid, self.gid, self.user_home_dir, self.manual_poscorrect) self.at_editor = atEditor.AtEditor(self, self.backend, self.at, self.template) ## #set user window self.setuserWindow = setuserWindow.SetuserWindow(self) #set add window self.addWindow = addWindow.AddWindow(self) # template windows self.template_chooser = template_chooser.TemplateChooser( self, self.template) self.template_manager = template_manager.TemplateManager( self, self.template) self.schedule_reload() self.timeout_handler_id = gobject.timeout_add(9000, self.update_schedule) # temporary files to be deleted self.temp_files = [] if inapplet == False: gtk.main()