-
Notifications
You must be signed in to change notification settings - Fork 23
/
collect_script.py
67 lines (49 loc) · 1.44 KB
/
collect_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import platform
import subprocess
import sys
def get_os_info():
return {
"system": platform.system(),
"node": platform.node(),
"release": platform.release(),
"version": platform.version(),
"machine": platform.machine(),
"processor": platform.processor(),
}
def get_python_info():
return {
"implementation": platform.python_implementation(),
"version": platform.python_version(),
"compiler": platform.python_compiler(),
}
def get_pip_list():
result = subprocess.run(
[sys.executable, "-m", "pip", "list"],
capture_output=True,
text=True,
check=False,
)
if result.returncode == 0:
return result.stdout
return f"Failed to get pip list: {result.stderr}"
def write_to_log_file(content, filename="env_output.log"):
with open(filename, "w") as file:
file.write(content)
def main():
os_info = get_os_info()
python_info = get_python_info()
pip_list = get_pip_list()
content = "Operating System Information:\n"
for key, value in os_info.items():
content += f"{key}: {value}\n"
content += "\nPython Information:\n"
for key, value in python_info.items():
content += f"{key}: {value}\n"
content += "\nPip List:\n"
content += pip_list
# stdout
print(content) # noqa: T201
# file
write_to_log_file(content)
if __name__ == "__main__":
main()