Skip to content

Commit 971673f

Browse files
authored
Update main.py
1 parent 9c266df commit 971673f

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

source-code/apt-fronted/main.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,20 @@
1212
from rich.panel import Panel
1313
from rich.prompt import Prompt
1414
from rich.style import Style as RichStyle
15-
1615
# Initialize colorama for cross-platform ANSI support
1716
colorama.init()
18-
1917
# Rich console for advanced output
2018
console = Console()
21-
2219
# Blessed terminal for some cursor control if needed
2320
term = blessed.Terminal()
24-
2521
def print_header():
2622
"""Print a fancy header for the tool."""
2723
console.print(Panel.fit(
28-
"[bold cyan]APT-Fronted[/bold cyan] - A Beautiful Frontend for APT (Inspired by DNF/Zypper/Pacman)",
24+
"[bold cyan]APT-Fronted[/bold cyan] - A Beautiful Frontend for APT",
2925
border_style="bold magenta",
3026
title="Welcome to APT-Fronted",
31-
subtitle="Powered by xAI's Grok Inspiration",
32-
expand=False
27+
subtitle="Powered by HackerOS"
3328
))
34-
3529
def run_command(cmd, capture_output=False, check=True):
3630
"""Run a subprocess command with error handling."""
3731
try:
@@ -44,7 +38,6 @@ def run_command(cmd, capture_output=False, check=True):
4438
if e.stderr:
4539
console.print(f"[red]{e.stderr.strip()}[/red]")
4640
sys.exit(1)
47-
4841
def parse_apt_output(output):
4942
"""Parse APT output for progress indicators."""
5043
# Simple regex to find progress like "Reading package lists... Done"
@@ -53,7 +46,6 @@ def parse_apt_output(output):
5346
if progress_matches:
5447
return int(progress_matches[-1])
5548
return 0
56-
5749
def simulate_progress(task_name, steps=100):
5850
"""Simulate a progress bar for operations without real-time output."""
5951
with Progress(
@@ -65,16 +57,15 @@ def simulate_progress(task_name, steps=100):
6557
) as progress:
6658
task = progress.add_task(task_name, total=steps)
6759
for _ in range(steps):
68-
time.sleep(0.05) # Simulate work
60+
time.sleep(0.05) # Simulate work
6961
progress.update(task, advance=1)
70-
7162
def apt_update():
7263
"""Run apt update with progress."""
7364
console.print(f"[green]Running {colored('apt update', 'yellow', attrs=['bold'])}...[/green]")
7465
try:
7566
# Run apt update with subprocess and capture output for parsing
7667
proc = subprocess.Popen(['sudo', 'apt', 'update'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
77-
68+
7869
with Progress(
7970
TextColumn("[bold green]Updating...[/bold green]"),
8071
BarColumn(),
@@ -92,30 +83,29 @@ def apt_update():
9283
progress.update(task, completed=new_progress)
9384
current_progress = new_progress
9485
time.sleep(0.1)
95-
86+
9687
if proc.returncode != 0:
9788
error = proc.stderr.read().strip()
9889
console.print(f"[bold red]Update failed:[/bold red] {error}")
9990
else:
10091
console.print("[bold green]Update completed successfully![/bold green]")
10192
except Exception as e:
10293
console.print(f"[bold red]Error during update:[/bold red] {str(e)}")
103-
10494
def apt_install(package):
10595
"""Install a package with progress and error handling."""
10696
console.print(f"[green]Installing {colored(package, 'cyan', attrs=['bold'])}...[/green]")
107-
97+
10898
# Check if package is already installed
10999
check_cmd = ['dpkg', '-s', package]
110100
check = subprocess.run(check_cmd, capture_output=True, text=True)
111101
if check.returncode == 0:
112102
console.print(f"[yellow]{package} is already installed.[/yellow]")
113103
return
114-
104+
115105
try:
116106
# Run apt install
117107
proc = subprocess.Popen(['sudo', 'apt', 'install', '-y', package], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
118-
108+
119109
with Progress(
120110
TextColumn("[bold cyan]Installing...[/bold cyan]"),
121111
BarColumn(),
@@ -133,7 +123,7 @@ def apt_install(package):
133123
progress.update(task, completed=new_progress)
134124
current_progress = new_progress
135125
time.sleep(0.1)
136-
126+
137127
if proc.returncode != 0:
138128
error = proc.stderr.read().strip()
139129
if "unable to locate package" in error.lower():
@@ -146,19 +136,17 @@ def apt_install(package):
146136
console.print(f"[bold green]{package} installed successfully![/bold green]")
147137
except Exception as e:
148138
console.print(f"[bold red]Error during installation:[/bold red] {str(e)}")
149-
150139
def apt_remove(package):
151140
"""Remove a package with confirmation."""
152141
confirm = Prompt.ask(f"[yellow]Are you sure you want to remove {package}? (y/n)[/yellow]", default="n")
153142
if confirm.lower() != 'y':
154143
console.print("[blue]Removal cancelled.[/blue]")
155144
return
156-
145+
157146
console.print(f"[green]Removing {colored(package, 'red', attrs=['bold'])}...[/green]")
158-
simulate_progress("Removing package", steps=50) # Simulated for removal
147+
simulate_progress("Removing package", steps=50) # Simulated for removal
159148
run_command(['sudo', 'apt', 'remove', '-y', package])
160149
console.print(f"[bold green]{package} removed successfully![/bold green]")
161-
162150
def apt_search(query):
163151
"""Search for packages."""
164152
console.print(f"[green]Searching for {colored(query, 'magenta', attrs=['bold'])}...[/green]")
@@ -168,16 +156,15 @@ def apt_search(query):
168156
console.print(Panel(output, title="Search Results", border_style="green"))
169157
else:
170158
console.print("[yellow]No results found.[/yellow]")
171-
172159
def main():
173160
print_header()
174-
161+
175162
if len(sys.argv) < 2:
176163
console.print("[bold red]Usage:[/bold red] apt-fronted [update|install <pkg>|remove <pkg>|search <query>]")
177164
sys.exit(1)
178-
165+
179166
command = sys.argv[1].lower()
180-
167+
181168
if command == 'update':
182169
apt_update()
183170
elif command == 'install':
@@ -197,6 +184,5 @@ def main():
197184
apt_search(sys.argv[2])
198185
else:
199186
console.print(f"[bold red]Unknown command: {command}[/bold red]")
200-
201187
if __name__ == "__main__":
202188
main()

0 commit comments

Comments
 (0)