summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2021-06-05 19:45:19 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2021-06-05 19:45:19 (GMT)
commit11b21739cbeee401572c8621f40ac25603b2ac69 (patch)
treee96ebd5e35861c17860cfdd927c795cf62e09d5f
parentbd157f9a071fc6a883a2f744fb9d7e47ac88c043 (diff)
downloadeoptasks-11b21739cbeee401572c8621f40ac25603b2ac69.zip
eoptasks-11b21739cbeee401572c8621f40ac25603b2ac69.tar.gz
eoptasks-11b21739cbeee401572c8621f40ac25603b2ac69.tar.bz2
add support for (re)defining environment variables
-rw-r--r--README14
-rwxr-xr-xeoptasks.py19
2 files changed, 32 insertions, 1 deletions
diff --git a/README b/README
index f848622..777319c 100644
--- a/README
+++ b/README
@@ -50,6 +50,20 @@ or to prevent common errors or misconceptions::
saas/test = saas/test,-hds,-re,-docbow
+Custom server options can be defined in [server:SERVER_NAME] sections, ex::
+
+ [server:server1.local]
+ env = TERM=xterm
+
+
+Any option starting with env will be used to define or replace environment
+variables, ex::
+
+ [server:server1.local]
+ env = TERM=xterm
+ env1 = PS1=LANG=C.UTF-8
+
+
Examples
--------
diff --git a/eoptasks.py b/eoptasks.py
index d7bbb52..fe865ad 100755
--- a/eoptasks.py
+++ b/eoptasks.py
@@ -18,6 +18,7 @@
import argparse
import configparser
+import copy
import curses
import json
import os
@@ -272,9 +273,25 @@ def command_window(args):
if args.args:
cmd += ' ' + ' '.join(['"%s"' % x for x in args.args])
orig_cmd = cmd
+
+ config = get_config()
+ environ = {}
+ if config.has_section('server:%s' % args.command_server_name):
+ new_environ = {}
+ for key, value in config.items('server:%s' % args.command_server_name):
+ if key.startswith('env'):
+ new_environ[value.split('=', 1)[0]] = value.split('=', 1)[1]
+ if new_environ:
+ environ = copy.copy(os.environ)
+ environ.update(new_environ)
+
+ call_kwargs = {}
+ if environ:
+ call_kwargs['env'] = environ
+
while True:
# -t: force a tty for interactive commands.
- rc = subprocess.call(['ssh', '-t', args.command_server_name] + [cmd])
+ rc = subprocess.call(['ssh', '-t', args.command_server_name] + [cmd], **call_kwargs)
if rc == 0:
send_status_message(
tmux_session_name, {'@type': 'server-result', 'info': {args.command_server_name: 'success'}}