Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support env_file directive to add environment to subprocess by file #934

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions supervisor/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ def dict_of_key_value_pairs(arg):
i += 4
return D

def dict_from_env_file(fpath):
""" read file fpath with each line KEY=VAL into {'KEY': 'VAL'} """

D = {}
try:
import re
f = open(fpath, 'rt')
for line in f.readlines():
line = line.strip()
m = re.match(r'(.+)=(.+)', line)
if m:
key, val = m.groups()
D.update({key: val})
except FileNotFoundError:
pass
finally:
f.close()

return D

class Automatic:
pass

Expand Down
3 changes: 3 additions & 0 deletions supervisor/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from supervisor.datatypes import signal_number
from supervisor.datatypes import list_of_exitcodes
from supervisor.datatypes import dict_of_key_value_pairs
from supervisor.datatypes import dict_from_env_file
from supervisor.datatypes import logfile_name
from supervisor.datatypes import list_of_strings
from supervisor.datatypes import octal_type
Expand Down Expand Up @@ -885,6 +886,7 @@ def get(section, opt, *args, **kwargs):
numprocs = integer(get(section, 'numprocs', 1))
numprocs_start = integer(get(section, 'numprocs_start', 0))
environment_str = get(section, 'environment', '', do_expand=False)
env_file = get(section, 'env_file', '', do_expand=False)
stdout_cmaxbytes = byte_size(get(section,'stdout_capture_maxbytes','0'))
stdout_events = boolean(get(section, 'stdout_events_enabled','false'))
stderr_cmaxbytes = byte_size(get(section,'stderr_capture_maxbytes','0'))
Expand Down Expand Up @@ -927,6 +929,7 @@ def get(section, opt, *args, **kwargs):

environment = dict_of_key_value_pairs(
expand(environment_str, expansions, 'environment'))
environment.update(dict_from_env_file(env_file))

directory = get(section, 'directory', None)

Expand Down