eoptasks: add possibility to define command shortcuts in config file
This commit is contained in:
parent
8e4427dae6
commit
b9a1ec6a2a
|
@ -20,6 +20,10 @@
|
||||||
# ignore = server1, server2
|
# ignore = server1, server2
|
||||||
# stripsuffix = .entrouvert.org
|
# 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:
|
# Examples:
|
||||||
#
|
#
|
||||||
# eoptasks -k test apt.upgrade
|
# eoptasks -k test apt.upgrade
|
||||||
|
@ -221,8 +225,11 @@ def send_status_message(tmux_session_name, msg):
|
||||||
|
|
||||||
|
|
||||||
def command_window(args):
|
def command_window(args):
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read(os.path.join(os.path.expanduser('~/.config/eoptasks.ini')))
|
||||||
|
|
||||||
tmux_session_name = args.session_name
|
tmux_session_name = args.session_name
|
||||||
cmd = {
|
builtin_cmds = {
|
||||||
'apt.update': 'sudo apt update',
|
'apt.update': 'sudo apt update',
|
||||||
'apt.upgrade': 'sudo apt update && sudo apt full-upgrade -y',
|
'apt.upgrade': 'sudo apt update && sudo apt full-upgrade -y',
|
||||||
# collectstatic is useful after an upgrade of gadjo.
|
# collectstatic is useful after an upgrade of gadjo.
|
||||||
|
@ -250,7 +257,14 @@ def command_window(args):
|
||||||
'wcs.restart': '''sudo systemctl restart wcs; /bin/true''',
|
'wcs.restart': '''sudo systemctl restart wcs; /bin/true''',
|
||||||
# puppet.update, unfortunately without proper error checking.
|
# puppet.update, unfortunately without proper error checking.
|
||||||
'puppet.update': '''sudo puppet agent -t || true''',
|
'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:
|
if args.args:
|
||||||
cmd += ' ' + ' '.join(['"%s"' % x for x in args.args])
|
cmd += ' ' + ' '.join(['"%s"' % x for x in args.args])
|
||||||
orig_cmd = cmd
|
orig_cmd = cmd
|
||||||
|
|
Loading…
Reference in New Issue