1 |
commit: 46e5883adc29ea0ae920800a449db4684004dc3a |
2 |
Author: Stephan Hartmann <sultan <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Feb 5 16:28:38 2022 +0000 |
4 |
Commit: Stephan Hartmann <sultan <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Feb 5 16:29:12 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/chromium-tools.git/commit/?id=46e5883a |
7 |
|
8 |
bump_chrome.py: add revision and dry run support |
9 |
|
10 |
Signed-off-by: Stephan Hartmann <sultan <AT> gentoo.org> |
11 |
|
12 |
bump_chrome.py | 99 ++++++++++++++++++++++++++++++++++++++-------------------- |
13 |
1 file changed, 66 insertions(+), 33 deletions(-) |
14 |
|
15 |
diff --git a/bump_chrome.py b/bump_chrome.py |
16 |
index a046815..dadc059 100755 |
17 |
--- a/bump_chrome.py |
18 |
+++ b/bump_chrome.py |
19 |
@@ -6,6 +6,7 @@ import os |
20 |
import shutil |
21 |
import sys |
22 |
import urllib.request |
23 |
+import subprocess |
24 |
|
25 |
from portage.dbapi.porttree import portdbapi |
26 |
from portage.versions import * |
27 |
@@ -25,7 +26,7 @@ pkg_data = \ |
28 |
"suffix" : None, |
29 |
"version" : None, |
30 |
"bump" : False, |
31 |
- "stable" : False |
32 |
+ "stable" : True |
33 |
}, |
34 |
"beta" : |
35 |
{ |
36 |
@@ -102,9 +103,13 @@ def getPrevChannel(channel): |
37 |
return channel_list[i + 1] |
38 |
raise ValueError(f"Unknown channel \"{channel}\".") |
39 |
|
40 |
+def getEbuildVersion(version): |
41 |
+ if version[1] == "r0": |
42 |
+ return version[0] |
43 |
+ return f"{version[0]}-{version[1]}" |
44 |
+ |
45 |
def main(): |
46 |
parser = argparse.ArgumentParser() |
47 |
- parser.add_argument('--commit', '-c', action='store_true') |
48 |
parser.add_argument('--dry-run', '-n', action='store_true') |
49 |
args = parser.parse_args() |
50 |
|
51 |
@@ -134,13 +139,14 @@ def main(): |
52 |
pkg_data[category][channel]["version"] = None |
53 |
for cpv in cpvs: |
54 |
(cp, version, rev) = pkgsplit(mypkg=cpv) |
55 |
- suffix = pkg_data[category][channel]['suffix'] |
56 |
+ suffix = pkg_data[category][channel]["suffix"] |
57 |
if suffix is not None: |
58 |
suffix = "_" + suffix |
59 |
if version.endswith(suffix): |
60 |
- pkg_data[category][channel]["version"] = version[:-len(suffix)] |
61 |
+ pkg_data[category][channel]["version"] = (version[:-len(suffix)], |
62 |
+ rev) |
63 |
elif not "_" in version: |
64 |
- pkg_data[category][channel]["version"] = version |
65 |
+ pkg_data[category][channel]["version"] = (version, rev) |
66 |
if pkg_data[category][channel]["version"] is None: |
67 |
output.ewarn("Couldn't determine tree version for "+ |
68 |
"{category}/{pkg}") |
69 |
@@ -154,7 +160,7 @@ def main(): |
70 |
for category in pkg_data.keys(): |
71 |
pkg_data[category][channel]["bump"] = False |
72 |
ver_info = vercmp(chrome_info[channel], |
73 |
- pkg_data[category][channel]["version"]) |
74 |
+ pkg_data[category][channel]["version"][0]) |
75 |
if ver_info is None: |
76 |
output.ewarn("Cannot determine new version for " + |
77 |
f"channel \"{channel}\" of " + |
78 |
@@ -174,23 +180,26 @@ def main(): |
79 |
output.einfo(f"{category}/{pkg} version information:") |
80 |
need_bump = pkg_data[category][channel]["bump"] |
81 |
uversion = chrome_info[channel] |
82 |
- tversion = pkg_data[category][channel]["version"] |
83 |
+ tversion = getEbuildVersion(pkg_data[category][channel]["version"]) |
84 |
output.einfo(f"\t{channel}\t{tversion}\t{uversion}" + |
85 |
f"\t==> {'bump' if need_bump else 'no bump'}") |
86 |
|
87 |
- repo = Repo(repo_path) |
88 |
- if repo.is_dirty(): |
89 |
- output.eerror("Git Repository is dirty, can't continue.") |
90 |
- sys.exit(1) |
91 |
+ if not args.dry_run: |
92 |
+ repo = Repo(repo_path) |
93 |
+ if repo.is_dirty(): |
94 |
+ output.eerror("Git Repository is dirty, can't continue.") |
95 |
+ sys.exit(1) |
96 |
+ |
97 |
+ index = repo.index |
98 |
|
99 |
- index = repo.index |
100 |
for channel in channels: |
101 |
for category in pkg_data.keys(): |
102 |
if not pkg_data[category][channel]["bump"]: |
103 |
continue |
104 |
uversion = chrome_info[channel] |
105 |
- tversion = pkg_data[category][channel]["version"] |
106 |
- major_bump = isMajorBump(uversion=uversion, tversion=tversion) |
107 |
+ tversion = getEbuildVersion(pkg_data[category][channel]["version"]) |
108 |
+ major_bump = isMajorBump(uversion=uversion, |
109 |
+ tversion=pkg_data[category][channel]["version"][0]) |
110 |
pkg = pkg_data[category][channel]["pkg"] |
111 |
suffix = pkg_data[category][channel]["suffix"] |
112 |
if suffix is not None: |
113 |
@@ -201,58 +210,82 @@ def main(): |
114 |
if major_bump: |
115 |
prev_channel = getPrevChannel(channel=channel) |
116 |
prev_pkg = pkg_data[category][prev_channel]["pkg"] |
117 |
- prev_version = pkg_data[category][prev_channel]["version"] |
118 |
+ prev_version = getEbuildVersion(pkg_data[category][prev_channel]["version"]) |
119 |
prev_suffix = pkg_data[category][prev_channel]["suffix"] |
120 |
- print(prev_pkg) |
121 |
if prev_suffix is not None: |
122 |
prev_suffix = "_" + prev_suffix |
123 |
else: |
124 |
prev_suffix = "" |
125 |
- from_ebuild = os.path.join(repo_path, |
126 |
- category, |
127 |
+ from_ebuild = os.path.join(category, |
128 |
prev_pkg, |
129 |
prev_pkg + "-" + |
130 |
prev_version + prev_suffix + |
131 |
".ebuild") |
132 |
else: |
133 |
- from_ebuild = os.path.join(repo_path, |
134 |
- category, |
135 |
+ from_ebuild = os.path.join(category, |
136 |
pkg, |
137 |
pkg + "-" + |
138 |
tversion + suffix + |
139 |
".ebuild") |
140 |
- to_ebuild = os.path.join(repo_path, |
141 |
- category, |
142 |
+ to_ebuild = os.path.join(category, |
143 |
pkg, |
144 |
pkg + "-" + |
145 |
uversion + suffix + |
146 |
".ebuild") |
147 |
|
148 |
- shutil.copyfile(from_ebuild, to_ebuild) |
149 |
+ if args.dry_run: |
150 |
+ print(f"cp {from_ebuild} {to_ebuild}") |
151 |
+ if not major_bump: |
152 |
+ print(f"git rm {from_ebuild}") |
153 |
+ else: |
154 |
+ from_ebuild = os.path.join(repo_path, from_ebuild) |
155 |
+ shutil.copyfile(from_ebuild, |
156 |
+ os.path.join(repo_path, to_ebuild)) |
157 |
+ if not major_bump: |
158 |
+ index.remove(from_ebuild, working_tree=True) |
159 |
|
160 |
- index.add(to_ebuild) |
161 |
if major_bump: |
162 |
- old_ebuild = os.path.join(repo_path, |
163 |
- category, |
164 |
+ old_ebuild = os.path.join(category, |
165 |
pkg, |
166 |
pkg + "-" + |
167 |
tversion + suffix + |
168 |
".ebuild") |
169 |
- index.remove(old_ebuild, working_tree=True) |
170 |
+ if args.dry_run: |
171 |
+ print(f"git rm {old_ebuild}") |
172 |
+ else: |
173 |
+ index.remove(os.path.join(repo_path, old_ebuild), |
174 |
+ working_tree=True) |
175 |
+ if pkg_data[category][channel]["stable"]: |
176 |
+ if args.dry_run: |
177 |
+ print(f"ekeyword amd64 {to_ebuild}") |
178 |
+ else: |
179 |
+ subprocess.run(["ekeyword", "amd64", |
180 |
+ os.path.join(repo_path, to_ebuild)]) |
181 |
+ |
182 |
+ if args.dry_run: |
183 |
+ print(f"git add {to_ebuild}") |
184 |
else: |
185 |
- index.remove(from_ebuild, working_tree=True) |
186 |
+ to_ebuild = os.path.join(repo_path, to_ebuild) |
187 |
+ index.add(to_ebuild) |
188 |
|
189 |
to_path = os.path.dirname(to_ebuild) |
190 |
cfg = config.config() |
191 |
cfg["O"] = to_path |
192 |
|
193 |
- digestgen.digestgen(None, cfg, db) |
194 |
+ if args.dry_run: |
195 |
+ print(f"git add {os.path.join(to_path, 'Manifest')}") |
196 |
+ print("git commit -m", |
197 |
+ f"\"{category}/{pkg}: automated update", |
198 |
+ f"({uversion}{suffix})", |
199 |
+ "-s -S\"") |
200 |
+ else: |
201 |
+ digestgen.digestgen(None, cfg, db) |
202 |
|
203 |
- index.add(os.path.join(to_path, "Manifest")) |
204 |
+ index.add(os.path.join(to_path, "Manifest")) |
205 |
|
206 |
- repo.git.commit("-m", |
207 |
- f"{category}/{pkg}: automated update ({uversion})", |
208 |
- "-s", "-S") |
209 |
+ repo.git.commit("-m", |
210 |
+ f"{category}/{pkg}: automated update ({uversion}{suffix})", |
211 |
+ "-s", "-S") |
212 |
|
213 |
if __name__ == "__main__": |
214 |
main() |