summarylogtreecommitdiffstats
path: root/storage-kween.py
blob: e4afcd218af46f792b554bcef051c7d6a6ffc802 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3

from dearpygui.dearpygui import *
import os
import subprocess
import time

# Check and install required system tools if needed (run manually or via setup script)
REQUIRED_COMMANDS = ["du", "find", "fdupes", "paccache", "pacman", "lsblk", "free", "uname"]

def check_dependencies():
    missing = []
    for cmd in REQUIRED_COMMANDS:
        if subprocess.call(f"command -v {cmd}", shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) != 0:
            missing.append(cmd)
    if missing:
        print("Missing system tools:", ", ".join(missing))
        print("\nInstall them using your package manager:")
        print("sudo pacman -S " + " ".join(missing))
        exit(1)

check_dependencies()

create_context()
create_viewport(title="Storage Queen ๐Ÿ‘‘", width=900, height=600)
setup_dearpygui()

results_cache = ""

def update_panel(label, content):
    delete_item("main_panel", children_only=True)
    add_text(label, parent="main_panel")
    add_separator(parent="main_panel")
    add_text(content, parent="main_panel", wrap=800)

def run_analyzer(sender, app_data, user_data):
    update_panel("๐Ÿ“Š Disk Analyzer", "Scanning disk usage...")
    output = subprocess.getoutput("du -h --max-depth=1 ~ | sort -hr | head -n 15")
    update_panel("๐Ÿ“Š Disk Analyzer", output)

def clean_junk(sender, app_data, user_data):
    update_panel("๐Ÿงน Junk Cleaner", "Cleaning pacman cache and logs...")
    subprocess.call(["paccache", "-r"])
    subprocess.call(["sudo", "rm", "-rf", "/var/log/*.log"])
    update_panel("๐Ÿงน Junk Cleaner", "Done cleaning. Your majesty's filesystem is fresh.")

def find_large_files(sender, app_data, user_data):
    update_panel("๐Ÿ” Large Files", "Locating large files...")
    output = subprocess.getoutput("find ~ -type f -exec du -h {} + | sort -hr | head -n 15")
    update_panel("๐Ÿ” Large Files", output)

def find_duplicates(sender, app_data, user_data):
    update_panel("๐Ÿง‚ Duplicates", "Looking for duplicate files via MD5 hash...")
    output = subprocess.getoutput("fdupes -r ~ | head -n 40")
    update_panel("๐Ÿง‚ Duplicates", output if output else "No duplicates found!")

def safe_delete_mode(sender, app_data, user_data):
    update_panel("๐Ÿ’ฃ Safe Delete", "Not yet implemented, but soon you'll queue files for deletion with mercy.")

with window(label="Storage Queen ๐Ÿ‘‘", width=900, height=600):
    with group(horizontal=True):
        with child_window(width=180, border=True):
            add_button(label="๐Ÿ“Š Analyze", callback=run_analyzer)
            add_button(label="๐Ÿงน Clean Junk", callback=clean_junk)
            add_button(label="๐Ÿ” Large Files", callback=find_large_files)
            add_button(label="๐Ÿง‚ Duplicates", callback=find_duplicates)
            add_button(label="๐Ÿ’ฃ Safe Delete", callback=safe_delete_mode)
        with child_window(tag="main_panel", width=700, height=550, border=True):
            add_text("๐Ÿ‘‘ Welcome to Storage Queen\nClick a button to begin.", wrap=700)
    add_text("Built for the Arch community, with love.", bullet=True)

show_viewport()
try:
    start_dearpygui()
except KeyboardInterrupt:
    print("๐Ÿ‘‘ Storage Queen was dismissed by the court.")
finally:
    destroy_context()