22
22
23
23
TIMEMULTS = {'s' : 1 , 'm' : 60 , 'h' : 3600 }
24
24
25
- def get_package_dir (prog ):
26
- if sys .version_info >= (3 , 10 ):
27
- from importlib .resources import files
28
- else :
29
- from importlib_resources import files
30
-
31
- return files (Path (prog ).stem .replace ('-' , '_' ))
32
-
33
25
def conv_to_secs (val ):
34
26
'Convert given time string to float seconds'
35
27
# Default input time value (without qualifier) is minutes
@@ -138,8 +130,10 @@ def init():
138
130
opt .add_argument ('-i' , '--inhibit' , help = argparse .SUPPRESS )
139
131
args = opt .parse_args ()
140
132
133
+ base_dir = Path (__file__ ).resolve ().parent
134
+
141
135
if args .package_dir :
142
- print (get_package_dir ( opt . prog ) )
136
+ print (base_dir )
143
137
sys .exit ()
144
138
145
139
# This instance may be a child invocation merely to run and check
@@ -178,25 +172,16 @@ def init():
178
172
opts = ' or ' .join (SYSTEMD_SLEEP_PROGS )
179
173
sys .exit (f'No systemd-inhibitor app installed from one of { opts } .' )
180
174
181
- # Work out plugin and base dirs for this installation
182
- plugin_dir = Path (sys .prefix ) / 'share' / progname / 'plugins'
183
- if plugin_dir .exists ():
184
- base_dir = plugin_dir .parent
185
- else :
186
- plugin_dir = None
187
- base_dir = None
188
-
189
175
# Determine config file path
190
176
cname = progname + '.conf'
191
177
cfile = Path (args .config ).expanduser () if args .config else \
192
178
Path (f'/etc/{ cname } ' )
193
179
194
180
if not cfile .exists ():
195
- print (f'Configuration file { cfile } does not exist.' , file = sys .stderr )
196
- if base_dir and not args .config :
197
- print (f'Copy { base_dir } /{ cname } to /etc and edit appropriately.' ,
198
- file = sys .stderr )
199
- sys .exit ()
181
+ err = f'Configuration file { cfile } does not exist.'
182
+ if not args .config :
183
+ err += f' Copy { base_dir } /{ cname } to /etc and edit appropriately.'
184
+ sys .exit (err )
200
185
201
186
from ruamel .yaml import YAML
202
187
conf = YAML (typ = 'safe' ).load (cfile )
@@ -206,6 +191,8 @@ def init():
206
191
sys .exit ('No plugins configured' )
207
192
208
193
# Work out plugin dir
194
+ plugin_dir = base_dir / 'plugins'
195
+ plugin_dir = str (plugin_dir ) if plugin_dir .is_dir () else None
209
196
plugin_dir = args .plugin_dir or conf .get ('plugin_dir' , plugin_dir )
210
197
211
198
# Get some global defaults
0 commit comments