2019-03-11 23:48:40 -03:00
|
|
|
import os, time
|
|
|
|
|
|
2019-03-13 09:15:15 -03:00
|
|
|
from lib import Config
|
2019-03-11 23:48:40 -03:00
|
|
|
|
|
|
|
|
def check_timers(config):
|
|
|
|
|
'''Will check every timer setup for it's usage and limits'''
|
|
|
|
|
for timer in config.timers:
|
|
|
|
|
# restore timers after interval
|
|
|
|
|
if timer.usage.isOffInterval():
|
|
|
|
|
print('Timer %s is off interval' % timer.name)
|
|
|
|
|
timer.usage.release()
|
2019-03-13 09:12:01 -03:00
|
|
|
if not timer.isRunning():
|
|
|
|
|
continue
|
|
|
|
|
print('Timer %s is running' % timer.name)
|
2025-11-12 23:19:09 +02:00
|
|
|
timer.maybeWarn(config.checkInterval)
|
2019-03-11 23:48:40 -03:00
|
|
|
# check for off limit apps
|
|
|
|
|
if timer.usage.isOffLimit():
|
|
|
|
|
print('Timer %s is off limit' % timer.name)
|
|
|
|
|
timer.block()
|
|
|
|
|
# increment running apps timer
|
|
|
|
|
timer.usage.increment(config.checkInterval)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config = Config()
|
|
|
|
|
while True:
|
|
|
|
|
# check config changes
|
|
|
|
|
if config.hasChanges():
|
|
|
|
|
print('Config has changes')
|
|
|
|
|
config.reload()
|
|
|
|
|
# check app timers
|
|
|
|
|
check_timers(config)
|
|
|
|
|
# wait interval in minutes
|
|
|
|
|
time.sleep(-time.time() % (config.checkInterval * 60))
|