@@ -20,101 +20,21 @@ import subprocess
20
20
logger = logging .getLogger ("breaker" )
21
21
22
22
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
118
38
119
39
120
40
# Get reverse library dependency for specified package
@@ -185,18 +105,19 @@ def get_revdeps(
185
105
# get package versions and filter out removed packages
186
106
res = []
187
107
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" ]):
190
113
logger .warning ("Package %s dropped, skipping" , pkg )
191
114
continue
192
115
193
- version = get_package_version (package_path , defines_path )
194
116
res .append (
195
117
{
196
118
"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" ],
200
121
}
201
122
)
202
123
logger .info ("Reverse dependencies: %s" , ", " .join ([pkg ["name" ] for pkg in res ]))
@@ -205,7 +126,7 @@ def get_revdeps(
205
126
206
127
# Generate groups/xxx-rebuilds content
207
128
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 ]
209
130
rebuilds_path_list = [
210
131
i for i in rebuilds_path_list if i != None and len (i .split ("/" )) == 2
211
132
]
@@ -333,8 +254,8 @@ def main():
333
254
exit (1 )
334
255
335
256
# 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" ]
338
259
339
260
revdeps = get_revdeps (args .package , args .alldeps , args .include , args .exclude )
340
261
@@ -349,8 +270,8 @@ def main():
349
270
logger .info ("Bumping reverse depedencies" )
350
271
reason = f"{ args .package } update to { version } "
351
272
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 )
354
275
logger .info ("Created %s git commits" , len (revdeps ))
355
276
356
277
if args .pkgbreak :
@@ -360,7 +281,7 @@ def main():
360
281
logger .info ("Using acbs-build to reorder packages" )
361
282
output = subprocess .check_output (
362
283
["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 ],
364
285
encoding = "utf-8" ,
365
286
)
366
287
for line in output .split ("\n " ):
0 commit comments