Gentoo Archives: gentoo-commits

From: Stephan Hartmann <sultan@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/chromium-tools:master commit in: /
Date: Fri, 06 May 2022 09:55:59
Message-Id: 1651830951.eb9734c60aff0ea27cf030a88b4779ae613f88dd.sultan@gentoo
1 commit: eb9734c60aff0ea27cf030a88b4779ae613f88dd
2 Author: Stephan Hartmann <sultan <AT> gentoo <DOT> org>
3 AuthorDate: Fri May 6 09:54:02 2022 +0000
4 Commit: Stephan Hartmann <sultan <AT> gentoo <DOT> org>
5 CommitDate: Fri May 6 09:55:51 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/chromium-tools.git/commit/?id=eb9734c6
7
8 Add opera-bump script
9
10 Signed-off-by: Stephan Hartmann <sultan <AT> gentoo.org>
11
12 opera-bump | 397 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 397 insertions(+)
14
15 diff --git a/opera-bump b/opera-bump
16 new file mode 100755
17 index 0000000..c1e3c46
18 --- /dev/null
19 +++ b/opera-bump
20 @@ -0,0 +1,397 @@
21 +#!/bin/env python3
22 +
23 +import argparse
24 +import json
25 +import os
26 +import shutil
27 +import sys
28 +import urllib.request
29 +import subprocess
30 +import functools
31 +import operator
32 +
33 +from bs4 import BeautifulSoup
34 +from debian import deb822
35 +from contextlib import closing
36 +
37 +from portage.dbapi.porttree import portdbapi
38 +from portage.versions import *
39 +from portage.package.ebuild import digestgen, config
40 +from portage.output import EOutput
41 +
42 +from git import Repo
43 +
44 +pkg_data = \
45 +{
46 + "stable" :
47 + {
48 + "pkg" : "opera",
49 + "suffix" : "stable",
50 + "version" : [],
51 + "dversion" : [],
52 + "bversion" : [],
53 + "stable" : True,
54 + "count" : 1
55 + },
56 + "beta" :
57 + {
58 + "pkg" : "opera-beta",
59 + "suffix" : None,
60 + "version" : [],
61 + "dversion" : [],
62 + "bversion" : [],
63 + "stable" : False,
64 + "count" : 3
65 + },
66 + "dev" :
67 + {
68 + "pkg" : "opera-developer",
69 + "suffix" : None,
70 + "version" : [],
71 + "dversion" : [],
72 + "bversion" : [],
73 + "stable" : False,
74 + "count" : 3
75 + }
76 +}
77 +
78 +def getOperaVersionInfo(base_url, archive, arch, version):
79 + if not base_url.endswith("/"):
80 + url = base_url + "/"
81 + url += f"{version}/linux"
82 + try:
83 + req = urllib.request.urlopen(url)
84 + except urllib.error.HTTPError:
85 + return None
86 + soup = BeautifulSoup(req, "html.parser")
87 + base_fn = f"{archive}_{version}_{arch}."
88 + rpm = False
89 + for node in soup.find_all("a"):
90 + v = node.get("href")
91 + if v.startswith(base_fn):
92 + if v.endswith("rpm"):
93 + rpm = True
94 + elif v.endswith("deb"):
95 + return (version, "0", "deb")
96 + if rpm:
97 + return (version, "0", "rpm")
98 + return None
99 +
100 +def getOperaVersionData(base_url, package, archive, arch, tversion,
101 + platform=None):
102 + if not base_url.endswith("/"):
103 + url = base_url + "/"
104 + url += package
105 + if platform is not None:
106 + url += f"/{platform}"
107 +
108 + req = urllib.request.urlopen(url)
109 + soup = BeautifulSoup(req, "html.parser")
110 + versions = []
111 + for node in soup.find_all("a"):
112 + v = node.get("href")
113 + if v.endswith("/"):
114 + v = v[:-1]
115 + if v != "..":
116 + check = False
117 + for tver in tversion:
118 + c = vercmp(v, tver[0])
119 + if c is not None and c >= 0:
120 + check = True
121 + if check:
122 + ver = getOperaVersionInfo(base_url=url,
123 + archive=archive,
124 + arch=arch,
125 + version=v)
126 + if ver is not None:
127 + versions.append(ver)
128 + return versions
129 +
130 +def compareOperaVersion(item1, item2):
131 + return -vercmp(item1[0], item2[0])
132 +
133 +def isMajorBump(channel, uversion, tversion):
134 + uv_list = uversion.split(".")
135 + tv_list = tversion.split(".")
136 + if ( int(uv_list[0]) > int(tv_list[0]) and
137 + getPrevChannel(channel=channel) != channel ):
138 + return True
139 + return False
140 +
141 +def getPrevChannel(channel):
142 + channels = list(pkg_data.keys())
143 + channel_list = channels + [channels[len(channels) - 1]]
144 + for i in range(0, len(channel_list) - 1):
145 + if channel_list[i] == channel:
146 + return channel_list[i + 1]
147 + raise ValueError(f"Unknown channel \"{channel}\".")
148 +
149 +def getEbuildVersion(version):
150 + if version[1] == "r0":
151 + return version[0]
152 + return f"{version[0]}-{version[1]}"
153 +
154 +def main():
155 + parser = argparse.ArgumentParser()
156 + parser.add_argument("--dry-run", "-n", action="store_true")
157 + args = parser.parse_args()
158 +
159 + output = EOutput()
160 +
161 + output.einfo("Looking up Opera versions information in tree ...")
162 +
163 + db = portdbapi()
164 + repo_path = db.getRepositoryPath(repository_id="gentoo")
165 + for channel in pkg_data.keys():
166 + pkg = pkg_data[channel]["pkg"]
167 + cpvs = db.cp_list(mycp=f"www-client/{pkg}", mytree=repo_path)
168 + for cpv in cpvs:
169 + (cp, version, rev) = pkgsplit(mypkg=cpv)
170 + pkg_data[channel]["version"].append((version,rev))
171 + if len(pkg_data[channel]["version"]) == 0:
172 + output.ewarn("Couldn't determine tree versions for "+
173 + "www-client/{pkg}")
174 + pkg_data[channel]["version"].sort(key=functools.cmp_to_key(compareOperaVersion))
175 +
176 + opera_info = {}
177 + for channel in pkg_data.keys():
178 + archive = pkg_data[channel]["pkg"]
179 + platform = None
180 + if pkg_data[channel]["suffix"] is not None:
181 + archive += "-" + pkg_data[channel]["suffix"]
182 + platform = "desktop"
183 + output.einfo(f"Fetching upstream version information \"{archive}\" ...")
184 + versions = getOperaVersionData(base_url="https://download1.operacdn.com/pub",
185 + package=pkg_data[channel]["pkg"],
186 + archive=archive, arch="amd64",
187 + tversion=pkg_data[channel]["version"],
188 + platform=platform)
189 + versions.sort(key=functools.cmp_to_key(compareOperaVersion))
190 + opera_info[channel] = versions
191 +
192 + output.einfo("Comparing Opera version informations ...")
193 +
194 + for channel in pkg_data.keys():
195 + versions = map(operator.itemgetter(0), opera_info[channel])
196 + for ver in pkg_data[channel]["version"]:
197 + if ver[0] not in versions:
198 + output.ewarn("Upstream dropped version " +
199 + f"{ver[0]} from channel " +
200 + f"\"{channel}\" of www-client/" +
201 + f"{pkg_data[channel]['pkg']}.")
202 + pkg_data[channel]["dversion"].append(ver)
203 +
204 + for channel in pkg_data.keys():
205 + if len(opera_info[channel]) == 0:
206 + output.ewarn(f"Upstream version unknown for channel \"{channel}\".")
207 + else:
208 + for uver in opera_info[channel]:
209 + bump = None
210 + for tver in pkg_data[channel]["version"]:
211 + ver_info = vercmp(uver[0], getEbuildVersion(tver))
212 + if ver_info is None:
213 + output.ewarn("Cannot determine new version for " +
214 + f"channel \"{channel}\" of " +
215 + f"www-client/" +
216 + f"{pkg_data[channel]['pkg']}.")
217 + bump = False
218 + break
219 + elif ver_info > 0:
220 + if bump is None:
221 + bump = True
222 + elif ver_info == 0:
223 + bump = False
224 + elif ver_info < 0:
225 + bump = False
226 + if bump:
227 + pkg_data[channel]["bversion"].append((uver[0], "r0"))
228 +
229 + if ( len(pkg_data[channel]["bversion"]) == 0 and
230 + len(pkg_data[channel]["dversion"]) ==
231 + len(pkg_data[channel]["version"]) ):
232 + output.ewarn("Update would remove all versions " +
233 + f"from tree for channel \"{channel}\" of " +
234 + f"www-client/" +
235 + f"{pkg_data[channel]['pkg']}.")
236 + pkg_data[channel]["dversion"] = []
237 + elif ( len(pkg_data[channel]["bversion"]) >=
238 + pkg_data[channel]["count"] ):
239 + count = pkg_data[channel]["count"]
240 + pkg_data[channel]["bversion"] = \
241 + pkg_data[channel]["bversion"][:count]
242 + pkg_data[channel]["dversion"] = pkg_data[channel]["version"]
243 + elif ( len(pkg_data[channel]["bversion"]) +
244 + len(pkg_data[channel]["version"]) >
245 + pkg_data[channel]["count"] ):
246 + count = len(pkg_data[channel]["bversion"]) + \
247 + len(pkg_data[channel]["version"]) - \
248 + pkg_data[channel]["count"]
249 + pkg_data[channel]["dversion"] = \
250 + pkg_data[channel]["version"][-count:]
251 +
252 + for channel in pkg_data.keys():
253 + pkg = pkg_data[channel]["pkg"]
254 + output.einfo(f"www-client/{pkg} version information:")
255 + vstr = ""
256 + for ver in reversed(pkg_data[channel]["version"]):
257 + if ver in pkg_data[channel]["dversion"]:
258 + vstr += f"({getEbuildVersion(ver)})\t"
259 + else:
260 + vstr += f"{getEbuildVersion(ver)}\t"
261 + for ver in pkg_data[channel]["bversion"]:
262 + vstr += f"{getEbuildVersion(ver)}*\t"
263 + output.einfo(f"\t{channel}\t{vstr}")
264 +
265 + if len(pkg_data[channel]["bversion"]) > 0:
266 + output.einfo(f"\t\t==> bump")
267 + elif len(pkg_data[channel]["dversion"]) > 0:
268 + output.einfo(f"\t\t==> cleanup")
269 + else:
270 + output.einfo(f"\t\t==> unchanged")
271 +
272 + if not args.dry_run:
273 + repo = Repo(repo_path)
274 + if repo.is_dirty():
275 + output.eerror("Git Repository is dirty, can't continue.")
276 + sys.exit(1)
277 +
278 + index = repo.index
279 +
280 + for channel in pkg_data.keys():
281 + pkg = pkg_data[channel]["pkg"]
282 + tver = pkg_data[channel]["version"][0]
283 + tversion = getEbuildVersion(tver)
284 + for uver in pkg_data[channel]["bversion"]:
285 + uversion = getEbuildVersion(uver)
286 + major_bump = isMajorBump(channel=channel,
287 + uversion=uver[0],
288 + tversion=tver[0])
289 + output.einfo(f"Bumping www-client/{pkg}-{uversion} ...")
290 + if major_bump:
291 + prev_channel = getPrevChannel(channel=channel)
292 + prev_pkg = pkg_data[prev_channel]["pkg"]
293 + prev_version = getEbuildVersion(
294 + pkg_data[prev_channel]["version"][0])
295 + from_ebuild = os.path.join("www-client",
296 + prev_pkg,
297 + prev_pkg + "-" +
298 + prev_version +
299 + ".ebuild")
300 + from_meta = os.path.join("www-client",
301 + prev_pkg,
302 + "metadata.xml")
303 + to_meta = os.path.join("www-client",
304 + pkg,
305 + "metadata.xml")
306 + else:
307 + from_ebuild = os.path.join("www-client",
308 + pkg,
309 + pkg + "-" +
310 + tversion +
311 + ".ebuild")
312 + to_ebuild = os.path.join("www-client",
313 + pkg,
314 + pkg + "-" +
315 + uversion +
316 + ".ebuild")
317 +
318 + if args.dry_run:
319 + print(f"cp {from_ebuild} {to_ebuild}")
320 + if pkg_data[channel]["stable"]:
321 + print(f"ekeyword ~amd64 {to_ebuild}")
322 + print(f"git add {to_ebuild}")
323 + if major_bump:
324 + print(f"cp {from_meta} {to_meta}")
325 + print(f"git add {to_meta}")
326 + else:
327 + to_ebuild = os.path.join(repo_path, to_ebuild)
328 + from_ebuild = os.path.join(repo_path, from_ebuild)
329 + shutil.copyfile(from_ebuild, to_ebuild)
330 + if pkg_data[channel]["stable"]:
331 + subprocess.check_call(["ekeyword", "~amd64", to_ebuild])
332 + index.add(to_ebuild)
333 + if major_bump:
334 + to_meta = os.path.join(repo_path, to_meta)
335 + from_meta = os.path.join(repo_path, from_meta)
336 +
337 + if args.dry_run:
338 + print(f"git add {os.path.join('www-client', pkg, 'Manifest')}")
339 + print("git commit -m",
340 + f"\"www-client/{pkg}: automated bump",
341 + f"({uversion})",
342 + "-s -S\"")
343 + else:
344 + to_path = os.path.dirname(to_ebuild)
345 + cfg = config.config()
346 + cfg["O"] = to_path
347 +
348 + digestgen.digestgen(None, cfg, db)
349 + index.add(os.path.join(to_path, "Manifest"))
350 +
351 + repo.git.commit("-m",
352 + f"www-client/{pkg}: automated bump ({uversion})",
353 + "-s", "-S")
354 +
355 + if pkg_data[channel]["stable"]:
356 + for bver in pkg_data[channel]["bversion"]:
357 + bversion = getEbuildVersion(bver)
358 + output.einfo(f"Stabilizing www-client/{pkg}-{bversion} ...")
359 + ebuild = os.path.join("www-client",
360 + pkg,
361 + pkg + "-" +
362 + bversion +
363 + ".ebuild")
364 + if args.dry_run:
365 + print(f"ekeyword amd64 {ebuild}")
366 + print(f"git add {os.path.join('www-client', pkg, 'Manifest')}")
367 + print("git commit -m",
368 + f"\"www-client/{pkg}: amd64 stable ({bversion})\" -s -S")
369 + else:
370 + ebuild = os.path.join(repo_path, ebuild)
371 + subprocess.check_call(["ekeyword", "amd64", ebuild])
372 + index.add(ebuild)
373 +
374 + to_path = os.path.dirname(ebuild)
375 + cfg = config.config()
376 + cfg["O"] = to_path
377 +
378 + digestgen.digestgen(None, cfg, db)
379 + index.add(os.path.join(to_path, "Manifest"))
380 +
381 + repo.git.commit("-m",
382 + f"www-client/{pkg}: amd64 stable ({bversion})",
383 + "-s", "-S")
384 +
385 + for dver in pkg_data[channel]["dversion"]:
386 + dversion = getEbuildVersion(dver)
387 + output.einfo(f"Removing www-client/{pkg}-{dversion} ...")
388 + rm_ebuild = os.path.join("www-client",
389 + pkg,
390 + pkg + "-" +
391 + dversion +
392 + ".ebuild")
393 + if args.dry_run:
394 + print(f"git rm {os.path.relpath(rm_ebuild, repo_path)}")
395 + else:
396 + rm_ebuild = os.path.join(repo_path, rm_ebuild)
397 + index.remove(rm_ebuild, working_tree=True)
398 +
399 + if len(pkg_data[channel]["dversion"]) > 0:
400 + if args.dry_run:
401 + print(f"git add {os.path.join('www-client', pkg, 'Manifest')}")
402 + print("git commit -m",
403 + f"\"www-client/{pkg}: remove old\" -s -S")
404 + else:
405 + to_path = os.path.dirname(rm_ebuild)
406 + cfg = config.config()
407 + cfg["O"] = to_path
408 +
409 + digestgen.digestgen(None, cfg, db)
410 + index.add(os.path.join(to_path, "Manifest"))
411 +
412 + repo.git.commit("-m",
413 + f"www-client/{pkg}: remove old",
414 + "-s", "-S")
415 +
416 +if __name__ == "__main__":
417 + main()