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
2023-01-27 11:53:51 +02:00

46 lines
1.3 KiB
Python

# 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 number in range(len(names)):
print(chr(ord("a") + number) + ") " + names[number] + " " + "[" + getValue(values[number]) + "]")
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())"]
selection = None
while True:
printList(names, data)
selection = input()
if selection == "y":
break
if not len(selection) == 1 or ord(selection) < ord("a") or ord(selection) >= (ord("a") + len(names)):
print("Invalid selection.")
continue
number = ord(selection) - ord("a")
data[number] = not data[number]
file_out = open("data.txt", "w")
for number in range(len(data)):
if data[number]:
writeData(file_out, names[number], code[number])
file_out.close()