15
15
# Return code which indicates plugin wants to inhibit suspend
16
16
SUSP_CODE = 254
17
17
18
- # Default check period in minutes if not specified for plugin in config
19
- DEF_PERIOD = 5
20
-
21
18
# On some non-systemd systems, systemd-inhibit emulators are used
22
19
# instead. The first found below is the one we use:
23
20
SYSTEMD_SLEEP_PROGS = (
@@ -30,7 +27,8 @@ class Plugin:
30
27
loglock = threading .Lock ()
31
28
threads = []
32
29
33
- def __init__ (self , index , prog , progname , conf , plugin_dir , inhibitor_prog ):
30
+ def __init__ (self , index , prog , progname , def_period , def_what ,
31
+ conf , plugin_dir , inhibitor_prog ):
34
32
'Constructor'
35
33
pathstr = conf .get ('path' )
36
34
if not pathstr :
@@ -51,7 +49,7 @@ def __init__(self, index, prog, progname, conf, plugin_dir, inhibitor_prog):
51
49
if not path .exists ():
52
50
sys .exit (f'{ self .name } : "{ path } " does not exist' )
53
51
54
- period = float (conf .get ('period' , DEF_PERIOD ))
52
+ period = float (conf .get ('period' , def_period ))
55
53
self .period = period * 60
56
54
self .is_inhibiting = None
57
55
@@ -63,7 +61,7 @@ def __init__(self, index, prog, progname, conf, plugin_dir, inhibitor_prog):
63
61
# The normal periodic check command
64
62
self .cmd = shlex .split (cmd )
65
63
66
- whatval = conf .get ('what' )
64
+ whatval = conf .get ('what' , def_what )
67
65
what = f' --what="{ whatval } "' if whatval else ''
68
66
69
67
# While inhibiting, we run outself again via systemd-inhibit to
@@ -111,7 +109,6 @@ def log(cls, msg):
111
109
112
110
def init ():
113
111
'Program initialisation'
114
-
115
112
# Process command line options
116
113
opt = argparse .ArgumentParser (description = __doc__ .strip ())
117
114
opt .add_argument ('-c' , '--config' ,
@@ -187,9 +184,14 @@ def init():
187
184
# Work out plugin dir
188
185
plugin_dir = args .plugin_dir or conf .get ('plugin_dir' , plugin_dir )
189
186
187
+ # Get some global defaults
188
+ period = float (conf .get ('period' , 5 ))
189
+ what = conf .get ('what' )
190
+
190
191
# Iterate to create each configured plugins
191
192
for index , plugin in enumerate (plugins , 1 ):
192
- Plugin (index , prog , progname , plugin , plugin_dir , inhibitor_prog )
193
+ Plugin (index , prog , progname , period , what , plugin , plugin_dir ,
194
+ inhibitor_prog )
193
195
194
196
def main ():
195
197
'Main entry'
0 commit comments