@@ -30,7 +30,7 @@ class Plugin:
30
30
loglock = threading .Lock ()
31
31
threads = []
32
32
33
- def __init__ (self , index , prog , conf , plugin_dir , inhibitor_prog ):
33
+ def __init__ (self , index , prog , name , conf , plugin_dir , inhibitor_prog ):
34
34
'Constructor'
35
35
pathstr = conf .get ('path' )
36
36
if not pathstr :
@@ -69,7 +69,7 @@ def __init__(self, index, prog, conf, plugin_dir, inhibitor_prog):
69
69
# While inhibiting, we run outself again via systemd-inhibit to
70
70
# run the plugin in a loop which keeps the inhibit on while the
71
71
# inhibit state is returned.
72
- self .icmd = shlex .split (f'{ inhibitor_prog } { what } --who="{ prog . name } " '
72
+ self .icmd = shlex .split (f'{ inhibitor_prog } { what } --who="{ name } " '
73
73
f'--why="{ self .name } " { prog } -s { self .period } -i "{ cmd } "' )
74
74
75
75
print (f'{ self .name } [{ path } ] configured @ { period } minutes' )
@@ -137,6 +137,7 @@ def init():
137
137
sys .exit (res .returncode )
138
138
139
139
prog = Path (sys .argv [0 ]).resolve ()
140
+ name = prog .stem .replace ('_' , '-' )
140
141
141
142
# Work out what sleep inhibitor program to use
142
143
inhibitor_prog = None
@@ -149,28 +150,28 @@ def init():
149
150
continue
150
151
151
152
vers = res .stdout .split ('\n ' )[0 ].strip ()
152
- print (f'{ prog . name } using { iprog } , { vers } ' )
153
+ print (f'{ name } using { iprog } , { vers } ' )
153
154
inhibitor_prog = iprog
154
155
155
156
if not inhibitor_prog :
156
157
opts = ' or ' .join (SYSTEMD_SLEEP_PROGS )
157
158
sys .exit (f'No systemd-inhibitor app installed from one of { opts } .' )
158
159
159
160
# Work out plugin and base dirs for this installation
160
- plugin_dir = Path (sys .prefix ) / 'share' / prog . name / 'plugins'
161
+ plugin_dir = Path (sys .prefix ) / 'share' / name / 'plugins'
161
162
if plugin_dir .exists ():
162
163
base_dir = plugin_dir .parent
163
164
else :
164
165
plugin_dir = None
165
166
base_dir = None
166
167
167
168
# Determine config file path
168
- cname = prog . name + '.conf'
169
+ cname = name + '.conf'
169
170
cfile = Path (args .config ).expanduser () if args .config else \
170
171
Path (f'/etc/{ cname } ' )
171
172
172
173
if not cfile .exists ():
173
- print (f'{ prog . name } configuration file { cfile } does not exist.' ,
174
+ print (f'{ name } configuration file { cfile } does not exist.' ,
174
175
file = sys .stderr )
175
176
if base_dir and not args .config :
176
177
print (f'Copy { base_dir } /{ cname } to /etc and edit appropriately.' ,
@@ -189,7 +190,7 @@ def init():
189
190
190
191
# Iterate to create each configured plugins
191
192
for index , plugin in enumerate (plugins , 1 ):
192
- Plugin (index , prog , plugin , plugin_dir , inhibitor_prog )
193
+ Plugin (index , prog , name , plugin , plugin_dir , inhibitor_prog )
193
194
194
195
def main ():
195
196
'Main entry'
0 commit comments