Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.

Commit 732be16

Browse files
authored
feat: package deletion, properly!
* hmm what could 2.3 be 😏 * save files to delete * Update delete.py
1 parent be45516 commit 732be16

3 files changed

Lines changed: 36 additions & 15 deletions

File tree

src/delete.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
2-
import sys
32

43
from rich.console import Console
4+
from rich.progress import BarColumn, Progress, TextColumn
55

66
import umbrella.autocorrect_package as Autocorrect
77
from status import status
@@ -10,9 +10,6 @@
1010

1111

1212
def main(package):
13-
print(
14-
"note that this function is not finished, and it does not delete all package files."
15-
)
1613
autocorrected = Autocorrect.main(package)
1714
if autocorrected != package:
1815
package = autocorrected
@@ -38,14 +35,27 @@ def main(package):
3835
f.write(repro)
3936

4037
status(f"Uninstalling {package}...", "info")
41-
try:
42-
if os.system(f"sudo rm -f /usr/bin/{package}") != 0:
43-
status(f"Failed to uninstall {package}", "error")
44-
return False
45-
status(f"Successfully uninstalled {package}", "ok")
46-
return True
47-
except Exception:
48-
console.print("::", style="red", end=" ")
49-
console.print("Unhandled exception")
50-
console.print_exception()
51-
return False
38+
39+
delete_files = []
40+
41+
if os.path.isfile(f"/etc/car/saves/{package}"):
42+
with open(f"/etc/car/saves/{package}", "r") as f:
43+
delete_files = f.read().splitlines()
44+
45+
# +1 to account for /usr/bin/{package}
46+
total = len(delete_files) + 1
47+
48+
status("Progress:")
49+
50+
with Progress(
51+
TextColumn("{task.completed}/{task.total}"),
52+
BarColumn(),
53+
) as progress:
54+
task = progress.add_task("Deleting", total=total)
55+
56+
for i in delete_files:
57+
os.system(f"rm -rf {i}")
58+
progress.advance(task)
59+
60+
os.system(f"rm -f /usr/bin/{package}")
61+
progress.advance(task)

src/init.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def main():
88

99
print(f"Creating {base_path}/")
1010
os.makedirs(f"{base_path}/hooks", exist_ok=True)
11+
os.makedirs(f"{base_path}/saves", exist_ok=True)
1112

1213
hook_path = f"{base_path}/hooks/check_core.py"
1314
with open(hook_path, "w") as f:

src/install.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@ def write_installed_versions(path, versions):
211211
if hasattr(install_script, "postinst"):
212212
install_script.postinst()
213213

214+
# save extra files to delete
215+
if "delete_files = " in script:
216+
try:
217+
with open(f"/etc/car/saves/{package}", "w") as f:
218+
for i in install_script.delete_files:
219+
f.write(f"{i}\n")
220+
status("Saved files for deletion if delete is run", "ok")
221+
except Exception as e:
222+
print(f"error {e}")
223+
214224
# clean up
215225
os.system("sudo rm -f /tmp/install_script.py")
216226
except Exception:

0 commit comments

Comments
 (0)