This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2022_Stanislav_Mykhailenko/Lesson_4/task1.py

47 lines
1.3 KiB
Python
Raw Normal View History

2023-01-06 15:22:20 +00:00
# Lesson 4 Task 1: write system info to a file
# Author: Stanislav Mykhailenko
# License: Unlicense
# Return codes:
# 0 - OK
import platform, psutil, os, serial.tools.list_ports
def getValue(checkedValue):
if checkedValue:
return "yes"
else:
return "no"
def printList(names, values):
for i in range(len(names)):
print(chr(ord("a") + i) + ") " + names[i] + " " + "[" + getValue(values[i]) + "]")
print("y) Proceed")
def writeData(file, name, code):
file.write(name + ": " + eval(code) + "\n")
names = ["CPU", "Architecture", "CPU Family", "RAM", "Operating system", "Disk usage", "Serial ports"]
data = [False] * len(names)
code = ["platform.processor()", "str(platform.architecture())", "platform.machine()", "str(psutil.virtual_memory())", "os.name", "str(psutil.disk_usage(\".\"))", "str(serial.tools.list_ports.comports())"]
2023-01-06 15:22:20 +00:00
selection = None
while True:
printList(names, data)
selection = input()
2023-01-06 15:22:20 +00:00
if selection == "y":
break
if not len(selection) == 1 or ord(selection) < ord("a") or ord(selection) >= (ord("a") + len(names)):
2023-01-06 15:22:20 +00:00
print("Invalid selection.")
continue
number = ord(selection) - ord("a")
data[number] = not data[number]
file_out = open("data.txt", "w")
2023-01-06 15:22:20 +00:00
for i in range(len(data)):
if data[i]:
writeData(file_out, names[i], code[i])
2023-01-06 15:22:20 +00:00
file_out.close()