Files
openide/bin/linux/printenv.py
Andrey Vlasovskikh f07f53d38e PY-40974 Always treat environment variables as raw bytes
It's unnecessary and sometimes wrong to assume any encoding
for an environment variable. They can be encoded differently
depending on the requirements of programs that utilize them.
In our case we just need to pass all the environment
variables "as is" to the IDE process.

I've modified printenv.py so that it's the same version of
the script for both Linux and macOS and for all the Python
versions from 2.3 to at least 3.9.

GitOrigin-RevId: 40d73ef6eb56da8609d75fbce8a4a04c52e317b4
2020-05-31 15:45:29 +03:00

34 lines
646 B
Python
Executable File

#!/usr/bin/env python
# Dumps environment variables into specified file.
# Format: zero-separated "name=value" pairs in platform encoding.
# The script can work with any version of Python from 2.3 to at least 3.9
import os
import sys
if len(sys.argv) != 2:
raise Exception('Exactly one argument expected')
PY2 = sys.version_info < (3,)
if PY2:
environ = os.environ
else:
environ = os.environb
def b(s):
if PY2:
return s
else:
return s.encode('utf-8')
fd = open(sys.argv[1], 'wb')
try:
for key, value in environ.items():
fd.writelines([key, b('='), value, b('\0')])
finally:
fd.close()