Skip to content

Commit 7152a67

Browse files
committed
random upgrades in the backend
1 parent 18e75bc commit 7152a67

File tree

4 files changed

+61
-45
lines changed

4 files changed

+61
-45
lines changed

functions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def retract_lines(lines):
2+
for _ in range(lines):
3+
print('\033[1A\033[2K', end='', flush=True)
4+
5+
def exit_and_retract(lines, status=0):
6+
retract_lines(lines)
7+
print('\nExiting...\n\033[2K')
8+
exit(status)

index.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
1-
# Left here for a hash/shebang letter edit in a possible setup script I might make
21
from colorama import Fore, Style, init
32
import runpy, os
3+
import functions
44

55
init()
66

77
storm_processes = [
8-
{'name': 'System Information', 'desc': 'Basic infomation about your system', 'path': 'sysinfo.py', 'colour': 'GREEN'},
9-
{'name': 'Resource Monitor', 'desc': 'A basic ', 'path': 'monitor.py', 'colour': 'BLUE'},
8+
{
9+
"name": "System Information",
10+
"desc": "Basic infomation about your system",
11+
"path": "sysinfo.py",
12+
"colour": "GREEN",
13+
},
14+
{
15+
"name": "Resource Monitor",
16+
"desc": "A basic ",
17+
"path": "monitor.py",
18+
"colour": "BLUE",
19+
},
1020
]
1121
color_map = {
12-
'BLACK': Fore.BLACK,
13-
'RED': Fore.RED,
14-
'GREEN': Fore.GREEN,
15-
'YELLOW': Fore.YELLOW,
16-
'BLUE': Fore.BLUE,
17-
'MAGENTA': Fore.MAGENTA,
18-
'CYAN': Fore.CYAN,
19-
'WHITE': Fore.WHITE,
20-
'RESET': Style.RESET_ALL
22+
"BLACK": Fore.LIGHTBLACK_EX,
23+
"RED": Fore.LIGHTRED_EX,
24+
"GREEN": Fore.LIGHTGREEN_EX,
25+
"YELLOW": Fore.LIGHTYELLOW_EX,
26+
"BLUE": Fore.LIGHTBLUE_EX,
27+
"MAGENTA": Fore.LIGHTMAGENTA_EX,
28+
"CYAN": Fore.LIGHTCYAN_EX,
29+
"WHITE": Fore.LIGHTWHITE_EX,
30+
"RESET": Style.RESET_ALL,
2131
}
2232
path = os.path.dirname(__file__)
2333

2434
for index, process in enumerate(storm_processes):
25-
print(f"{color_map[process['colour']]}[{index}={process['name']}]{Style.RESET_ALL} {process['desc']}{Style.RESET_ALL}")
35+
print(
36+
f"{color_map[process['colour']]}[{index}={process['name']}]{Style.RESET_ALL} {process['desc']}{Style.RESET_ALL}"
37+
)
2638

2739
try:
28-
choice = int(input('Please enter your choice:'))
40+
choice = int(input("Please enter your choice:"))
2941
except Exception as failure:
30-
print(f'Failure: {failure}')
42+
print(f"Failure: {failure}")
3143
exit(1)
44+
except KeyboardInterrupt:
45+
functions.exit_and_retract(2, 0)
3246
try:
33-
for _ in range(3):
34-
print('\033[1A\033[2K', end='', flush=True)
47+
functions.retract_lines(3)
3548
runpy.run_path(f'{path}/{storm_processes[choice]["path"]}')
3649
except Exception as failure:
37-
print(f'Failure: {failure}')
50+
print(f"Failure: {failure}")

monitor.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
1-
from colorama import Fore, Style, init
1+
from colorama import Fore, Style
22
import psutil, time
3-
4-
init()
3+
import functions
54

65
def gb_calculation(value):
76
return f"{value / (1024 ** 3):.2f}"
87

9-
def print_stats(cpu, ram, swap):
10-
print(Fore.YELLOW + "Processer Load: " + Style.RESET_ALL + f'{cpu}%', flush=True)
11-
print(Fore.MAGENTA + "Total RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.total)} GB", flush=True)
12-
print(Fore.MAGENTA + "Available RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.available)} GB", flush=True)
13-
print(Fore.MAGENTA + "Used RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.used)} GB", flush=True)
14-
print(Fore.MAGENTA + "RAM usage percentage: " + Style.RESET_ALL + f'{ram.percent}%', flush=True)
15-
print(Fore.GREEN + "Total Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.total)} GB")
16-
print(Fore.GREEN + "Used Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.used)} GB")
17-
print(Fore.GREEN + "Free Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.free)} GB")
18-
print(Fore.GREEN + "Swap usage percentage: " + Style.RESET_ALL + f"{swap.percent}%")
19-
208
try:
219
psutil.cpu_percent(interval=1)
2210
while True:
23-
c = psutil.cpu_percent(interval=0)
24-
r = psutil.virtual_memory()
25-
s = psutil.swap_memory()
26-
print_stats(c, r, s)
11+
cpu = psutil.cpu_percent(interval=0)
12+
ram = psutil.virtual_memory()
13+
swap = psutil.swap_memory()
14+
print(Fore.LIGHTYELLOW_EX + "Processer Load: " + Style.RESET_ALL + f'{cpu}%', flush=True)
15+
print(Fore.LIGHTMAGENTA_EX + "Total RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.total)} GB", flush=True)
16+
print(Fore.LIGHTMAGENTA_EX + "Available RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.available)} GB", flush=True)
17+
print(Fore.LIGHTMAGENTA_EX + "Used RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.used)} GB", flush=True)
18+
print(Fore.LIGHTMAGENTA_EX + "RAM usage percentage: " + Style.RESET_ALL + f'{ram.percent}%', flush=True)
19+
print(Fore.LIGHTGREEN_EX + "Total Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.total)} GB", flush=True)
20+
print(Fore.LIGHTGREEN_EX + "Used Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.used)} GB", flush=True)
21+
print(Fore.LIGHTGREEN_EX + "Free Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.free)} GB", flush=True)
22+
print(Fore.LIGHTGREEN_EX + "Swap usage percentage: " + Style.RESET_ALL + f"{swap.percent}%", flush=True)
23+
print("\nPress CMD+C or CTRL+C to exit", flush=True)
2724
time.sleep(1)
28-
for _ in range(9):
29-
print('\033[1A\033[2K', end='', flush=True)
25+
functions.retract_lines(11)
3026
except KeyboardInterrupt:
31-
for _ in range(9):
32-
print('\033[1A\033[2K', end='', flush=True)
33-
print("\nExiting...")
27+
functions.exit_and_retract(11)
3428
except Exception as e:
3529
print(f"Exception has occured: {e}")
3630

sysinfo.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import platform
2-
import socket
3-
import psutil
1+
import platform, socket, psutil, functions
42
from uuid import getnode as get_mac
53
from colorama import Fore, Style, init
64

@@ -47,5 +45,8 @@ def get_mac_address():
4745
{Fore.YELLOW}MAC Address:{Style.RESET_ALL} {mac_address}
4846
{Fore.CYAN}Total Disk Space:{Style.RESET_ALL} {total_disk} GB
4947
{Fore.CYAN}Used Disk Space:{Style.RESET_ALL} {used_disk} GB
50-
{Fore.CYAN}Free Disk Space:{Style.RESET_ALL} {free_disk} GB
48+
{Fore.CYAN}Free Disk Space:{Style.RESET_ALL} {free_disk} GB\n\n
5149
""")
50+
51+
input('Press enter to close menu.')
52+
functions.exit_and_retract(14)

0 commit comments

Comments
 (0)