1 | #!/usr/bin/env python3 |
---|
2 | |
---|
3 | # -*- coding: utf-8 -*- |
---|
4 | import gi |
---|
5 | gi.require_version('Gtk', '3.0') |
---|
6 | gi.require_version('PangoCairo', '1.0') |
---|
7 | import json |
---|
8 | import cairo |
---|
9 | import os |
---|
10 | import subprocess |
---|
11 | import shutil |
---|
12 | import threading |
---|
13 | import platform |
---|
14 | import subprocess |
---|
15 | import sys |
---|
16 | import time |
---|
17 | #import commands |
---|
18 | from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, GLib, PangoCairo, Pango |
---|
19 | import time |
---|
20 | from taskscheduler.cronParser import cronParser |
---|
21 | |
---|
22 | import gettext |
---|
23 | gettext.textdomain('taskscheduler') |
---|
24 | _ = gettext.gettext |
---|
25 | |
---|
26 | |
---|
27 | WIDGET_MARGIN=6 |
---|
28 | DBG=1 |
---|
29 | |
---|
30 | class DetailBox: |
---|
31 | |
---|
32 | def __init__(self,scheduler,expert_mode=False): |
---|
33 | self.expert_mode=expert_mode |
---|
34 | self.scheduler_client=scheduler |
---|
35 | self.parser=cronParser() |
---|
36 | self.task_serial="0" |
---|
37 | self.task_type="remote" |
---|
38 | self.btn_apply=Gtk.Button(stock=Gtk.STOCK_APPLY) |
---|
39 | try: |
---|
40 | self.flavour=subprocess.getoutput("lliurex-version -f") |
---|
41 | except: |
---|
42 | self.flavour="client" |
---|
43 | self.ldm_helper='/usr/sbin/sched-ldm.sh' |
---|
44 | |
---|
45 | def _debug(self,msg): |
---|
46 | if DBG: |
---|
47 | print("taskDetails: %s"%msg) |
---|
48 | #def _debug |
---|
49 | |
---|
50 | def _format_widget_for_grid(self,widget): |
---|
51 | #common |
---|
52 | widget.set_hexpand(False) |
---|
53 | widget.set_halign(Gtk.Align.CENTER) |
---|
54 | widget.set_valign(Gtk.Align.CENTER) |
---|
55 | if 'Gtk.Button' in str(type(widget)): |
---|
56 | pass |
---|
57 | elif 'Gtk.Entry' in str(type(widget)): |
---|
58 | widget.set_alignment(xalign=0.5) |
---|
59 | widget.set_max_length(2) |
---|
60 | widget.set_width_chars(2) |
---|
61 | widget.set_max_width_chars(3) |
---|
62 | #def _format_widget_for_grid |
---|
63 | |
---|
64 | def _load_interval_data(self,widget=None,handler=None): |
---|
65 | if handler: |
---|
66 | self.cmb_interval.handler_block(handler) |
---|
67 | position=self.cmb_interval.get_active() |
---|
68 | self.cmb_interval.remove_all() |
---|
69 | date=self.cmb_dates.get_active_text() |
---|
70 | total=24 |
---|
71 | if date==_("day(s)"): |
---|
72 | total=7 |
---|
73 | elif date==_("hour(s)"): |
---|
74 | total=24 |
---|
75 | elif date==_("week(s)"): |
---|
76 | total=4 |
---|
77 | elif date==_("month(s)"): |
---|
78 | total=12 |
---|
79 | for i in range(total): |
---|
80 | self.cmb_interval.append_text(str(i+1)) |
---|
81 | |
---|
82 | #Set sensitive status |
---|
83 | self._changed_interval() |
---|
84 | #If user changes selection try to activate same value on new interval data or max |
---|
85 | if position>=total: |
---|
86 | position=total-1 |
---|
87 | elif position<0: |
---|
88 | position=0 |
---|
89 | self.cmb_interval.set_active(position) |
---|
90 | if handler: |
---|
91 | self.cmb_interval.handler_unblock(handler) |
---|
92 | self._parse_scheduled(True) |
---|
93 | #def _load_interval_data |
---|
94 | |
---|
95 | def _load_date_data(self): |
---|
96 | date=[_("hour(s)"),_("day(s)"),_("week(s)"),_("month(s)")] |
---|
97 | for i in date: |
---|
98 | self.cmb_dates.append_text(i) |
---|
99 | self.cmb_dates.set_active(0) |
---|
100 | #def _load_date_data |
---|
101 | |
---|
102 | def _load_special_date_data(self): |
---|
103 | date=[_("Last month day"),_("First month day")] |
---|
104 | for i in date: |
---|
105 | self.cmb_special_dates.append_text(i) |
---|
106 | self.cmb_special_dates.set_active(0) |
---|
107 | #def _load_special_date_data |
---|
108 | |
---|
109 | def _load_date_time_data(self,date_type): |
---|
110 | inc=0 |
---|
111 | jump=0 |
---|
112 | time_units=0 |
---|
113 | months={} |
---|
114 | if date_type=='hour': |
---|
115 | time_units=24 |
---|
116 | widget=self.cmb_hours |
---|
117 | elif date_type=='minute': |
---|
118 | time_units=60 |
---|
119 | jump=5 |
---|
120 | widget=self.cmb_minutes |
---|
121 | elif date_type=='month': |
---|
122 | widget=self.cmb_months |
---|
123 | widget.append_text(_("Every month")) |
---|
124 | inc=1 |
---|
125 | time_units=12 |
---|
126 | months={1:'January',2:'February',3:'March',4:'April',5:'May',6:'June',7:'July',8:'August',9:'September',10:'October',11:'November',12:'December'} |
---|
127 | elif date_type=='day': |
---|
128 | widget=self.cmb_days |
---|
129 | widget.append_text(_("Every day")) |
---|
130 | inc=1 |
---|
131 | time_units=31 |
---|
132 | |
---|
133 | for i in range(time_units): |
---|
134 | if jump: |
---|
135 | if (not i%jump): |
---|
136 | widget.append_text(str(i+inc)) |
---|
137 | else: |
---|
138 | if months: |
---|
139 | widget.append_text(months[(i+inc)]) |
---|
140 | else: |
---|
141 | widget.append_text(str(i+inc)) |
---|
142 | widget.set_active(0) |
---|
143 | #def _load_date_time_data |
---|
144 | |
---|
145 | def render_form(self,gtkGrid,btn_apply=True): |
---|
146 | self.chk_monday=Gtk.ToggleButton(_("Monday")) |
---|
147 | self.chk_thursday=Gtk.ToggleButton(_("Tuesday")) |
---|
148 | self.chk_wednesday=Gtk.ToggleButton(_("Wednesday")) |
---|
149 | self.chk_tuesday=Gtk.ToggleButton(_("Thursday")) |
---|
150 | self.chk_friday=Gtk.ToggleButton(_("Friday")) |
---|
151 | self.chk_saturday=Gtk.ToggleButton(_("Saturday")) |
---|
152 | self.chk_sunday=Gtk.ToggleButton(_("Sunday")) |
---|
153 | self.chk_daily=Gtk.CheckButton(_("Daily")) |
---|
154 | self.chk_hourly=Gtk.CheckButton(_("Hourly")) |
---|
155 | self.chk_weekly=Gtk.CheckButton(_("Weekly")) |
---|
156 | self.chk_interval=Gtk.CheckButton(_("Interval")) |
---|
157 | self.cmb_interval=Gtk.ComboBoxText() |
---|
158 | self.cmb_dates=Gtk.ComboBoxText() |
---|
159 | self.chk_special_dates=Gtk.CheckButton(_("Last month day")) |
---|
160 | self.day_box=Gtk.Box() |
---|
161 | self.day_box.set_homogeneous(True) |
---|
162 | self.cmb_days=Gtk.ComboBoxText() |
---|
163 | self.day_box.add(Gtk.Label(_("Day"))) |
---|
164 | self.day_box.add(self.cmb_days) |
---|
165 | self.month_box=Gtk.Box() |
---|
166 | self.month_box.set_homogeneous(True) |
---|
167 | self.cmb_months=Gtk.ComboBoxText() |
---|
168 | self.month_box.add(Gtk.Label(_("Month"))) |
---|
169 | self.month_box.add(self.cmb_months) |
---|
170 | self.hour_box=Gtk.Box() |
---|
171 | self.hour_box.set_homogeneous(True) |
---|
172 | self.cmb_hours=Gtk.ComboBoxText() |
---|
173 | # self.hour_box.add(Gtk.Label(_("Hour"))) |
---|
174 | # self.hour_box.add(self.cmb_hours) |
---|
175 | ####REM |
---|
176 | spin_hour=Gtk.SpinButton() |
---|
177 | spin_hour.set_range(0,23) |
---|
178 | spin_hour.set_increments(1,1) |
---|
179 | spin_hour.set_wrap(True) |
---|
180 | spin_hour.set_orientation(Gtk.Orientation.VERTICAL) |
---|
181 | spin_hour.set_valign(Gtk.Align.START) |
---|
182 | spin_hour.set_halign(Gtk.Align.START) |
---|
183 | spin_hour.set_vexpand(False) |
---|
184 | spin_min=Gtk.SpinButton() |
---|
185 | spin_min.set_range(0,59) |
---|
186 | spin_min.set_increments(1,1) |
---|
187 | spin_min.set_wrap(True) |
---|
188 | spin_min.set_orientation(Gtk.Orientation.VERTICAL) |
---|
189 | spin_min.set_valign(Gtk.Align.START) |
---|
190 | spin_min.set_halign(Gtk.Align.START) |
---|
191 | spin_min.set_vexpand(False) |
---|
192 | self.hour_box.add(spin_hour) |
---|
193 | self.hour_box.add(Gtk.Label(":")) |
---|
194 | self.hour_box.add(spin_min) |
---|
195 | ####REM |
---|
196 | self.minute_box=Gtk.Box() |
---|
197 | # self.minute_box.set_homogeneous(True) |
---|
198 | self.cmb_minutes=Gtk.ComboBoxText() |
---|
199 | # self.minute_box.add(Gtk.Label(_("Minutes"))) |
---|
200 | # self.minute_box.add(self.cmb_minutes) |
---|
201 | |
---|
202 | self._load_interval_data() |
---|
203 | self._load_date_data() |
---|
204 | |
---|
205 | self.lbl_info=Gtk.Label("") |
---|
206 | self.lbl_info.set_line_wrap(True) |
---|
207 | self.lbl_info.set_max_width_chars(20) |
---|
208 | self.lbl_info.set_width_chars(20) |
---|
209 | self.lbl_info.set_opacity(0.6) |
---|
210 | gtkGrid.attach(self.lbl_info,0,0,4,1) |
---|
211 | self.lbl_info.set_margin_bottom(24) |
---|
212 | dow_frame=Gtk.Frame() |
---|
213 | dow_frame.set_shadow_type(Gtk.ShadowType.OUT) |
---|
214 | frame_box=Gtk.Box(orientation=Gtk.Orientation.VERTICAL,spacing=6) |
---|
215 | dow_frame.add(frame_box) |
---|
216 | label=Gtk.Label(_("Days of week")) |
---|
217 | frame_box.add(label) |
---|
218 | frame_box.set_margin_bottom(6) |
---|
219 | frame_box.set_margin_top(6) |
---|
220 | frame_box.set_margin_left(6) |
---|
221 | frame_box.set_margin_right(6) |
---|
222 | dow_box=Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) |
---|
223 | work_days_box=Gtk.Box(orientation=Gtk.Orientation.VERTICAL) |
---|
224 | work_days_box.add(self.chk_monday) |
---|
225 | work_days_box.add(self.chk_tuesday) |
---|
226 | work_days_box.add(self.chk_wednesday) |
---|
227 | work_days_box.add(self.chk_thursday) |
---|
228 | work_days_box.add(self.chk_friday) |
---|
229 | work_days_box.set_focus_chain([self.chk_monday,self.chk_tuesday,self.chk_wednesday,self.chk_thursday,self.chk_friday]) |
---|
230 | dow_box.add(work_days_box) |
---|
231 | weekend_days_box=Gtk.Box(orientation=Gtk.Orientation.VERTICAL) |
---|
232 | dow_box.add(weekend_days_box) |
---|
233 | weekend_days_box.add(self.chk_saturday) |
---|
234 | weekend_days_box.add(self.chk_sunday) |
---|
235 | weekend_days_box.set_focus_chain([self.chk_saturday,self.chk_sunday]) |
---|
236 | dow_box.set_focus_chain([work_days_box,weekend_days_box]) |
---|
237 | frame_box.add(dow_box) |
---|
238 | label=Gtk.Label() |
---|
239 | label.set_margin_bottom(WIDGET_MARGIN) |
---|
240 | self.interval_box=Gtk.Box() |
---|
241 | if self.expert_mode: |
---|
242 | label.set_text(_("Time & date")) |
---|
243 | minBoxPos=Gtk.PositionType.BOTTOM |
---|
244 | labelCol=1 |
---|
245 | dowCol=0 |
---|
246 | gtkGrid.attach(dow_frame,0,1,1,6) |
---|
247 | gtkGrid.attach(label,1,1,1,1) |
---|
248 | gtkGrid.attach_next_to(self.hour_box,label,Gtk.PositionType.BOTTOM,1,1) |
---|
249 | # gtkGrid.attach_next_to(self.minute_box,self.hour_box,Gtk.PositionType.BOTTOM,1,1) |
---|
250 | gtkGrid.attach_next_to(self.month_box,self.minute_box,Gtk.PositionType.BOTTOM,1,1) |
---|
251 | gtkGrid.attach_next_to(self.day_box,self.month_box,Gtk.PositionType.BOTTOM,1,1) |
---|
252 | label=Gtk.Label(_("Time intervals")) |
---|
253 | label.set_margin_bottom(WIDGET_MARGIN) |
---|
254 | gtkGrid.attach(label,2,1,2,1) |
---|
255 | gtkGrid.attach_next_to(self.chk_interval,label,Gtk.PositionType.BOTTOM,1,1) |
---|
256 | self.interval_box.add(Gtk.Label(_("Each"))) |
---|
257 | self.interval_box.add(self.cmb_interval) |
---|
258 | self.interval_box.add(self.cmb_dates) |
---|
259 | gtkGrid.attach_next_to(self.interval_box,self.chk_interval,Gtk.PositionType.BOTTOM,1,1) |
---|
260 | gtkGrid.attach_next_to(self.chk_special_dates,self.interval_box,Gtk.PositionType.BOTTOM,1,1) |
---|
261 | else: |
---|
262 | label.set_text(_("Time")) |
---|
263 | gtkGrid.attach(dow_frame,1,1,1,6) |
---|
264 | gtkGrid.attach(label,2,1,1,1) |
---|
265 | gtkGrid.attach_next_to(self.hour_box,label,Gtk.PositionType.BOTTOM,1,3) |
---|
266 | # gtkGrid.attach_next_to(self.minute_box,self.hour_box,Gtk.PositionType.RIGHT,1,1) |
---|
267 | gtkGrid.set_row_homogeneous(True) |
---|
268 | |
---|
269 | if btn_apply: |
---|
270 | self.btn_apply.set_halign(Gtk.Align.END) |
---|
271 | self.btn_apply.set_valign(Gtk.Align.END) |
---|
272 | gtkGrid.attach(self.btn_apply,4,7,2,1) |
---|
273 | self.chk_node=Gtk.CheckButton() |
---|
274 | self.chk_node.set_margin_top(12) |
---|
275 | self.chk_node.set_halign(Gtk.Align.START) |
---|
276 | self.chk_node.set_valign(Gtk.Align.START) |
---|
277 | gtkGrid.attach(self.chk_node,0,7,1,1) |
---|
278 | self.chk_node.set_label("Advanced") |
---|
279 | self.chk_node.set_active(self.expert_mode) |
---|
280 | |
---|
281 | #Tab order chain |
---|
282 | widget_array=[dow_frame,self.hour_box,self.minute_box,self.month_box,self.day_box,self.chk_interval,\ |
---|
283 | self.interval_box,self.chk_special_dates] |
---|
284 | if btn_apply: |
---|
285 | widget_array.append(self.btn_apply) |
---|
286 | |
---|
287 | gtkGrid.set_focus_chain(widget_array) |
---|
288 | #Add data to combos |
---|
289 | self._load_date_time_data('minute') |
---|
290 | self._load_date_time_data('hour') |
---|
291 | self._load_date_time_data('day') |
---|
292 | self._load_date_time_data('month') |
---|
293 | #handled signals |
---|
294 | interval_handler=self.cmb_interval.connect("changed",self._parse_scheduled) |
---|
295 | #Signals |
---|
296 | self.chk_monday.connect("toggled",self._enable_fixed_dates,interval_handler) |
---|
297 | self.chk_thursday.connect("toggled",self._enable_fixed_dates,interval_handler) |
---|
298 | self.chk_wednesday.connect("toggled",self._enable_fixed_dates,interval_handler) |
---|
299 | self.chk_tuesday.connect("toggled",self._enable_fixed_dates,interval_handler) |
---|
300 | self.chk_friday.connect("toggled",self._enable_fixed_dates,interval_handler) |
---|
301 | self.chk_saturday.connect("toggled",self._enable_fixed_dates,interval_handler) |
---|
302 | self.chk_sunday.connect("toggled",self._enable_fixed_dates,interval_handler) |
---|
303 | self.chk_interval.connect("toggled",self._chk_interval_status) |
---|
304 | self.chk_special_dates.connect("toggled",self._chk_special_dates_status) |
---|
305 | self.cmb_dates.connect("changed",self._load_interval_data,interval_handler) |
---|
306 | self.cmb_handler={} |
---|
307 | self.cmb_handler[self.cmb_months]=self.cmb_months.connect("changed",self._parse_scheduled) |
---|
308 | self.cmb_handler[self.cmb_days]=self.cmb_days.connect("changed",self._parse_scheduled) |
---|
309 | self.cmb_handler[self.cmb_hours]=self.cmb_hours.connect("changed",self._parse_scheduled) |
---|
310 | self.cmb_handler[self.cmb_minutes]=self.cmb_minutes.connect("changed",self._parse_scheduled) |
---|
311 | gtkGrid.connect("event",self._parse_scheduled) |
---|
312 | self.chk_node.connect("toggled",self._enable_expert_mode,gtkGrid,btn_apply) |
---|
313 | |
---|
314 | #Initial control status |
---|
315 | self.interval_box.set_sensitive(False) |
---|
316 | #signals |
---|
317 | return (gtkGrid) |
---|
318 | #def render_form |
---|
319 | |
---|
320 | def _enable_expert_mode(self,widget,gtkgrid,btn_apply): |
---|
321 | self.expert_mode=self.chk_node.get_active() |
---|
322 | for grid_widget in gtkgrid.get_children(): |
---|
323 | gtkgrid.remove(grid_widget) |
---|
324 | parent=gtkgrid.get_parent() |
---|
325 | parent.remove(gtkgrid) |
---|
326 | gtkgrid=self.render_form(gtkgrid,btn_apply) |
---|
327 | parent.add(gtkgrid) |
---|
328 | parent.show_all() |
---|
329 | |
---|
330 | |
---|
331 | def load_task_details(self,task_name,task_serial,task_data,task_type): |
---|
332 | self.clear_screen() |
---|
333 | for widget,handler in self.cmb_handler.items(): |
---|
334 | widget.handler_block(handler) |
---|
335 | self.task_name=task_name |
---|
336 | self.task_serial=task_serial |
---|
337 | self.task_cmd=task_data['cmd'] |
---|
338 | self.task_type=task_type |
---|
339 | self.lbl_info.set_text('') |
---|
340 | if task_data['m'].isdigit(): |
---|
341 | cursor=0 |
---|
342 | for minute in range(0,60,5): |
---|
343 | if minute>int(task_data['m']): |
---|
344 | break |
---|
345 | cursor+=1 |
---|
346 | self.cmb_minutes.set_active(cursor-1) |
---|
347 | else: |
---|
348 | self.cmb_minutes.set_active(0) |
---|
349 | |
---|
350 | self._parse_date_details(task_data['h'],self.cmb_hours,'hour') |
---|
351 | self._parse_date_details(task_data['dom'],self.cmb_days,'dom') |
---|
352 | self._parse_date_details(task_data['mon'],self.cmb_months,'mon') |
---|
353 | widget_dict={'0':self.chk_sunday,'1':self.chk_monday,'2':self.chk_tuesday,\ |
---|
354 | '3':self.chk_wednesday,'4':self.chk_thursday,'5':self.chk_friday,\ |
---|
355 | '6':self.chk_saturday,'7':self.chk_sunday} |
---|
356 | self._parse_date_details(task_data['dow'],None,'dow',widget_dict) |
---|
357 | if 'lmd' in task_data.keys(): |
---|
358 | self.chk_special_dates.set_active(True) |
---|
359 | for widget,handler in self.cmb_handler.items(): |
---|
360 | widget.handler_unblock(handler) |
---|
361 | #def load_task_details |
---|
362 | |
---|
363 | def _parse_date_details(self,date,widget=None,date_type=None,widget_dict=None): |
---|
364 | if date.isdigit() and widget: |
---|
365 | widget.set_active(int(date)) |
---|
366 | elif '/' in date: |
---|
367 | pos=date.split('/') |
---|
368 | self.chk_interval.set_active(True) |
---|
369 | self.cmb_interval.set_active(int(pos[1])-1) |
---|
370 | if date_type=='hour': |
---|
371 | self.cmb_dates.set_active(0) |
---|
372 | self.hour_box.set_sensitive(False) |
---|
373 | elif date_type=='dom': |
---|
374 | self.cmb_dates.set_active(1) |
---|
375 | self.day_box.set_sensitive(False) |
---|
376 | self.hour_box.set_sensitive(True) |
---|
377 | elif date_type=='mon': |
---|
378 | self.cmb_interval.set_active(int(pos[1])-1) |
---|
379 | self.cmb_dates.set_active(3) |
---|
380 | self.month_box.set_sensitive(False) |
---|
381 | self.hour_box.set_sensitive(True) |
---|
382 | elif widget_dict: |
---|
383 | array_date=[] |
---|
384 | if ',' in date: |
---|
385 | array_date=date.split(',') |
---|
386 | else: |
---|
387 | array_date.append(date) |
---|
388 | |
---|
389 | for selected_date in array_date: |
---|
390 | if selected_date.isdigit(): |
---|
391 | widget_dict[selected_date].set_active(True) |
---|
392 | #def _parse_date_details |
---|
393 | |
---|
394 | def clear_screen(self): |
---|
395 | widgets=[self.chk_monday,self.chk_thursday,self.chk_wednesday,self.chk_tuesday,\ |
---|
396 | self.chk_friday,self.chk_saturday,self.chk_sunday] |
---|
397 | for widget in widgets: |
---|
398 | widget.set_active(False) |
---|
399 | self.cmb_hours.set_active(0) |
---|
400 | self.cmb_minutes.set_active(0) |
---|
401 | self.cmb_days.set_active(0) |
---|
402 | self.cmb_months.set_active(0) |
---|
403 | self.cmb_interval.set_active(0) |
---|
404 | self.cmb_dates.set_active(0) |
---|
405 | self.chk_special_dates.set_active(False) |
---|
406 | self.chk_interval.set_active(False) |
---|
407 | #def clear_screen |
---|
408 | |
---|
409 | def _set_sensitive_widget(self,widget_dic): |
---|
410 | for widget,status in widget_dic.items(): |
---|
411 | widget.set_sensitive(status) |
---|
412 | #def _set_sensitive_widget |
---|
413 | |
---|
414 | def _changed_interval(self): |
---|
415 | if self.chk_interval.get_active(): |
---|
416 | interval=self.cmb_dates.get_active_text() |
---|
417 | if interval==_('hour(s)'): |
---|
418 | self._set_sensitive_widget({self.day_box:not self._get_days_active(),\ |
---|
419 | self.month_box:True,self.hour_box:False}) |
---|
420 | self._set_days_sensitive(True) |
---|
421 | elif interval==_('day(s)') or interval==_('week(s)'): |
---|
422 | self._set_sensitive_widget({self.day_box:False,self.month_box:True,self.hour_box:True}) |
---|
423 | self._set_days_sensitive(False) |
---|
424 | elif interval==_('month(s)'): |
---|
425 | self._set_sensitive_widget({self.day_box:not self._get_days_active(),\ |
---|
426 | self.month_box:False,self.hour_box:True}) |
---|
427 | self._set_days_sensitive(True) |
---|
428 | self._chk_special_dates_status() |
---|
429 | #def _changed_interval |
---|
430 | |
---|
431 | |
---|
432 | def _chk_interval_status(self,widget): |
---|
433 | if self.chk_interval.get_active(): |
---|
434 | self._set_sensitive_widget({self.interval_box:True,\ |
---|
435 | self.hour_box:False,self.month_box:True,self.day_box:not self._get_days_active()}) |
---|
436 | self._changed_interval() |
---|
437 | else: |
---|
438 | self._set_sensitive_widget({self.interval_box:False,\ |
---|
439 | self.hour_box:True,self.month_box:True,self.day_box:not self._get_days_active()}) |
---|
440 | self._chk_special_dates_status() |
---|
441 | #def _chk_interval_status |
---|
442 | |
---|
443 | def _chk_special_dates_status(self,widget=None): |
---|
444 | if self.chk_special_dates.get_active(): |
---|
445 | self._set_sensitive_widget({self.hour_box:True,self.month_box:True,self.day_box:False}) |
---|
446 | self._set_days_sensitive(False) |
---|
447 | else: |
---|
448 | self._set_sensitive_widget({self.day_box:not self._get_days_active()}) |
---|
449 | self._set_days_sensitive(True) |
---|
450 | #def _chk_special_dates_status |
---|
451 | |
---|
452 | def _get_days_active(self): |
---|
453 | sw_active=False |
---|
454 | widgets=[self.chk_monday, |
---|
455 | self.chk_thursday, |
---|
456 | self.chk_wednesday, |
---|
457 | self.chk_tuesday, |
---|
458 | self.chk_friday, |
---|
459 | self.chk_saturday, |
---|
460 | self.chk_sunday] |
---|
461 | for widget in widgets: |
---|
462 | if widget.get_active(): |
---|
463 | sw_active=True |
---|
464 | break |
---|
465 | return sw_active |
---|
466 | #def _get_days_active |
---|
467 | |
---|
468 | def _enable_fixed_dates(self,widget,handler=None): |
---|
469 | sw_enable=True |
---|
470 | sw_enable=self._get_days_active() |
---|
471 | if sw_enable: |
---|
472 | if self.chk_interval.get_active(): |
---|
473 | self._load_interval_data(True,handler) |
---|
474 | self.day_box.set_sensitive(False) |
---|
475 | else: |
---|
476 | self.month_box.set_sensitive(True) |
---|
477 | self.day_box.set_sensitive(False) |
---|
478 | else: |
---|
479 | if self.chk_interval.get_active(): |
---|
480 | self._load_interval_data(True,handler) |
---|
481 | else: |
---|
482 | self.day_box.set_sensitive(True) |
---|
483 | self.month_box.set_sensitive(True) |
---|
484 | #def _enable_fixed_dates |
---|
485 | |
---|
486 | def _set_days_sensitive(self,state): |
---|
487 | if self.chk_special_dates.get_active(): |
---|
488 | state=False |
---|
489 | widgets=[self.chk_monday, |
---|
490 | self.chk_thursday, |
---|
491 | self.chk_wednesday, |
---|
492 | self.chk_tuesday, |
---|
493 | self.chk_friday, |
---|
494 | self.chk_saturday, |
---|
495 | self.chk_sunday] |
---|
496 | for widget in widgets: |
---|
497 | widget.set_sensitive(state) |
---|
498 | #def _set_days_sensitive |
---|
499 | |
---|
500 | def _parse_screen(self): |
---|
501 | details={} |
---|
502 | dow='' |
---|
503 | widgets=[self.chk_monday,self.chk_thursday, self.chk_wednesday, self.chk_tuesday,\ |
---|
504 | self.chk_friday,self.chk_saturday,self.chk_sunday] |
---|
505 | cont=1 |
---|
506 | for widget in widgets: |
---|
507 | if widget.get_active() and widget.get_sensitive(): |
---|
508 | dow+=str(cont)+',' |
---|
509 | cont+=1 |
---|
510 | if dow!='': |
---|
511 | dow=dow.rstrip(',') |
---|
512 | else: |
---|
513 | dow='*' |
---|
514 | details['dow']=dow |
---|
515 | #Init date data |
---|
516 | for i in ["h","m","mon","dom"]: |
---|
517 | details[i]="*" |
---|
518 | #load data |
---|
519 | if self.cmb_hours.is_sensitive(): |
---|
520 | details["h"]=self.cmb_hours.get_active_text() |
---|
521 | if self.cmb_minutes.is_sensitive(): |
---|
522 | details["m"]=self.cmb_minutes.get_active_text() |
---|
523 | if self.cmb_months.is_sensitive(): |
---|
524 | if self.cmb_months.get_active()>0: |
---|
525 | details["mon"]=str(self.cmb_months.get_active()) |
---|
526 | if self.cmb_days.is_sensitive(): |
---|
527 | if self.cmb_days.get_active_text().isdigit(): |
---|
528 | details["dom"]=self.cmb_days.get_active_text() |
---|
529 | |
---|
530 | if self.cmb_dates.is_sensitive(): |
---|
531 | if self.cmb_dates.get_active_text()==_('hour(s)'): |
---|
532 | details['h']="0/"+self.cmb_interval.get_active_text() |
---|
533 | if self.cmb_dates.get_active_text()==_('day(s)'): |
---|
534 | details['dom']="1/"+self.cmb_interval.get_active_text() |
---|
535 | if self.cmb_dates.get_active_text()==_('week(s)'): |
---|
536 | week=int(self.cmb_interval.get_active_text())*7 |
---|
537 | details['dom']="1/"+str(week) |
---|
538 | if self.cmb_dates.get_active_text()==_('month(s)'): |
---|
539 | details['mon']="1/"+self.cmb_interval.get_active_text() |
---|
540 | details['hidden']=0 |
---|
541 | if self.chk_special_dates.get_active(): |
---|
542 | details['lmd']=1 |
---|
543 | details['dom']='*' |
---|
544 | details['dow']='*' |
---|
545 | return details |
---|
546 | #def _parse_screen |
---|
547 | |
---|
548 | def _parse_scheduled(self,container=None,widget=None): |
---|
549 | details=self._parse_screen() |
---|
550 | self.lbl_info.set_text(self.parser.parse_taskData(details)) |
---|
551 | #def _parse_scheduled |
---|
552 | |
---|
553 | def update_task_details(self,widget=None): |
---|
554 | if self.task_name and self.task_serial: |
---|
555 | task_data=self.get_task_details() |
---|
556 | return self.scheduler_client.write_tasks(task_data,self.task_type) |
---|
557 | #def update_task_details |
---|
558 | |
---|
559 | def get_task_details(self,widget=None,task_name=None,task_serial=None,task_cmd=None,task_type=None): |
---|
560 | if task_name: |
---|
561 | self.task_name=task_name |
---|
562 | if task_serial: |
---|
563 | self.task_serial=task_serial |
---|
564 | if task_cmd: |
---|
565 | self.task_cmd=task_cmd |
---|
566 | if task_type: |
---|
567 | self.task_type=task_type |
---|
568 | details=self._parse_screen() |
---|
569 | details['cmd']=self.scheduler_client.get_task_command(self.task_cmd) |
---|
570 | if 'lmd' in details.keys(): |
---|
571 | details['cmd']=self.ldm_helper+' '+details['cmd'] |
---|
572 | task={} |
---|
573 | task[self.task_name]={self.task_serial:details} |
---|
574 | self._debug("Saving %s"%task) |
---|
575 | return task |
---|
576 | #def get_task_details |
---|