From b9a1ec6a2ac9cdd9ef67c83942fbe91ed8bafd70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 22 Jan 2021 22:51:21 +0100 Subject: [PATCH] eoptasks: add possibility to define command shortcuts in config file --- eoptasks/eoptasks.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/eoptasks/eoptasks.py b/eoptasks/eoptasks.py index 7aab5a3..ca5f1d5 100755 --- a/eoptasks/eoptasks.py +++ b/eoptasks/eoptasks.py @@ -20,6 +20,10 @@ # ignore = server1, server2 # stripsuffix = .entrouvert.org # +# It is possible to add extra command shortcuts with additional sections, ex: +# [command:memcached.restart] +# cmd = sudo service memcached restart; /bin/true +# # Examples: # # eoptasks -k test apt.upgrade @@ -221,8 +225,11 @@ def send_status_message(tmux_session_name, msg): def command_window(args): + config = configparser.ConfigParser() + config.read(os.path.join(os.path.expanduser('~/.config/eoptasks.ini'))) + tmux_session_name = args.session_name - cmd = { + builtin_cmds = { 'apt.update': 'sudo apt update', 'apt.upgrade': 'sudo apt update && sudo apt full-upgrade -y', # collectstatic is useful after an upgrade of gadjo. @@ -250,7 +257,14 @@ def command_window(args): 'wcs.restart': '''sudo systemctl restart wcs; /bin/true''', # puppet.update, unfortunately without proper error checking. 'puppet.update': '''sudo puppet agent -t || true''', - }.get(args.cmd, args.cmd) + } + if config.has_section('command:%s' % args.cmd): + cmd = config.get('command:%s' % args.cmd, 'cmd') + elif args.cmd in builtin_cmds: + cmd = builtin_cmds[args.cmd] + else: + cmd = args.cmd + if args.args: cmd += ' ' + ' '.join(['"%s"' % x for x in args.args]) orig_cmd = cmd