Coverage for python/lsst/ctrl/bps/parsl/environment.py: 14%
13 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-20 09:31 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-20 09:31 +0000
1import os
3__all__ = ("export_environment",)
6def export_environment():
7 """Generate bash script to regenerate the current environment"""
8 output = ""
9 for key, val in os.environ.items():
10 if key in ("DISPLAY",):
11 continue
12 if val.startswith("() {"):
13 # This is a function.
14 # "Two parentheses, a single space, and a brace"
15 # is exactly the same criterion as bash uses.
17 # From 2014-09-25, the function name is prefixed by 'BASH_FUNC_'
18 # and suffixed by '()', which we have to remove.
19 if key.startswith("BASH_FUNC_") and key.endswith("()"):
20 key = key[10:-2]
22 output += "{key} {val}\nexport -f {key}\n".format(key=key, val=val)
23 else:
24 # This is a variable.
25 output += "export {key}='{val}'\n".format(key=key, val=val.replace("'", "'\"'\"'"))
26 return output