Skip to content

Commit 3c8b314

Browse files
committed
breaker: use mini packages site to get package path and version
1 parent 7348ec0 commit 3c8b314

File tree

1 file changed

+28
-107
lines changed

1 file changed

+28
-107
lines changed

breaker

Lines changed: 28 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -20,101 +20,21 @@ import subprocess
2020
logger = logging.getLogger("breaker")
2121

2222

23-
# Locate package & autobuild path for specified package
24-
def search_package_path(package_name: str) -> tuple[str, str]:
25-
with os.scandir(".") as dir1:
26-
for section in dir1:
27-
if section.is_dir() and not section.name.startswith("."):
28-
with os.scandir(section) as dir2:
29-
for package in dir2:
30-
if package.is_dir() and os.path.isdir(
31-
os.path.join(package, "autobuild")
32-
):
33-
defines_path = os.path.join(
34-
package.path, "autobuild/defines"
35-
)
36-
if os.path.exists(defines_path):
37-
with open(defines_path, "r") as f:
38-
defines = f.readlines()
39-
for line in defines:
40-
if "PKGNAME=" in line and (
41-
"{}\n".format(package_name) == line[8:]
42-
or '"{}"\n'.format(package_name) == line[8:]
43-
):
44-
return (
45-
package.path[2:],
46-
defines_path[2:],
47-
)
48-
49-
continue
50-
51-
# search subpackage, like arch-install-scripts/01-genfstab
52-
path = package
53-
if os.path.isdir(path) and section.name != "groups":
54-
with os.scandir(path) as dir3:
55-
for subpackage in dir3:
56-
if (
57-
subpackage.name != "autobuild"
58-
and subpackage.is_dir()
59-
):
60-
defines_path = os.path.join(
61-
subpackage, "defines"
62-
)
63-
try:
64-
with open(defines_path, "r") as f:
65-
defines = f.readlines()
66-
except:
67-
with open(
68-
os.path.join(
69-
subpackage, "autobuild/defines"
70-
),
71-
"r",
72-
) as f:
73-
defines = f.readlines()
74-
finally:
75-
for line in defines:
76-
if "PKGNAME=" in line and (
77-
"{}\n".format(package_name)
78-
== line[8:]
79-
or '"{}"\n'.format(package_name)
80-
== line[8:]
81-
):
82-
return (
83-
package.path[2:],
84-
defines_path[2:],
85-
)
86-
# not found
87-
return None, None
88-
89-
90-
# Get version of package
91-
def get_package_version(package_path: str, defines_path: str) -> str:
92-
ver = None
93-
rel = None
94-
pkgepoch = None
95-
96-
spec_path = os.path.join(package_path, "spec")
97-
with open(spec_path, "r") as f:
98-
for i in f:
99-
if i.startswith("VER="):
100-
ver = i.replace("VER=", "").strip()
101-
if i.startswith("REL="):
102-
rel = i.replace("REL=", "").strip()
103-
104-
with open(defines_path, "r") as f:
105-
for i in f:
106-
if i.startswith("PKGEPOCH="):
107-
pkgepoch = i.replace("PKGEPOCH=", "").strip()
108-
109-
res = None
110-
if ver is not None:
111-
res = ver
112-
if rel is not None:
113-
res += "-" + rel
114-
if pkgepoch is not None:
115-
res = pkgepoch + ":" + res
116-
117-
return res
23+
# Get package info from minipkgsite
24+
def get_package_info(package_name: str) -> dict[str, str]:
25+
try:
26+
response = requests.get(
27+
"https://api.mini.packages.aosc.io/package?name={}".format(package_name)
28+
)
29+
response.raise_for_status()
30+
package_info = response.json()
31+
return package_info
32+
except:
33+
logger.warning(
34+
"Failed to get info of package %s from mini packages site",
35+
package_name,
36+
)
37+
return None
11838

11939

12040
# Get reverse library dependency for specified package
@@ -185,18 +105,19 @@ def get_revdeps(
185105
# get package versions and filter out removed packages
186106
res = []
187107
for pkg in revdeps_list:
188-
package_path, defines_path = search_package_path(pkg)
189-
if package_path is None:
108+
package_info = get_package_info(pkg)
109+
if package_info is None:
110+
logger.warning("Package %s not found, skipping", pkg)
111+
continue
112+
if not os.path.exists(package_info["path"]):
190113
logger.warning("Package %s dropped, skipping", pkg)
191114
continue
192115

193-
version = get_package_version(package_path, defines_path)
194116
res.append(
195117
{
196118
"name": pkg,
197-
"package_path": package_path,
198-
"defines_path": defines_path,
199-
"version": version,
119+
"path": package_info["path"],
120+
"version": package_info["version"],
200121
}
201122
)
202123
logger.info("Reverse dependencies: %s", ", ".join([pkg["name"] for pkg in res]))
@@ -205,7 +126,7 @@ def get_revdeps(
205126

206127
# Generate groups/xxx-rebuilds content
207128
def gen_rebuilds_list_string(revdep_list: list[dict[str, str]], args) -> str:
208-
rebuilds_path_list = [pkg["package_path"] for pkg in revdep_list]
129+
rebuilds_path_list = [pkg["path"] for pkg in revdep_list]
209130
rebuilds_path_list = [
210131
i for i in rebuilds_path_list if i != None and len(i.split("/")) == 2
211132
]
@@ -333,8 +254,8 @@ def main():
333254
exit(1)
334255

335256
# get info of new package
336-
package_path, defines_path = search_package_path(args.package)
337-
version = get_package_version(package_path, defines_path)
257+
package_info = get_package_info(args.package)
258+
version = package_info["version"]
338259

339260
revdeps = get_revdeps(args.package, args.alldeps, args.include, args.exclude)
340261

@@ -349,8 +270,8 @@ def main():
349270
logger.info("Bumping reverse depedencies")
350271
reason = f"{args.package} update to {version}"
351272
for pkg in revdeps:
352-
spec_path = os.path.join(pkg["package_path"], "spec")
353-
bump_rel(reason, os.path.basename(pkg["package_path"]), spec_path)
273+
spec_path = os.path.join(pkg["path"], "spec")
274+
bump_rel(reason, os.path.basename(pkg["path"]), spec_path)
354275
logger.info("Created %s git commits", len(revdeps))
355276

356277
if args.pkgbreak:
@@ -360,7 +281,7 @@ def main():
360281
logger.info("Using acbs-build to reorder packages")
361282
output = subprocess.check_output(
362283
["sudo", "ciel", "shell", "-i", "main", "--", "acbs-build", "-ep", args.package]
363-
+ [os.path.basename(pkg["package_path"]) for pkg in revdeps],
284+
+ [os.path.basename(pkg["path"]) for pkg in revdeps],
364285
encoding="utf-8",
365286
)
366287
for line in output.split("\n"):

0 commit comments

Comments
 (0)