Esempio n. 1
0
 def set_task(self, task_str):
     try:
         new_task = backend.Task(task_str)
     except:
         self._error = 'Error: Wrong options.'
         self._editing_task = -1
         return 1
     if self._editing_task < len(self._tasks):
         self._tasks[self._editing_task] = new_task
     else:
         self._tasks.append(new_task)
     self._error = backend.write_crontab(self._others +\
                                     self._tasks)
     if self._error:
         self._tasks, self._others = backend.read_crontab()
     return 0
Esempio n. 2
0
 def set_task(self, task_str):
     "Set new or edited task"
     #noinspection PyBroadException
     try:
         new_task = backend.Task(task_str)
     except:
         self._error = 'Error: Wrong options.'
         self._editing_task = -1
         return 1
     if self._editing_task < len(self._tasks):
         self._tasks[self._editing_task] = new_task
     else:
         self._tasks.append(new_task)
     self._error = backend.write_crontab(self._others + self._tasks,
                                         self._user)
     if self._error:
         self._tasks, self._others = backend.read_crontab()
     ConfManager.get().commit('cron')
     return 0
Esempio n. 3
0
    def get_default_ui(self):
        user_sel = [
            UI.SelectOption(text=x,
                            value=x,
                            selected=True if x == self._user else False)
            for x in backend.get_all_users()
        ]
        topbox = UI.FormBox(UI.HContainer(
            UI.Label(text='User: '******'users'),
            UI.Button(text='Select',
                      onclick="form",
                      action='OK',
                      form='frmUsers')),
                            hideok=True,
                            hidecancel=True,
                            id='frmUsers')
        tabbar = UI.TabControl()
        table_other = UI.DataTable(
            UI.DataTableRow(
                UI.Label(text='String', size=80),
                UI.Label(text=''),
                header=True,
            ))
        for i, oth_str in enumerate(self._others):
            table_other.append(
                UI.DataTableRow(
                    UI.Label(text=oth_str),
                    UI.DataTableCell(UI.HContainer(
                        UI.MiniButton(id='edit_oth/' + str(i), text='Edit'),
                        UI.WarningMiniButton(id='del_oth/' + str(i),
                                             text='Delete',
                                             msg='Delete a string')),
                                     hidden=True)))
        table_task = UI.DataTable(
            UI.DataTableRow(
                UI.Label(text='Minutes'),
                UI.Label(text='Hours'),
                UI.Label(text='Days'),
                UI.Label(text='Months'),
                UI.Label(text='DoW'),
                UI.Label(text='Command'),
                UI.Label(text=''),
                header=True,
            ))

        for i, t in enumerate(self._tasks):
            if t.special:
                table_task.append(
                    UI.DataTableRow(
                        UI.Label(text=t.special), UI.Label(), UI.Label(),
                        UI.Label(), UI.Label(), UI.Label(text=t.command),
                        UI.DataTableCell(UI.HContainer(
                            UI.MiniButton(id='edit_task/' + str(i),
                                          text='Edit'),
                            UI.WarningMiniButton(id='del_task/' + str(i),
                                                 text='Delete',
                                                 msg='Delete a task')),
                                         hidden=True)))
            else:
                table_task.append(
                    UI.DataTableRow(
                        UI.Label(text=t.m), UI.Label(text=t.h),
                        UI.Label(text=t.dom), UI.Label(text=t.mon),
                        UI.Label(text=t.dow), UI.Label(text=t.command),
                        UI.DataTableCell(UI.HContainer(
                            UI.MiniButton(id='edit_task/' + str(i),
                                          text='Edit'),
                            UI.WarningMiniButton(id='del_task/' + str(i),
                                                 text='Delete',
                                                 msg='Delete a task')),
                                         hidden=True)))
        part = self._error.partition(':')[2]
        self._error = 'Error:' + part if part else self._error
        if self._error:
            er = UI.ErrorBox(title='Error', text=self._error)
        else:
            er = UI.Spacer()
        vbox_task = UI.VContainer(table_task,
                                  UI.Button(text='Add task', id='add_task'))
        vbox_oth = UI.VContainer(
            table_other, UI.Button(text='Add non-task string', id='add_oth'))
        tabbar.add("Tasks", vbox_task)
        tabbar.add("Non-task strings", vbox_oth)
        vbox = UI.VContainer(topbox, er, tabbar)
        if self._editing_task != -1:
            try:
                task = self._tasks[self._editing_task]
            except IndexError:
                task = backend.Task()
            if self._show_dialog:
                vbox.append(self.get_ui_edit(task))
        if self._editing_other != -1:
            try:
                other = self._others[self._editing_other]
            except IndexError:
                other = ''
            if self._show_dialog:
                vbox.append(self.get_ui_edit_other(other))
        return vbox
Esempio n. 4
0
    def get_ui(self):
        ui = self.app.inflate('cron:main')
        ui.find('tabs').set('active', self._tab)
        ui.find('title').set('text', 'Scheduled tasks for %s' % self._user)
        user_sel = [
            UI.SelectOption(text=x,
                            value=x,
                            selected=True if x == self._user else False)
            for x in backend.get_all_users()
        ]
        ui.appendAll('users_select', *user_sel)

        table_other = ui.find("table_other")
        table_task = ui.find("table_task")
        #Fill non-task strings table
        for i, oth_str in enumerate(self._others):
            table_other.append(
                UI.DTR(
                    UI.Label(text=oth_str),
                    UI.DTD(UI.HContainer(
                        UI.TipIcon(icon='/dl/core/ui/stock/edit.png',
                                   id='edit_oth/' + str(i),
                                   text='Edit'),
                        UI.TipIcon(icon='/dl/core/ui/stock/delete.png',
                                   id='del_oth/' + str(i),
                                   text='Delete',
                                   warning='Delete a string')),
                           hidden=True)))
        #Fill tasks table
        for i, t in enumerate(self._tasks):
            table_task.append(
                UI.DTR(
                    UI.Label(text=t.special if t.special else t.m),
                    UI.Label(text=t.h if not t.special else ''),
                    UI.Label(text=t.dom if not t.special else ''),
                    UI.Label(text=t.mon if not t.special else ''),
                    UI.Label(text=t.dow if not t.special else ''),
                    UI.Label(text=t.command),
                    UI.DTD(
                        UI.HContainer(
                            UI.TipIcon(icon='/dl/core/ui/stock/edit.png',
                                       id='edit_task/' + str(i),
                                       text='Edit'),
                            UI.TipIcon(icon='/dl/core/ui/stock/delete.png',
                                       id='del_task/' + str(i),
                                       text='Delete',
                                       warning='Delete a task')), )))
        #if crontab return error
        part = self._error.partition(':')[2]
        self._error = 'Error:' + part if part else self._error
        if self._error:
            self.put_message('err', self._error)

        #For tabs name
        REGULARTAB = 11
        ADVANCEDTAB = 12
        SPECIALTAB = 13
        #special values
        avaible_values = ('@reboot', '@hourly', '@daily', '@weekly',
                          '@monthly', '@yearly')
        #edit or new task
        if self._editing_task != -1:
            try:
                task = self._tasks[self._editing_task]
            except IndexError:
                task = backend.Task()
            #edit task
            if not self._newtask:
                ui.remove(str(REGULARTAB))
                if task.special:
                    ui.remove(str(ADVANCEDTAB))
                    ui.find('tabsEdit').set('active', SPECIALTAB)
                    #select special values
                    if task.special and task.special in avaible_values:
                        ui.find('r' + task.special[1:]).\
                            set('checked', 'True')
                    else:
                        ui.find('rreboot').set('checked', 'True')
                    ui.find('s_command').set("value", task.command)
                else:
                    #fill advanced view task
                    ui.find('tabsEdit').set('active', ADVANCEDTAB)
                    ui.remove(str(SPECIALTAB))
                    ui.find('m').set("value", task.m)
                    ui.find('h').set("value", task.h)
                    ui.find('dom').set("value", task.dom)
                    ui.find('mon').set("value", task.mon)
                    ui.find('dow').set("value", task.dow)
                    ui.find('a_command').set("value", task.command)
            #new task
            else:
                ui.find('tabsEdit').set('active', REGULARTAB)
                ui.find('rreboot').set('checked', 'True')
                ui.find('m').set("value", task.m)
                ui.find('h').set("value", task.h)
                ui.find('dom').set("value", task.dom)
                ui.find('mon').set("value", task.mon)
                ui.find('dow').set("value", task.dow)
                #For templates
                ui.find('tabsRegular').set('active', 15)
                SelectOptionNumbs = lambda r: [
                    UI.SelectOption(text=str(m), value=str(m))
                    for m in xrange(r)
                ]
                #generate similar selectOptions lists for xml.
                minute_select_h = SelectOptionNumbs(60)
                minute_select_d = SelectOptionNumbs(60)
                minute_select_w = SelectOptionNumbs(60)
                minute_select_m = SelectOptionNumbs(60)
                hour_select_d = SelectOptionNumbs(24)
                hour_select_w = SelectOptionNumbs(24)
                hour_select_m = SelectOptionNumbs(24)

                weekday = ('Monday', 'Tuesday', 'Wednesday', 'Thursday',
                           'Friday', 'Saturday', 'Sunday')
                weekday_select = [
                    UI.SelectOption(text=str(w), value=str(v + 1))
                    for v, w in enumerate(weekday)
                ]
                day_select = [
                    UI.SelectOption(text=str(d), value=str(d))
                    for d in range(1, 32)
                ]
                #Fill selects
                ui.appendAll("minute_select_h", *minute_select_h)
                ui.appendAll("minute_select_d", *minute_select_d)
                ui.appendAll("minute_select_w", *minute_select_w)
                ui.appendAll("minute_select_m", *minute_select_m)
                ui.appendAll("hour_select_d", *hour_select_d)
                ui.appendAll("hour_select_w", *hour_select_w)
                ui.appendAll("hour_select_m", *hour_select_m)
                ui.appendAll("weekday_select", *weekday_select)
                ui.appendAll("day_select", *day_select)
        #Nothing happens with task
        else:
            ui.remove('dlgEditTask')
        #edit non-task string
        if self._editing_other != -1 and self._show_dialog:
            other_value = self._others[self._editing_other]\
                if self._editing_other < len(self._others) else ''
            ui.find("other_str").set("value", other_value)
        #Nothing happens with non-task string
        else:
            ui.remove('dlgEditOther')
        return ui