@@ -27,15 +27,15 @@ class Plugin:
27
27
loglock = threading .Lock ()
28
28
threads = []
29
29
30
- def __init__ (self , index , prog , progname , def_period , def_what ,
31
- conf , plugin_dir , inhibitor_prog ):
30
+ def __init__ (self , index , prog , progname , def_period , def_period_on ,
31
+ def_what , conf , plugin_dir , inhibitor_prog ):
32
32
'Constructor'
33
33
pathstr = conf .get ('path' )
34
34
if not pathstr :
35
35
sys .exit (f'Plugin #{ index } : path must be defined' )
36
36
37
37
path = Path (pathstr )
38
- name = conf .get ('name' , path .name )
38
+ name = conf .get ('name' , path .stem )
39
39
self .name = f'Plugin { name } '
40
40
41
41
if not path .is_absolute ():
@@ -49,7 +49,15 @@ def __init__(self, index, prog, progname, def_period, def_what,
49
49
if not path .exists ():
50
50
sys .exit (f'{ self .name } : "{ path } " does not exist' )
51
51
52
- period = float (conf .get ('period' , def_period ))
52
+ per = conf .get ('period' )
53
+ if per is None :
54
+ period = def_period
55
+ period_on_def = def_period_on
56
+ else :
57
+ period = float (per )
58
+ period_on_def = period
59
+
60
+ period_on = float (conf .get ('period_on' , period_on_def ))
53
61
self .period = period * 60
54
62
self .is_inhibiting = None
55
63
@@ -68,9 +76,9 @@ def __init__(self, index, prog, progname, def_period, def_what,
68
76
# run the plugin in a loop which keeps the inhibit on while the
69
77
# inhibit state is returned.
70
78
self .icmd = shlex .split (f'{ inhibitor_prog } { what } --who="{ progname } " '
71
- f'--why="{ self .name } " { prog } -s { self . period } -i "{ cmd } "' )
79
+ f'--why="{ self .name } " { prog } -s { period_on * 60 } -i "{ cmd } "' )
72
80
73
- print (f'{ self .name } [{ path } ] configured @ { period } minutes' )
81
+ print (f'{ self .name } [{ path } ] configured @ { period } / { period_on } minutes' )
74
82
75
83
# Each plugin periodic check runs in it's own thread
76
84
thread = threading .Thread (target = self .run )
@@ -186,12 +194,13 @@ def init():
186
194
187
195
# Get some global defaults
188
196
period = float (conf .get ('period' , 5 ))
197
+ period_on = float (conf .get ('period_on' , period ))
189
198
what = conf .get ('what' )
190
199
191
200
# Iterate to create each configured plugins
192
201
for index , plugin in enumerate (plugins , 1 ):
193
- Plugin (index , prog , progname , period , what , plugin , plugin_dir ,
194
- inhibitor_prog )
202
+ Plugin (index , prog , progname , period , period_on , what , plugin ,
203
+ plugin_dir , inhibitor_prog )
195
204
196
205
def main ():
197
206
'Main entry'
0 commit comments