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

Commit dbf0072

Browse files
authored
refactors, fixes
* Update delete.py * Update delete.py * refactor, notify about oudated pkg * clarify logs * do not show "," if not needed * show how to reinstall * docs * ruff * ruff * ruff + comments * ruff + comments * comments * warning about deletion * Update existing-packages.txt
1 parent 4452159 commit dbf0072

8 files changed

Lines changed: 95 additions & 46 deletions

File tree

existing-packages.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
example
22
example2
33
crust
4-
reskin
54
vim-build
65
vim
76
firefox

src/delete.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33

44
from rich.console import Console
55

6-
from status import status
76
import umbrella.autocorrect_package as Autocorrect
7+
from status import status
88

99
console = Console()
1010

11+
1112
def main(package):
13+
print(
14+
"note that this function is not finished, and it does not delete all package files."
15+
)
1216
autocorrected = Autocorrect.main(package)
1317
if autocorrected != package:
1418
package = autocorrected
@@ -19,7 +23,7 @@ def main(package):
1923
open("/etc/repro.car", "w").close()
2024
return False
2125

22-
with open(f"/home/{os.getlogin()}/.config/repro.car") as f:
26+
with open("/etc/repro.car") as f:
2327
repro = f.read()
2428

2529
if package not in repro:
@@ -30,7 +34,7 @@ def main(package):
3034
if i.startswith(package):
3135
repro = repro.replace(i, "")
3236

33-
with open("", "w") as f:
37+
with open("/etc/repro.car", "w") as f:
3438
f.write(repro)
3539

3640
status(f"Uninstalling {package}...", "info")

src/hooks.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,30 @@
33

44
import status
55

6+
67
def post_inst(package):
7-
status.status("Loading hooks")
8-
print("(1/?) Loading hooks")
8+
status.status("Running hooks")
99

1010
hooks_file = f"/etc/car/post-inst-hooks"
1111

1212
if not os.path.exists(hooks_file):
1313
print(f"No hooks file found at {hooks_file}")
1414
return
1515

16+
# read what hooks to run
1617
with open(hooks_file, "r") as f:
1718
hooks = [line.strip() for line in f if line.strip()]
1819

19-
steps = 1 + len(hooks) * 2
20+
steps = len(hooks)
2021
step_counter = 1
2122

2223
for i, hook_path in enumerate(hooks, start=1):
23-
step_counter += 1
24-
print(f"({step_counter}/{steps}) Loading hook {hook_path}")
24+
# load the hook
2525
spec = importlib.util.spec_from_file_location(f"hook_{i}", hook_path)
2626
hook = importlib.util.module_from_spec(spec)
2727
spec.loader.exec_module(hook)
2828

29-
step_counter += 1
29+
# run
3030
print(f"({step_counter}/{steps}) Running hook {hook_path}")
31+
step_counter += 1
3132
hook.run(package)

src/init.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,29 @@
22

33
import updatelist
44

5+
56
def main():
6-
base_path = f"/etc/car"
7-
7+
base_path = "/etc/car"
8+
89
print(f"Creating {base_path}/")
910
os.makedirs(f"{base_path}/hooks", exist_ok=True)
1011

1112
hook_path = f"{base_path}/hooks/check_core.py"
1213
with open(hook_path, "w") as f:
1314
f.write(
14-
'import os\n'
15-
'def run(package):\n'
15+
"import os\n"
16+
"def run(package):\n"
1617
' os.system("curl -s -L -o cores https://raw.githubusercontent.com/redroselinux/car-coreutils-repo/refs/heads/main/cores")\n'
17-
' with open(\'cores\', \'r\') as f:\n'
18-
' cores = f.read()\n'
19-
' if package in cores.splitlines():\n'
20-
' print("Reboot recommended!")\n'
18+
" with open('cores', 'r') as f:\n"
19+
" cores = f.read()\n"
20+
" if package in cores.splitlines():\n"
21+
' print(":: Reboot recommended!")\n'
2122
)
2223

2324
post_inst_path = f"{base_path}/post-inst-hooks"
2425
with open(post_inst_path, "w") as f:
2526
f.write(f"{hook_path}\n")
26-
27+
2728
print(f"Created hook script at {hook_path}")
2829
print(f"Created post-inst-hooks file at {post_inst_path}")
2930

src/install.py

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
import os
21
import importlib.util
3-
from rich.console import Console
2+
import os
43
import sys
54

6-
from status import status
7-
import mirrors
8-
import hooks
5+
from rich.console import Console
6+
97
import get_package_list
10-
import umbrella.autocorrect_package as Autocorrect
8+
import hooks
119
import install
10+
import mirrors
11+
import umbrella.autocorrect_package as Autocorrect
12+
from status import status
1213

1314
# init rich console
1415
console = Console()
1516

1617
# Track packages currently being installed to prevent circular dependencies
1718
_installing = set()
1819

20+
1921
def main(package, noconfirm=False):
2022
local = False
2123
# check if package is local
@@ -31,7 +33,7 @@ def main(package, noconfirm=False):
3133
autocorrected = Autocorrect.main(package)
3234
if autocorrected != package:
3335
package = autocorrected
34-
36+
3537
# Prevent circular dependencies and infinite loops
3638
if package in _installing:
3739
return
@@ -41,7 +43,7 @@ def main(package, noconfirm=False):
4143
if not local:
4244
if get_package_list.main(package) != True:
4345
return False
44-
46+
4547
# main
4648
try:
4749
# save installed package
@@ -75,7 +77,7 @@ def write_installed_versions(path, versions):
7577
# go to /tmp
7678
if not local:
7779
os.chdir("/tmp/")
78-
80+
7981
status("Fetching package")
8082

8183
# fetch all repos for the install script
@@ -84,7 +86,7 @@ def write_installed_versions(path, versions):
8486
for mirror in mirrors.install_script_places:
8587
url = f"{mirror.rstrip('/')}/{package}/install_script"
8688

87-
result = os.system(f"curl -s -L -o install_script.py {url}")
89+
os.system(f"curl -s -L -o install_script.py {url}")
8890

8991
with open("install_script.py", "r") as f:
9092
script = f.read()
@@ -102,7 +104,9 @@ def write_installed_versions(path, versions):
102104
exit(1)
103105

104106
# import the script as a python library
105-
spec = importlib.util.spec_from_file_location("install_script", "install_script.py")
107+
spec = importlib.util.spec_from_file_location(
108+
"install_script", "install_script.py"
109+
)
106110
install_script = importlib.util.module_from_spec(spec)
107111
spec.loader.exec_module(install_script)
108112

@@ -122,9 +126,16 @@ def write_installed_versions(path, versions):
122126
installed_version = installed_versions.get(package)
123127
if installed_version is not None and installed_version == script_version:
124128
status(f"{package} is up to date ({script_version}). Exiting.", "ok")
129+
status(
130+
f"You can use\n sudo car delete {package} && sudo car get {package}"
131+
)
132+
status("to reinstall it")
125133
return
126134
elif installed_version is not None and installed_version != script_version:
127-
status(f"New version available for {package}: {installed_version} -> {script_version}. Reinstalling.", "warn")
135+
status(
136+
f"New version available for {package}: {installed_version} -> {script_version}. Reinstalling.",
137+
"warn",
138+
)
128139
elif installed_version is None:
129140
if not os.path.isfile(repro_path):
130141
status("No repro.car file. Creating", "warn")
@@ -138,11 +149,28 @@ def write_installed_versions(path, versions):
138149
# ask for confirmation
139150
if not noconfirm:
140151
status("The following packages are going to be installed:")
141-
print(" ", end="")
152+
if "description" not in script:
153+
description = "No description defined."
154+
else:
155+
description = install_script.description
156+
print(
157+
f" {package}={install_script.version} - {description}"
158+
) # appending to the list did not work for some reason
142159
if "car_deps" in script:
143-
for i in install_script.car_deps:
144-
print(i, end=", ")
145-
print(package) # appending to the list did not work for some reason
160+
counter = 1
161+
if len(install_script.car_deps) != 0:
162+
print(" dependencies: ", end="")
163+
for i in install_script.car_deps:
164+
if counter != len(install_script.car_deps):
165+
print(f"{i}, ", end="")
166+
else:
167+
print(f"{i}", end="")
168+
print()
169+
if "outdated = True" in script:
170+
if (
171+
package != "example"
172+
): # example is set to be outdated for demonstration
173+
status(f'The package "{package}" is outdated! ', "error")
146174
console.print("::", style="blue bold", end=" ")
147175
sure = input("Install dependencies and build? (Y/n) ")
148176
if sure not in ("", "y", "Y"):
@@ -152,7 +180,8 @@ def write_installed_versions(path, versions):
152180
if "deps" in script:
153181
try:
154182
install_script.deps()
155-
except Exception:pass
183+
except Exception:
184+
pass
156185
if "car_deps" in script:
157186
for i in install_script.car_deps:
158187
install.main(i, noconfirm=True)
@@ -161,7 +190,8 @@ def write_installed_versions(path, versions):
161190
if "build" in script:
162191
try:
163192
install_script.build()
164-
except Exception:pass
193+
except Exception:
194+
pass
165195

166196
# ask for confirmation
167197
# todo: make confirmation prompts better by mixing into one
@@ -175,7 +205,6 @@ def write_installed_versions(path, versions):
175205
status("Installing", "ok")
176206
install_script.install()
177207

178-
179208
if not "DoNotWriteVersion = True" in script:
180209
installed_versions[package] = script_version
181210
write_installed_versions(repro_path, installed_versions)
@@ -197,7 +226,10 @@ def write_installed_versions(path, versions):
197226
except KeyboardInterrupt:
198227
# keyboard interrupt, suggest cleaning up
199228
status("Installation interrupted", "error")
200-
status("There might be some files that were installed, but not removed. You can remove them manually.", "warn")
229+
status(
230+
"There might be some files that were installed, but not removed. You can remove them manually.",
231+
"warn",
232+
)
201233
status("If you want to remove them, run the following command:", "warn")
202234
status("sudo car delete " + package, "warn")
203235
sys.exit(1)

src/lspkgs.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import os
2-
31
def main():
2+
# open repro.car
43
with open("/etc/repro.car", "r") as f:
54
repro = f.read()
65

6+
# sometimes, car writes the same package multiple times. for this reason,
7+
# do not only print content but filter specifically the PACKAGES from the file
78
alr_used = []
89
for i in repro.splitlines():
9-
if i in alr_used: continue
10+
if i in alr_used:
11+
# already printed, continue
12+
continue
13+
# we have used this just now, write it into alr_used
1014
alr_used.append(i)
1115

16+
# print the current package
1217
print(i)

src/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
import update
1111
import updatelist
1212

13-
parser = argparse.ArgumentParser(description="A simple package manager")
13+
parser = argparse.ArgumentParser(
14+
prog="car",
15+
description="A simple package manager for Redrose Linux. Documentation is available at: https://redroselinux.miraheze.org/wiki/Car_Package_Manager",
16+
epilog="Authors: Juraj Kollár (mostypc123) <mostypc7@gmail.com>",
17+
)
1418
subparsers = parser.add_subparsers(dest="command", required=True)
1519

1620
# install

src/search.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import mirrors
2-
import status
3-
import os
2+
43

54
def main(package):
5+
# get list of packages
66
packages = mirrors.fetch_all_packages(mirrors.packagelist_places)
7+
8+
# loop through the packages
79
for i in packages:
10+
# found, print it
811
if package in i:
9-
status.status("Found: " + i, "ok")
12+
print(i)

0 commit comments

Comments
 (0)