From 6f1d05bbc21516fde45b190b4cd539b7332b56b3 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Mon, 1 Apr 2019 10:47:44 +0200 Subject: Allow to run in batch mode by specifying the profile ID monitor-menu.py now takes an additional optional argument: . When specified, the script will attempt to load the configuration of the profile specified. Signed-off-by: Olivier Gayot --- monitor-menu.py | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/monitor-menu.py b/monitor-menu.py index 423faee..c81f753 100755 --- a/monitor-menu.py +++ b/monitor-menu.py @@ -1,8 +1,16 @@ #!/usr/bin/env python3 +''' +monitor-menu.py +Usage: + monitor-menu.py + monitor-menu.py +''' + from os.path import expanduser import dialog +import docopt import json import subprocess @@ -13,18 +21,19 @@ class MonitorMenu(): with open(expanduser(config_file)) as fd: self.profiles = json.load(fd) - def run(self): + def run(self, profile_idx=None): choices = [] - i = 0 - for p in self.profiles: - choices.append((str(i), p['name'])) - i += 1 + if profile_idx is None: + i = 0 + for p in self.profiles: + choices.append((str(i), p['name'])) + i += 1 - code, profile_idx = d.menu('Select the profile you want to use.', choices=choices) + code, profile_idx = d.menu('Select the profile you want to use.', choices=choices) - if code == d.ESC or code == d.CANCEL: - return + if code == d.ESC or code == d.CANCEL: + return profile = self.profiles[int(profile_idx)] @@ -47,10 +56,19 @@ class MonitorMenu(): subprocess.run(feh_cmd) -def main(): +def main(argv=None): + args = docopt.docopt(__doc__, version='1', argv=argv) + menu = MonitorMenu() - menu.run() + try: + if '' in args: + menu.run(int(args[''])) + else: + menu.run() + + except ValueError as e: + raise docopt.DocoptExit(str(e)) if __name__ == '__main__': main() -- cgit v1.2.3