diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2019-04-01 10:47:44 +0200 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2019-04-01 10:47:44 +0200 |
commit | 6f1d05bbc21516fde45b190b4cd539b7332b56b3 (patch) | |
tree | 6fd7efe0e133598adababfc0185c4eac42fc5c94 /monitor-menu.py | |
parent | 970b2e90d1fa6c0f2e23d7528e7bc0c0b1030a14 (diff) |
Allow to run in batch mode by specifying the profile ID
monitor-menu.py now takes an additional optional argument: <profile>.
When specified, the script will attempt to load the configuration of the
profile specified.
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'monitor-menu.py')
-rwxr-xr-x | monitor-menu.py | 38 |
1 files 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 <profile> +''' + 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 '<profile>' in args: + menu.run(int(args['<profile>'])) + else: + menu.run() + + except ValueError as e: + raise docopt.DocoptExit(str(e)) if __name__ == '__main__': main() |