Skip to content

Commit 67d730c

Browse files
committed
breaker: resole updated package locally
1 parent 3c8b314 commit 67d730c

File tree

1 file changed

+100
-3
lines changed

1 file changed

+100
-3
lines changed

breaker

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,103 @@ def get_package_info(package_name: str) -> dict[str, str]:
3737
return None
3838

3939

40+
# Locate package & autobuild path for specified package
41+
def search_package_path(package_name: str) -> tuple[str, str]:
42+
with os.scandir(".") as dir1:
43+
for section in dir1:
44+
if section.is_dir() and not section.name.startswith("."):
45+
with os.scandir(section) as dir2:
46+
for package in dir2:
47+
if package.is_dir() and os.path.isdir(
48+
os.path.join(package, "autobuild")
49+
):
50+
defines_path = os.path.join(
51+
package.path, "autobuild/defines"
52+
)
53+
if os.path.exists(defines_path):
54+
with open(defines_path, "r") as f:
55+
defines = f.readlines()
56+
for line in defines:
57+
if "PKGNAME=" in line and (
58+
"{}\n".format(package_name) == line[8:]
59+
or '"{}"\n'.format(package_name) == line[8:]
60+
):
61+
return (
62+
package.path[2:],
63+
defines_path[2:],
64+
)
65+
66+
continue
67+
68+
# search subpackage, like arch-install-scripts/01-genfstab
69+
path = package
70+
if os.path.isdir(path) and section.name != "groups":
71+
with os.scandir(path) as dir3:
72+
for subpackage in dir3:
73+
if (
74+
subpackage.name != "autobuild"
75+
and subpackage.is_dir()
76+
):
77+
defines_path = os.path.join(
78+
subpackage, "defines"
79+
)
80+
try:
81+
with open(defines_path, "r") as f:
82+
defines = f.readlines()
83+
except:
84+
with open(
85+
os.path.join(
86+
subpackage, "autobuild/defines"
87+
),
88+
"r",
89+
) as f:
90+
defines = f.readlines()
91+
finally:
92+
for line in defines:
93+
if "PKGNAME=" in line and (
94+
"{}\n".format(package_name)
95+
== line[8:]
96+
or '"{}"\n'.format(package_name)
97+
== line[8:]
98+
):
99+
return (
100+
package.path[2:],
101+
defines_path[2:],
102+
)
103+
# not found
104+
return None, None
105+
106+
107+
# Get version of package
108+
def get_package_version(package_path: str, defines_path: str) -> str:
109+
ver = None
110+
rel = None
111+
pkgepoch = None
112+
113+
spec_path = os.path.join(package_path, "spec")
114+
with open(spec_path, "r") as f:
115+
for i in f:
116+
if i.startswith("VER="):
117+
ver = i.replace("VER=", "").strip()
118+
if i.startswith("REL="):
119+
rel = i.replace("REL=", "").strip()
120+
121+
with open(defines_path, "r") as f:
122+
for i in f:
123+
if i.startswith("PKGEPOCH="):
124+
pkgepoch = i.replace("PKGEPOCH=", "").strip()
125+
126+
res = None
127+
if ver is not None:
128+
res = ver
129+
if rel is not None:
130+
res += "-" + rel
131+
if pkgepoch is not None:
132+
res = pkgepoch + ":" + res
133+
134+
return res
135+
136+
40137
# Get reverse library dependency for specified package
41138
def get_revdeps(
42139
package_name: str, alldeps: bool, include: list[str], exclude: list[str]
@@ -253,9 +350,9 @@ def main():
253350
logger.error("Do not use --bump with --rebuilds or --pkgbreak")
254351
exit(1)
255352

256-
# get info of new package
257-
package_info = get_package_info(args.package)
258-
version = package_info["version"]
353+
# get info of new package locally
354+
package_path, defines_path = search_package_path(args.package)
355+
version = get_package_version(package_path, defines_path)
259356

260357
revdeps = get_revdeps(args.package, args.alldeps, args.include, args.exclude)
261358

0 commit comments

Comments
 (0)