Add printenv for linux (PY-15085)

This commit is contained in:
Dmitry Trofimov
2016-09-28 15:02:17 +02:00
parent 73f082e1f2
commit 43cc6f5519
2 changed files with 23 additions and 3 deletions
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env python
# Dumps environment variables into specified file.
# Format: zero-separated "name=value" pairs in platform encoding.
import os
import sys
if len(sys.argv) != 2:
raise Exception('Exactly one argument expected')
f = open(sys.argv[1], 'wb')
try:
for key, value in os.environ.items():
s = '%s=%s\0' % (key, value)
f.write(s.encode('utf-8'))
finally:
f.close()
@@ -161,10 +161,11 @@ public class EnvironmentUtil {
public static class ShellEnvReader {
public Map<String, String> readShellEnv() throws Exception {
String os = SystemInfo.isLinux ? "linux" : "mac";
File reader = FileUtil.findFirstThatExist(
PathManager.getBinPath() + "/printenv.py",
PathManager.getHomePath() + "/community/bin/mac/printenv.py",
PathManager.getHomePath() + "/bin/mac/printenv.py");
PathManager.getHomePath() + "/community/bin/" + os + "/printenv.py",
PathManager.getHomePath() + "/bin/" + os + "/printenv.py");
if (reader == null) {
throw new Exception("bin:" + PathManager.getBinPath());
}
@@ -185,7 +186,8 @@ public class EnvironmentUtil {
}
@NotNull
protected static Map<String, String> runProcessAndReadEnvs(@NotNull List<String> command, @NotNull File envFile, String lineSeparator) throws Exception {
protected static Map<String, String> runProcessAndReadEnvs(@NotNull List<String> command, @NotNull File envFile, String lineSeparator)
throws Exception {
ProcessBuilder builder = new ProcessBuilder(command).redirectErrorStream(true);
builder.environment().put(DISABLE_OMZ_AUTO_UPDATE, "true");
Process process = builder.start();