Skip to content

Commit

Permalink
wm_win_tool.py: improve missing command behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans-Peter Jansen committed Mar 2, 2020
1 parent 9297fe2 commit 542290b
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions wm_win_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,17 @@ def command(cmd, *args):
return res.returncode, res.stdout


def test_command(cmd, *args):
cmdstr = '%s %s' % (cmd, ' '.join(args))
try:
rc, buf = command(cmd, *args)
except OSError as e:
log.debug('%s: %s' % (cmdstr, e))
return -1, '%s: program not found' % cmdstr
else:
return rc, '%s: failed with error: %s' % (cmdstr, buf)


def wmctrl_list():
'''run wmctrl -lGpx, return WinList'''
log.info('collect window list')
Expand Down Expand Up @@ -710,19 +721,10 @@ def main():

setup_logging(gpar.loglevel)

rc, _ = command('wmctrl', '-h')
if rc:
exit(2, 'program wmctrl not found')

rc, _ = command('xprop', '-version')
if rc:
exit(2, 'program xprop not found')

if not os.path.isdir(gpar.storelistdir):
try:
os.makedirs(gpar.storelistdir, 0o755)
except OSError as e:
exit(3, e)
for cmd in (('wmctrl', '-h'), ('xprop', '-version')):
rc, msg = test_command(*cmd)
if rc:
exit(2, msg)

disp = {
'store': store,
Expand Down

0 comments on commit 542290b

Please sign in to comment.