add support for (re)defining environment variables
This commit is contained in:
parent
bd157f9a07
commit
11b21739cb
14
README
14
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
|
||||
--------
|
||||
|
||||
|
|
19
eoptasks.py
19
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'}}
|
||||
|
|
Loading…
Reference in New Issue