summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2021-01-22 21:51:21 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2021-01-22 21:51:21 (GMT)
commitb9a1ec6a2ac9cdd9ef67c83942fbe91ed8bafd70 (patch)
tree531106903bb9b531813d788df73a18b624bb888f
parent8e4427dae64833ed4149b6e5517e9bb92f3b0ba9 (diff)
downloadmisc-fred-b9a1ec6a2ac9cdd9ef67c83942fbe91ed8bafd70.zip
misc-fred-b9a1ec6a2ac9cdd9ef67c83942fbe91ed8bafd70.tar.gz
misc-fred-b9a1ec6a2ac9cdd9ef67c83942fbe91ed8bafd70.tar.bz2
eoptasks: add possibility to define command shortcuts in config file
-rwxr-xr-xeoptasks/eoptasks.py18
1 files 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