Skip to content

Commit a4ff48c

Browse files
committed
Fix variable name clash
Program was setting wrong "who"string in `systemd-inhibit --list` output.
1 parent 8f0cb8b commit a4ff48c

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
setup(
1313
name=name,
14-
version='1.13',
14+
version='1.14',
1515
description='Program to run plugins to inhibit system '
1616
'sleep/suspend/hibernate',
1717
long_description=here.joinpath('README.md').read_text(),

sleep_inhibitor.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Plugin:
3030
loglock = threading.Lock()
3131
threads = []
3232

33-
def __init__(self, index, prog, name, conf, plugin_dir, inhibitor_prog):
33+
def __init__(self, index, prog, progname, conf, plugin_dir, inhibitor_prog):
3434
'Constructor'
3535
pathstr = conf.get('path')
3636
if not pathstr:
@@ -69,7 +69,7 @@ def __init__(self, index, prog, name, conf, plugin_dir, inhibitor_prog):
6969
# While inhibiting, we run outself again via systemd-inhibit to
7070
# run the plugin in a loop which keeps the inhibit on while the
7171
# inhibit state is returned.
72-
self.icmd = shlex.split(f'{inhibitor_prog}{what} --who="{name}" '
72+
self.icmd = shlex.split(f'{inhibitor_prog}{what} --who="{progname}" '
7373
f'--why="{self.name}" {prog} -s {self.period} -i "{cmd}"')
7474

7575
print(f'{self.name} [{path}] configured @ {period} minutes')
@@ -137,7 +137,7 @@ def init():
137137
sys.exit(res.returncode)
138138

139139
prog = Path(sys.argv[0]).resolve()
140-
name = prog.stem.replace('_', '-')
140+
progname = prog.stem.replace('_', '-')
141141

142142
# Work out what sleep inhibitor program to use
143143
inhibitor_prog = None
@@ -150,29 +150,28 @@ def init():
150150
continue
151151

152152
vers = res.stdout.split('\n')[0].strip()
153-
print(f'{name} using {iprog}, {vers}')
153+
print(f'{progname} using {iprog}, {vers}')
154154
inhibitor_prog = iprog
155155

156156
if not inhibitor_prog:
157157
opts = ' or '.join(SYSTEMD_SLEEP_PROGS)
158158
sys.exit(f'No systemd-inhibitor app installed from one of {opts}.')
159159

160160
# Work out plugin and base dirs for this installation
161-
plugin_dir = Path(sys.prefix) / 'share' / name / 'plugins'
161+
plugin_dir = Path(sys.prefix) / 'share' / progname / 'plugins'
162162
if plugin_dir.exists():
163163
base_dir = plugin_dir.parent
164164
else:
165165
plugin_dir = None
166166
base_dir = None
167167

168168
# Determine config file path
169-
cname = name + '.conf'
169+
cname = progname + '.conf'
170170
cfile = Path(args.config).expanduser() if args.config else \
171171
Path(f'/etc/{cname}')
172172

173173
if not cfile.exists():
174-
print(f'{name} configuration file {cfile} does not exist.',
175-
file=sys.stderr)
174+
print(f'Configuration file {cfile} does not exist.', file=sys.stderr)
176175
if base_dir and not args.config:
177176
print(f'Copy {base_dir}/{cname} to /etc and edit appropriately.',
178177
file=sys.stderr)
@@ -190,7 +189,7 @@ def init():
190189

191190
# Iterate to create each configured plugins
192191
for index, plugin in enumerate(plugins, 1):
193-
Plugin(index, prog, name, plugin, plugin_dir, inhibitor_prog)
192+
Plugin(index, prog, progname, plugin, plugin_dir, inhibitor_prog)
194193

195194
def main():
196195
'Main entry'

0 commit comments

Comments
 (0)