Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Commit

Permalink
random upgrades in the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanautumnlyra committed Jun 25, 2024
1 parent 18e75bc commit 7152a67
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 45 deletions.
8 changes: 8 additions & 0 deletions functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def retract_lines(lines):
for _ in range(lines):
print('\033[1A\033[2K', end='', flush=True)

def exit_and_retract(lines, status=0):
retract_lines(lines)
print('\nExiting...\n\033[2K')
exit(status)
49 changes: 31 additions & 18 deletions index.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
# Left here for a hash/shebang letter edit in a possible setup script I might make
from colorama import Fore, Style, init
import runpy, os
import functions

init()

storm_processes = [
{'name': 'System Information', 'desc': 'Basic infomation about your system', 'path': 'sysinfo.py', 'colour': 'GREEN'},
{'name': 'Resource Monitor', 'desc': 'A basic ', 'path': 'monitor.py', 'colour': 'BLUE'},
{
"name": "System Information",
"desc": "Basic infomation about your system",
"path": "sysinfo.py",
"colour": "GREEN",
},
{
"name": "Resource Monitor",
"desc": "A basic ",
"path": "monitor.py",
"colour": "BLUE",
},
]
color_map = {
'BLACK': Fore.BLACK,
'RED': Fore.RED,
'GREEN': Fore.GREEN,
'YELLOW': Fore.YELLOW,
'BLUE': Fore.BLUE,
'MAGENTA': Fore.MAGENTA,
'CYAN': Fore.CYAN,
'WHITE': Fore.WHITE,
'RESET': Style.RESET_ALL
"BLACK": Fore.LIGHTBLACK_EX,
"RED": Fore.LIGHTRED_EX,
"GREEN": Fore.LIGHTGREEN_EX,
"YELLOW": Fore.LIGHTYELLOW_EX,
"BLUE": Fore.LIGHTBLUE_EX,
"MAGENTA": Fore.LIGHTMAGENTA_EX,
"CYAN": Fore.LIGHTCYAN_EX,
"WHITE": Fore.LIGHTWHITE_EX,
"RESET": Style.RESET_ALL,
}
path = os.path.dirname(__file__)

for index, process in enumerate(storm_processes):
print(f"{color_map[process['colour']]}[{index}={process['name']}]{Style.RESET_ALL} {process['desc']}{Style.RESET_ALL}")
print(
f"{color_map[process['colour']]}[{index}={process['name']}]{Style.RESET_ALL} {process['desc']}{Style.RESET_ALL}"
)

try:
choice = int(input('Please enter your choice:'))
choice = int(input("Please enter your choice:"))
except Exception as failure:
print(f'Failure: {failure}')
print(f"Failure: {failure}")
exit(1)
except KeyboardInterrupt:
functions.exit_and_retract(2, 0)
try:
for _ in range(3):
print('\033[1A\033[2K', end='', flush=True)
functions.retract_lines(3)
runpy.run_path(f'{path}/{storm_processes[choice]["path"]}')
except Exception as failure:
print(f'Failure: {failure}')
print(f"Failure: {failure}")
40 changes: 17 additions & 23 deletions monitor.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
from colorama import Fore, Style, init
from colorama import Fore, Style
import psutil, time

init()
import functions

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

def print_stats(cpu, ram, swap):
print(Fore.YELLOW + "Processer Load: " + Style.RESET_ALL + f'{cpu}%', flush=True)
print(Fore.MAGENTA + "Total RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.total)} GB", flush=True)
print(Fore.MAGENTA + "Available RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.available)} GB", flush=True)
print(Fore.MAGENTA + "Used RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.used)} GB", flush=True)
print(Fore.MAGENTA + "RAM usage percentage: " + Style.RESET_ALL + f'{ram.percent}%', flush=True)
print(Fore.GREEN + "Total Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.total)} GB")
print(Fore.GREEN + "Used Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.used)} GB")
print(Fore.GREEN + "Free Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.free)} GB")
print(Fore.GREEN + "Swap usage percentage: " + Style.RESET_ALL + f"{swap.percent}%")

try:
psutil.cpu_percent(interval=1)
while True:
c = psutil.cpu_percent(interval=0)
r = psutil.virtual_memory()
s = psutil.swap_memory()
print_stats(c, r, s)
cpu = psutil.cpu_percent(interval=0)
ram = psutil.virtual_memory()
swap = psutil.swap_memory()
print(Fore.LIGHTYELLOW_EX + "Processer Load: " + Style.RESET_ALL + f'{cpu}%', flush=True)
print(Fore.LIGHTMAGENTA_EX + "Total RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.total)} GB", flush=True)
print(Fore.LIGHTMAGENTA_EX + "Available RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.available)} GB", flush=True)
print(Fore.LIGHTMAGENTA_EX + "Used RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.used)} GB", flush=True)
print(Fore.LIGHTMAGENTA_EX + "RAM usage percentage: " + Style.RESET_ALL + f'{ram.percent}%', flush=True)
print(Fore.LIGHTGREEN_EX + "Total Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.total)} GB", flush=True)
print(Fore.LIGHTGREEN_EX + "Used Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.used)} GB", flush=True)
print(Fore.LIGHTGREEN_EX + "Free Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.free)} GB", flush=True)
print(Fore.LIGHTGREEN_EX + "Swap usage percentage: " + Style.RESET_ALL + f"{swap.percent}%", flush=True)
print("\nPress CMD+C or CTRL+C to exit", flush=True)
time.sleep(1)
for _ in range(9):
print('\033[1A\033[2K', end='', flush=True)
functions.retract_lines(11)
except KeyboardInterrupt:
for _ in range(9):
print('\033[1A\033[2K', end='', flush=True)
print("\nExiting...")
functions.exit_and_retract(11)
except Exception as e:
print(f"Exception has occured: {e}")

9 changes: 5 additions & 4 deletions sysinfo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import platform
import socket
import psutil
import platform, socket, psutil, functions
from uuid import getnode as get_mac
from colorama import Fore, Style, init

Expand Down Expand Up @@ -47,5 +45,8 @@ def get_mac_address():
{Fore.YELLOW}MAC Address:{Style.RESET_ALL} {mac_address}
{Fore.CYAN}Total Disk Space:{Style.RESET_ALL} {total_disk} GB
{Fore.CYAN}Used Disk Space:{Style.RESET_ALL} {used_disk} GB
{Fore.CYAN}Free Disk Space:{Style.RESET_ALL} {free_disk} GB
{Fore.CYAN}Free Disk Space:{Style.RESET_ALL} {free_disk} GB\n\n
""")

input('Press enter to close menu.')
functions.exit_and_retract(14)

0 comments on commit 7152a67

Please sign in to comment.