-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimekprlimit.py
More file actions
716 lines (614 loc) · 24 KB
/
Copy pathtimekprlimit.py
File metadata and controls
716 lines (614 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
#from wocommon import * # wocommon.py
from woClock import clock
from wocommon import strTime2seconds, seconds2strTime, getCmdOutput
from time import strptime, strftime, localtime
from os.path import isfile, getmtime
import xml.dom.minidom as dom
class constrain(object):
GRANT = 0
LIMIT = 1
def __init__(self):
self.name = 'constrain'
self.mode = constrain.GRANT
self.status = False
self.active = False
self.timeUpdateStatus = 0
self.priority = 10
def setPriority(self, p):
self.priority = p
def getPriority(self):
return self.priority
def update(self):
return
def allow(self):
if not self.active: return None
s = (self.mode == constrain.GRANT and self.status) or (self.mode == constrain.LIMIT and not self.status)
return s
def deny(self):
if not self.active: return None
return not self.allow()
def getMode(self):
return self.mode
def setMode(self, p):
self.mode = p
if self.active: self.update()
def activate(self):
self.active = True
def deactivate(self):
self.active = False
def isActive(self):
return self.active
class switch(constrain):
def __init__(self, loadSettings=None):
constrain.__init__(self)
self.name = 'switch'
if loadSettings is not None:
self.loadSettings(loadSettings)
def on(self):
self.status = True
self.active = True
def off(self):
self.status = False
self.active = True
def reset(self):
self.status = False
def saveSettings(self):
dc = dom.Element('constrain')
dc.setAttribute('type', self.name)
dc.setAttribute('mode', ('grant' if self.mode == self.GRANT else 'limit'))
# dt=dc.appendChild(dom.Element("status"))
# dtt=dom.Text()
# dtt.data=('on' if self.status else 'off')
# dt.appendChild(dtt)
return dc
def loadSettings(self, dc):
g = dc.getAttribute("mode")
self.setMode((constrain.GRANT if g == 'grant' else constrain.LIMIT))
# tl = dc.getElementsByTagName("status")
# s= (tl[0].firstChild.data.strip() =='on')
# self.status = s
def loadStatus(self, fbase, force = False):
self.timeFile = fbase + '.' + self.name
if isfile(self.timeFile) and (getmtime(self.timeFile) > self.timeUpdateStatus or force):
f = open(self.timeFile)
s = f.readline()
self.status = (s == 'on')
f.close()
if self.active: self.start()
self.timeUpdateStatus = self.now
def saveStatus(self, fbase):
self.timeFile = fbase + '.' + self.name
f = open(self.timeFile , 'w')
f.write(('on' if self.status else 'off'))
f.close()
getCmdOutput('touch -m -t %s %s' % (strftime('%Y%m%d%H%M.%S', localtime(self.now)), self.timeFile))
class countdownTimer(constrain):
def __init__(self, loadSettings=None):
constrain.__init__(self)
self.name = 'countdown'
self.timeLeft = 0.
self.timeStart = 0.
self.timeEnd = 0.
self.now = 0.
self.timeCountdown = 0.
self.timeFile = ''
self.status = True
self.autoUpdateTime = False
if loadSettings is not None:
self.loadSettings(loadSettings)
def updateTime(self, t=-1):
if t<0: t = clock.now()
self.now = t
self.update()
def update(self):
if self.autoUpdateTime: self.now=clock.now()
if self.active:
self.timeLeft = self.timeEnd - self.now
self.status = (not self.exceeded())
def start(self):
if self.autoUpdateTime: self.now=clock.now()
self.timeStart = self.now
self.timeEnd = self.timeStart + self.timeLeft
self.active = True
self.update()
def stop(self):
self.update()
self.active = False
def reset(self):
self.timeLeft = self.getCountdown()
if self.isActive(): self.start(); # if timer is running set start time now
def setCountdown(self, p):
self.timeCountdown = strTime2seconds(p)
self.reset()
def getCountdown(self, t=-1):
return self.timeCountdown
def setTimeLeft(self, p):
self.timeLeft = p
def getTimeLeft(self):
return self.timeLeft
def getTimeUsed(self):
return self.getCountdown() - self.timeLeft
def exceeded(self):
return (self.timeLeft< 0.)
def saveSettings(self):
dc = dom.Element('constrain')
dc.setAttribute('type', self.name)
dc.setAttribute('mode', ('grant' if self.mode == self.GRANT else 'limit'))
dt=dc.appendChild(dom.Element("time"))
dtt=dom.Text()
dtt.data=seconds2strTime(self.getTimeCountdown())
dt.appendChild(dtt)
return dc
def loadSettings(self, dc):
g = dc.getAttribute("mode")
self.setMode((constrain.GRANT if g == 'grant' else constrain.LIMIT))
tl = dc.getElementsByTagName("time")
wl = strTime2seconds(tl[0].firstChild.data)
self.setCountdown(wl)
'''loads the status from a file fbase.<constrain_name>
if the constrain is active time end is adjusted keeping the start time
if it is inactive time left is set'''
def loadStatus(self, fbase, force = False):
self.timeFile = fbase + '.' + self.name
if isfile(self.timeFile) and (getmtime(self.timeFile) > self.timeUpdateStatus or force):
f = open(self.timeFile)
self.timeLeft = float(f.readline())
f.close()
else:
self.timeLeft = self.getCountdown()
if self.active:
self.timeEnd = self.timeStart + self.timeLeft
else:
self.timeEnd = self.now + self.timeLeft
self.timeUpdateStatus = self.now
def saveStatus(self, fbase):
self.timeFile = fbase + '.' + self.name
f = open(self.timeFile , 'w')
f.write(str(self.timeLeft))
f.close()
getCmdOutput('touch -m -t %s %s' % (strftime('%Y%m%d%H%M.%S', localtime(self.now)), self.timeFile))
class recurringCountdownTimer(countdownTimer):
def __init__(self, loadSettings=None):
countdownTimer.__init__(self)
self.name = 'recurringCountdown'
self.resetTime = 0. ;# time point when Countdown will be reset
self.resetPeriod = 0. ;# duration between two resets
if loadSettings is not None:
self.loadSettings(loadSettings)
def loadStatus(self, fbase, force = False):
countdownTimer.loadStatus(self, fbase, force)
t = (getmtime(self.timeFile) if isfile(self.timeFile) else self.now)
self.updateResetTime(t); # set reset time to last reset time when status file was modified
if self.resetTime <= self.now: # old reset time passed already hence old left time is not valid, reset timeleft
self.timeLeft = self.getCountdown()
self.timeEnd = self.now + self.timeLeft
self.updateResetTime()
def update(self):
countdownTimer.update(self)
if self.active:
# if now past reset time, reset timeleft
if self.now > self.resetTime:
self.setTimeLeft(self.getCountdown() - (self.now - self.resetTime)) ; # reset timeleft to countdown minus time already past in new period since reset
self.timeEnd = self.now + self.timeLeft
self.updateResetTime()
def setResetPeriod(self, p):
self.resetPeriod = p
self.updateResetTime()
def getLastResetTime(self, t=-1):
if t < 0: t = self.now
round = 0
if self.resetPeriod > 0:
round = (t - self.timeStart) // self.resetPeriod
r= self.timeStart + round * self.resetPeriod
return r
def updateResetTime(self, t = -1):
if t < 0: t = self.now
self.resetTime = self.getLastResetTime(t)+ self.resetPeriod
def start(self):
if self.autoUpdateTime: self.now=clock.now()
self.timeStart = self.now
self.timeEnd = self.timeStart + self.timeLeft
self.active = True
self.updateResetTime()
self.update()
def getEffectiveTimeLeft(self):
r = self.timeLeft
if self.timeEnd >= self.resetTime:
r = self.resetTime + self.getCountdown(self.timeEnd) - self.now
return r
def saveSettings(self):
dc = dom.Element('constrain')
dc.setAttribute('type', self.name)
dc.setAttribute('mode', ('grant' if self.mode == self.GRANT else 'limit'))
dt=dc.appendChild(dom.Element("time"))
dtt=dom.Text()
dtt.data=seconds2strTime(self.getCountdown())
dt.appendChild(dtt)
dt=dc.appendChild(dom.Element("resetPeriod"))
dtt=dom.Text()
dtt.data=seconds2strTime(self.resetPeriod)
dt.appendChild(dtt)
return dc
def loadSettings(self, dc):
g = dc.getAttribute("mode")
self.setMode((constrain.GRANT if g == 'grant' else constrain.LIMIT))
tl = dc.getElementsByTagName("time")
wl = strTime2seconds(tl[0].firstChild.data)
self.setCountdown(wl)
tl = dc.getElementsByTagName("resetPeriod")
wl = strTime2seconds(tl[0].firstChild.data)
self.resetPeriod = wl
class weeklyCountdownTimer(recurringCountdownTimer):
def __init__(self, loadSettings=None):
recurringCountdownTimer.__init__(self)
self.name = 'weeklyCountdown'
self.resetPeriod = clock.SECONDS_PER_WEEK
if loadSettings is not None:
self.loadSettings(loadSettings)
def getLastResetTime(self, t=-1):
if t < 0: t = self.now
rtime = clock.getDate(t) - clock.getWeekday(t)*clock.SECONDS_PER_DAY
return rtime
def saveSettings(self):
dc = dom.Element('constrain')
dc.setAttribute('type', self.name)
dc.setAttribute('mode', ('grant' if self.mode == self.GRANT else 'limit'))
dt=dc.appendChild(dom.Element("time"))
dtt=dom.Text()
dtt.data=seconds2strTime(self.getCountdown())
dt.appendChild(dtt)
return dc
def loadSettings(self, dc):
g = dc.getAttribute("mode")
self.setMode((constrain.GRANT if g == 'grant' else constrain.LIMIT))
tl = dc.getElementsByTagName("time")
wl = strTime2seconds(tl[0].firstChild.data)
self.setCountdown(wl)
class monthlyCountdownTimer(recurringCountdownTimer):
def __init__(self, loadSettings=None):
recurringCountdownTimer.__init__(self)
self.name = 'monthlyCountdown'
self.resetPeriod = clock.SECONDS_PER_MONTH
if loadSettings is not None:
self.loadSettings(loadSettings)
def getLastResetTime(self, t=-1):
if t < 0: t = self.now
rtime = clock.getDate(t) - clock.getMonthday(t)*clock.SECONDS_PER_DAY
return rtime
def saveSettings(self):
dc = dom.Element('constrain')
dc.setAttribute('type', self.name)
dc.setAttribute('mode', ('grant' if self.mode == self.GRANT else 'limit'))
dt=dc.appendChild(dom.Element("time"))
dtt=dom.Text()
dtt.data=seconds2strTime(self.getCountdown())
dt.appendChild(dtt)
return dc
def loadSettings(self, dc):
g = dc.getAttribute("mode")
self.setMode((constrain.GRANT if g == 'grant' else constrain.LIMIT))
tl = dc.getElementsByTagName("time")
wl = strTime2seconds(tl[0].firstChild.data)
self.setCountdown(wl)
class dailyCountdownTimer(recurringCountdownTimer):
def __init__(self, loadSettings=None):
recurringCountdownTimer.__init__(self)
self.name = 'dailyCountdown'
self.resetPeriod = clock.SECONDS_PER_DAY
self.timeCountdown = [0] * 7
if loadSettings is not None:
self.loadSettings(loadSettings)
def getLastResetTime(self, t = -1):
if t< 0: t= self.now
return clock.getDate(t)
def getCountdown(self, t=-1):
if t< 0: t= self.now
r = self.timeCountdown[clock.getWeekday(t)]
return r
def getCountdownEntries(self):
r = len(set(self.timeCountdown))
return r
def setCountdown(self, pp):
if type(pp) is list:
p= [strTime2seconds(it) for it in pp]
if len(p) == 1:
self.timeCountdown = [ p[0] for i in range(7)]
elif len(p) == 2:
self.timeCountdown = [ p[0] if i<5 else p[1] for i in range(7)]
elif len(p) == 7:
self.timeCountdown = p
else:
print("Error: timeCountdown list should have a length of 1,2 or 7")
return False
else:
self.timeCountdown = [strTime2seconds(pp) for i in range(7)]
self.timeCountdown = [max(0, min(i, self.resetPeriod)) for i in self.timeCountdown]
if self.active:
self.timeEnd = self.now + self.getCountdown()- self.getTimeUsed()
self.update()
else:
self.reset()
return True
def saveSettings(self):
dc = dom.Element('constrain')
dc.setAttribute('type', self.name)
dc.setAttribute('mode', ('grant' if self.mode == self.GRANT else 'limit'))
for i in range(len(self.timeCountdown)):
dt=dc.appendChild(dom.Element("time"))
dt.setAttribute("day", str(i))
dtt=dom.Text()
dtt.data=seconds2strTime(self.timeCountdown[i])
dt.appendChild(dtt)
return dc
def loadSettings(self, dc):
g = dc.getAttribute("mode")
self.setMode((constrain.GRANT if g == 'grant' else constrain.LIMIT))
dl = [0] * 7
for tl in dc.getElementsByTagName("time"):
wday = int(tl.getAttribute("day"))
dl[wday] = strTime2seconds(tl.firstChild.data)
self.setCountdown(dl)
class timerangeTimer(countdownTimer):
def __init__(self, loadSettings=None):
countdownTimer.__init__(self)
self.name = 'timerange'
self.fromTime= 0
self.toTime= 0
if loadSettings is not None:
self.loadSettings(loadSettings)
def reset(self, **p):
return
def update(self):
if self.isActive():
today = clock.getBeginOfDay(self.now)
if self.now < (today + self.getFromTime()):
self.timeLeft = self.now - (today + self.getFromTime())
self.timeEnd = today
else:
self.timeEnd = today + self.getToTime()
self.timeLeft = self.timeEnd - self.now
self.status = (not self.exceeded())
def exceeded(self):
r = not (self.getFromTime()<= self.now - clock.getBeginOfDay(self.now) <= self.getToTime())
return r
def setFromTime(self, p):
s = strptime(p, "%H:%M")
self.fromTime = 3600*s[3]+60 * s[4]
def getFromTime(self, t=-1):
if t < 0: t = self.now
return self.fromTime
def setToTime(self, p):
s = strptime(p, "%H:%M")
self.toTime = 3600*s[3]+60 * s[4]
def getToTime(self, t=-1):
if t < 0: t = self.now
return self.toTime
def saveSettings(self):
dc = dom.Element('constrain')
dc.setAttribute('type', self.name)
dc.setAttribute('mode', ('grant' if self.mode == self.GRANT else 'limit'))
dt=dc.appendChild(dom.Element("time"))
dt.setAttribute("type", 'from')
dtt=dom.Text()
dtt.data=seconds2strTime(self.fromTime)
dt.appendChild(dtt)
dt=dc.appendChild(dom.Element("time"))
dt.setAttribute("type", 'to')
dtt=dom.Text()
dtt.data=seconds2strTime(self.toTime)
dt.appendChild(dtt)
return dc
def loadSettings(self, dc):
g = dc.getAttribute("mode")
self.setMode((constrain.GRANT if g == 'grant' else constrain.LIMIT))
for tl in dc.getElementsByTagName("time"):
l = int(tl.getAttribute("type"))
v = strTime2seconds(tl.firstChild.data)
if l == 'from':
self.setFromTime(v)
elif l == 'to':
self.setToTime(v)
class weekdayTimerangeTimer(timerangeTimer):
def __init__(self, loadSettings=None):
timerangeTimer.__init__(self)
self.name = 'weekdayTimerange'
self.fromTime = [0] * 7
self.toTime = [0] * 7
if loadSettings is not None:
self.loadSettings(loadSettings)
# def update(self):
# dateToday= clock.getDate(self.now)
# timeToday= clock.getTime(self.now)
# if timeToday <= self.getFromTime():
# self.timeUsed = self.getToTime() - self.getFromTime()
# else:
# self.timeUsed = self.now - self.getFromTime()
# self.status = (self.getFromTime() <= self.now - dateToday <= self.getToTime())
def loadStatus(self, fbase):
return True
def saveStatus(self, fbase):
return True
def setFromTime(self, pp):
if type(pp) is list:
p=[]
for it in pp:
p.append(strTime2seconds(it))
#p= [strTime2seconds(it) for it in pp]
if len(p) == 1:
self.fromTime = [ p[0] for i in range(7)]
elif len(p) == 2:
self.fromTime = [ p[0] if i<5 else p[1] for i in range(7)]
elif len(p) == 7:
self.fromTime = p
else:
print("Error: fromtime list should have a length of 1,2 or 7")
return False
else:
self.fromTime = [ strTime2seconds(pp) for i in range(7)]
self.fromTime = [max(0, min(i, clock.SECONDS_PER_DAY)) for i in self.fromTime]
return True
def getFromTime(self, t = -1):
if t < 0: t = self.now
wtoday = clock.getWeekday(t)
return self.fromTime[wtoday]
def setToTime(self, pp):
if type(pp) is list:
p= [strTime2seconds(it) for it in pp]
if len(p) == 1:
self.toTime = [ p[0] for i in range(7)]
elif len(p) == 2:
self.toTime = [ p[0] if i<5 else p[1] for i in range(7)]
elif len(p) == 7:
self.toTime = p
else:
print("Error: totime list should have a length of 1,2 or 7")
return False
else:
self.toTime = [ strTime2seconds(pp) for i in range(7)]
self.toTime = [max(0, min(i, clock.SECONDS_PER_DAY)) for i in self.toTime]
return True
def getToTime(self, t = -1):
if t < 0: t = self.now
wtoday = clock.getWeekday(t)
return self.toTime[wtoday]
def getFromTimeEntries(self):
r = len(set(self.fromTime))
return r
def getToTimeEntries(self):
r = len(set(self.toTime))
return r
def saveSettings(self):
dc = dom.Element('constrain')
dc.setAttribute('type', self.name)
dc.setAttribute('mode', ('grant' if self.mode == self.GRANT else 'limit'))
for t, l in zip([self.fromTime, self.toTime], ['from', 'to']):
for i in range(len(t)):
dt=dc.appendChild(dom.Element("time"))
dt.setAttribute("day", str(i))
dt.setAttribute("type", l)
dtt=dom.Text()
dtt.data=seconds2strTime(t[i])
dt.appendChild(dtt)
return dc
def loadSettings(self, dc):
g = dc.getAttribute("mode")
self.setMode((constrain.GRANT if g == 'grant' else constrain.LIMIT))
flist = [0] * 7
tlist = [0] * 7
for tl in dc.getElementsByTagName("time"):
t = tl.getAttribute("type")
wday = int(tl.getAttribute("day"))
if t == "from":
flist[wday] = strTime2seconds(tl.firstChild.data)
elif t == "to":
tlist[wday] = strTime2seconds(tl.firstChild.data)
self.setFromTime(flist)
self.setToTime(tlist)
class constrainList(object):
CONFIGDIR = ''
STATUSDIR = ''
def __init__(self):
self.constrains = list()
self.settingsLoadTime = 0
self.settingsSavedTime = 0
self.statusLoadTime = 0
def loadStatus(self):
self.statusLoadTime = clock.now()
for l in self.constrains:
# check whether we have a status file for current limit
l.loadStatus(constrainList.STATUSDIR+ '/' + self.name )
def saveStatus(self):
for l in self.constrains:
# check whether we have a status file for current limit
l.saveStatus(constrainList.STATUSDIR + '/' + self.name )
def addConstrain(self, c):
self.constrains.append(c)
return c
def updateConstrains(self):
for l in self.constrains:
l.updateTime()
def deleteConstrains(self):
self.constrains = []
def resetTimer(self):
for l in self.constrains:
if issubclass(type(l), countdownTimer):
l.reset()
def resetConstrains(self):
for l in self.constrains:
l.reset()
def startTimer(self):
for l in self.constrains:
if issubclass(type(l), countdownTimer):
l.start()
def stopTimer(self):
for l in self.constrains:
if issubclass(type(l), countdownTimer):
l.stop()
def getConstrainIndex(self, name=''):
for j in range(len(self.constrains)):
if self.constrains[j].name == name:
return j
return None
def delConstrain(self, index=None, name=''):
if index is not None:
i = index
elif name != '':
i = self.getConstrainIndex(name=name)
if i is not None:
self.constrains.pop(i)
def delConstrains(self):
self.constrains = []
def getConstrain(self, name='', index=None):
if index is not None:
i = index
elif name != '':
i = self.getConstrainIndex(name=name)
if i is None:
return None
return self.constrains[i]
def loadSettings(self, udoc):
self.settingsLoadTime = clock.now()
udoc.getElementsByTagName("modified")
for c in udoc.getElementsByTagName("constrain"):
t=c.getAttribute("type")
if t == "switch":
self.constrains.append(switch(loadSettings=c))
elif t == "countdown":
self.constrains.append(countdownTimer(loadSettings=c))
elif t == "recurringCountdown":
self.constrains.append(recurringCountdownTimer(loadSettings=c))
elif t == "dailyCountdown":
self.addConstrain(dailyCountdownTimer(loadSettings=c))
elif t == "weeklyCountdown":
self.addConstrain(weeklyCountdownTimer(loadSettings=c))
elif t == "monthlyCountdown":
self.addConstrain(monthlyCountdownTimer(loadSettings=c))
elif t == "timerange":
self.constrains.append(timerangeTimer(loadSettings=c))
elif t == "weekdayTimerange":
self.constrains.append(weekdayTimerangeTimer(loadSettings=c))
return True
def saveSettings(self, doc, udoc):
self.settingsSavedTime = clock.now()
if len(self.constrains) > 0:
dl=udoc.appendChild(doc.createElement("constrains"))
for l in self.constrains:
dl.appendChild(l.saveSettings())
def getTimeLeft(self):
t=9999999999
for l in self.constrains:
t=min(t, l.getTimeLeft())
return t
def accessOk(self):
for l in self.constrains:
if l.deny(): return False
return True
def limitingConstrain(self):
t=9999999999
el = None
for l in self.constrains:
tl = l.getTimeLeft()
if tl < t:
t=min(t, tl)
el = l
return el