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

Commit 14ff29c

Browse files
authored
2.3.1 (#5)
* update print * check if car was inited * Create nocarinit.py * Update mirrors.py
1 parent 204249c commit 14ff29c

4 files changed

Lines changed: 40 additions & 15 deletions

File tree

src/install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def write_installed_versions(path, versions):
257257
"warn",
258258
)
259259
status("If you want to remove them, run the following command:", "warn")
260-
status("sudo car delete " + package, "warn")
260+
print(" > ")
261261
sys.exit(1)
262262
finally:
263263
# Always remove from installing set, even if installation fails

src/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import init
77
import lspkgs
88
import mirrors
9+
import nocarinit
910
import search
11+
import status
1012
import update
1113
import updatelist
1214

@@ -50,6 +52,11 @@
5052

5153
args = parser.parse_args()
5254

55+
if args.command != "init":
56+
if nocarinit.main():
57+
status.status("Car was not initalized. Run:\n > car init", "error")
58+
exit()
59+
5360
if args.command == "get":
5461
finstall.main(packages=args.packages, noconfirm=args.noconfirm)
5562
elif args.command == "delete":

src/mirrors.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os
22
import subprocess
33
from concurrent.futures import ThreadPoolExecutor
4-
from status import status
54

5+
# mirrors config (written only if missing)
66
mirrors = """:main:
77
install_script = https://raw.githubusercontent.com/redroselinux/car-binary-storage/main/
88
packagelist = https://raw.githubusercontent.com/redroselinux/car/main/existing-packages.txt
@@ -16,59 +16,67 @@
1616
:end:
1717
"""
1818

19-
# Write mirrors only if they do not exist
20-
for path in ["/etc/mirrors.car", "/home/user/.config/mirrors.car"]:
19+
# write mirrors only if they do not exist
20+
for path in ["/etc/mirrors.car", os.path.expanduser("~/.config/mirrors.car")]:
2121
if not os.path.exists(path):
2222
os.makedirs(os.path.dirname(path), exist_ok=True)
2323
with open(path, "w") as f:
2424
f.write(mirrors)
2525

26-
install_script_places = []
27-
packagelist_places = []
28-
versions_places = []
26+
install_script_places = [] # list of (repo, url)
27+
packagelist_places = [] # list of (repo, url)
28+
versions_places = [] # list of (repo, url)
2929
repos = []
3030

3131
current_repo = None
3232
current_data = {}
3333

34+
# parse mirrors config
3435
for line in mirrors.strip().splitlines():
3536
line = line.strip()
37+
3638
if line.startswith(":") and line.endswith(":") and line != ":end:":
3739
current_repo = line.strip(":")
3840
repos.append(current_repo)
3941
current_data = {}
42+
4043
elif line == ":end:":
4144
if "install_script" in current_data:
42-
install_script_places.append(current_data["install_script"])
45+
install_script_places.append((current_repo, current_data["install_script"]))
4346
if "packagelist" in current_data:
44-
packagelist_places.append(current_data["packagelist"])
47+
packagelist_places.append((current_repo, current_data["packagelist"]))
4548
if "versions" in current_data:
46-
versions_places.append(current_data["versions"])
49+
versions_places.append((current_repo, current_data["versions"]))
4750
current_repo = None
4851
current_data = {}
52+
4953
elif current_repo and "=" in line:
5054
key, value = line.split("=", 1)
5155
current_data[key.strip()] = value.strip()
5256

53-
def fetch_one(url):
57+
58+
def fetch_one(repo, url):
5459
print("fetch " + url)
5560
try:
5661
result = subprocess.run(
5762
["curl", "-fsSL", url],
5863
capture_output=True,
5964
text=True,
60-
check=True
65+
check=True,
6166
)
6267
packages = [line.strip() for line in result.stdout.splitlines() if line.strip()]
63-
repo_name = url.strip().split("/")[-2] if "/" in url else "unknown"
64-
return [f"{repo_name}/{pkg}" for pkg in packages]
68+
return [f"{repo}/{pkg}" for pkg in packages]
6569
except subprocess.CalledProcessError:
6670
return []
6771

72+
6873
def fetch_all_packages(packagelist_places, max_threads=8):
6974
all_packages = []
7075
with ThreadPoolExecutor(max_workers=max_threads) as executor:
71-
results = executor.map(fetch_one, packagelist_places)
76+
results = executor.map(
77+
lambda x: fetch_one(x[0], x[1]),
78+
packagelist_places,
79+
)
7280
for r in results:
7381
all_packages.extend(r)
7482
return all_packages

src/nocarinit.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
3+
import status
4+
5+
6+
def main():
7+
if not os.path.isdir("/etc/car"):
8+
return True
9+
else:
10+
return False

0 commit comments

Comments
 (0)