-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcranky-0
More file actions
executable file
·338 lines (253 loc) · 9.1 KB
/
Copy pathcranky-0
File metadata and controls
executable file
·338 lines (253 loc) · 9.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/usr/bin/env python3
import os
import sys
from subprocess import CalledProcessError, check_call
import click
from debian.changelog import Changelog
CRANKY = os.getenv("CRANKY", "cranky")
COLS = int(os.popen("tput cols", "r").read().strip())
def source_debian_env():
with open("debian/debian.env", encoding="utf-8") as fh:
for line in fh:
if line.startswith("DEBIAN="):
return line.strip().split("=")[1]
return None
def parse_changelog(changelog=None, offset=0):
if not changelog:
changelog = f"{source_debian_env()}/changelog"
with open(changelog, encoding="utf-8") as fh:
return Changelog(fh)[offset]
def print_banner(cmd, invert=True, color=9):
txt = " ".join(cmd) + " " * COLS
x = 48 if invert else 38
print(f"\033[{x};5;{color}m{txt[:COLS]}\033[0m")
def run(cmd, shell=False):
print()
print_banner(cmd)
try:
if cmd[0] == "cranky":
print_banner([os.popen("which cranky", "r").read().strip()], invert=False)
if shell:
check_call(" ".join(cmd), bufsize=0, shell=True)
else:
check_call(cmd, bufsize=0)
except CalledProcessError as e:
print("Error: " + str(e))
sys.exit(1)
def debian_version(git_obj):
line = os.popen(f"git show {git_obj} | head -1", "r").read()
return line.split("(")[1].split(")")[0]
@click.group()
def main():
pass
@main.command()
def fix():
series = parse_changelog().distributions
if series == "UNRELEASED":
print(f"Invalid series: {series}", file=sys.stderr)
sys.exit(1)
run([CRANKY, "fix"])
@main.command()
@click.option("--dry-run", is_flag=True)
@click.argument("tag")
@click.argument("tag2", nargs=-1)
def rebase(dry_run, tag, tag2):
opts = []
if dry_run:
opts += ["--dry-run"]
run(["cranky-rebase", "--tag", tag] + opts)
ch = parse_changelog()
if ch.package == "linux-raspi-realtime" and os.path.exists("debian.realtime"):
run(["cranky-update-tree"] + opts + ["--strategy", "cherry-pick", "realtime", tag2[0]])
@main.command(name="open")
@click.option("--dry-run", is_flag=True)
def open_(dry_run):
opts = []
if dry_run:
opts += ["--dry-run"]
series = parse_changelog().distributions
if series == "UNRELEASED":
print(f"Invalid series: {series}", file=sys.stderr)
sys.exit(1)
run([CRANKY, "open"] + opts)
@main.command()
def configs():
run([CRANKY, "updateconfigs"])
@main.command()
@click.option("--dry-run", is_flag=True)
@click.option("--re-run", is_flag=True)
@click.option("--cycle", required=True, help="SRU cycle name.")
def link(dry_run, re_run, cycle):
opts = []
if dry_run:
opts += ["--dry-run"]
if re_run:
opts += ["--re-run"]
run([CRANKY, "link-tb", "--sru-cycle", cycle] + opts)
@main.command()
def dkms():
if os.path.exists("update-dkms-versions"):
print("Error: ./update-dkms-versions exists. This is unexpected!")
sys.exit(1)
run([CRANKY, "update-dkms-versions"])
@main.command(name="close")
@click.option("--force", is_flag=True)
def close_(force):
series = parse_changelog().distributions
if series != "UNRELEASED":
print(f"Invalid series: {series}", file=sys.stderr)
sys.exit(1)
opts = []
if force:
opts += ["--force"]
run([CRANKY, "close"])
if parse_changelog().package == "linux-raspi-realtime" and os.path.exists("debian.realtime"):
print()
print("*** FIXME ***")
print()
# Reset HEAD
run(["git", "reset", "--hard", "HEAD~1"])
cl = "debian.raspi-realtime/changelog"
# Previous release version and tag
raspi_realtime_version = str(parse_changelog("debian.raspi-realtime/changelog", offset=1).version)
raspi_realtime_tag = f"Ubuntu-raspi-realtime-{raspi_realtime_version}"
#
# raspi
#
version = debian_version(f"{raspi_realtime_tag}:debian.raspi/changelog")
run([CRANKY, "update-changelog", "--changelog", cl,
"--from-version", version,
"--from-changelog", "debian.raspi/changelog"])
#
# realtime
#
version = debian_version(f"{raspi_realtime_tag}:debian.realtime/changelog")
from_commit = os.popen("git log --format='%h __%s__' |" +
f"grep -m1 -F '__UBUNTU: Ubuntu-realtime-{version}__' | sed 's/ .*//'",
"r").read().strip()
version = str(parse_changelog("debian.realtime/changelog").version)
to_commit = os.popen("git log --format='%h __%s__' |" +
f"grep -m1 -F '__UBUNTU: Ubuntu-realtime-{version}__' | sed 's/ .*//'",
"r").read().strip()
run([CRANKY, "update-changelog", "--changelog", cl,
"--commit-range", f"{from_commit}..{to_commit}"])
#
# raspi-realtime
#
from_commit = os.popen("git log --format='%h __%s__' |" +
f"grep -m1 -F '__UBUNTU: {raspi_realtime_tag}__' | sed 's/ .*//'",
"r").read().strip()
run([CRANKY, "update-changelog", "--changelog", cl,
"--from-commit", from_commit])
# Commit
series = parse_changelog(cl, offset=1).distributions
version = str(parse_changelog(cl).version)
run(["git", "add", cl])
run(["dch", "--nomultimaint", "-c", cl, "-r", "-D", series, ""])
run(["git", "commit", "-sam", f"UBUNTU: Ubuntu-raspi-realtime-{version}"])
run([CRANKY, "tag"] + opts)
@main.command()
def dependents():
run(["cranky-update-dependents", "-f"])
@main.command()
def verify():
run(["cranky-verify-release-ready"])
@main.command()
@click.option("--no-orig", is_flag=True)
@click.option("--orig", is_flag=True)
@click.argument("pocket_offset_abi")
def build(pocket_offset_abi, no_orig, orig):
cmd = ["cranky-build-sources", "--force"]
if no_orig:
cmd.append("--no-orig")
if orig:
cmd.append("--orig")
cmd.append(pocket_offset_abi)
run(cmd)
@main.command()
@click.argument("pocket_offset_abi")
def review(pocket_offset_abi):
run(["cranky-review-sources", pocket_offset_abi])
run(["cranky-reduce-debdiff"])
run(["cranky-review-sources", "|", "less"], shell=True)
run(["review-debdiff", "-r", "|", "less"], shell=True)
@main.command()
def push():
run(["cranky-push-all", "--dry-run"])
val = ""
while val != "y":
val = input("Push (y|n)? ")
run(["cranky-push-all"])
@main.command()
@click.argument("ppa")
def dput(ppa):
run([CRANKY, "dput-sources", ppa])
@main.command()
@click.option("--dry-run", is_flag=True)
def checkout(dry_run):
opts = []
if dry_run:
opts += ["--dry-run"]
run(["cranky-checkout"] + opts)
@main.command(context_settings=dict(ignore_unknown_options=True,))
@click.argument("cbd_args", nargs=-1, type=click.UNPROCESSED)
def cbd(cbd_args):
run(["cbd-cli", "-n", "build"] + list(cbd_args))
# ---------------------------------------------------------------------------------------------------
@main.command(name="1--checkout")
@click.option("--dry-run", is_flag=True)
@click.pass_context
def x1(ctx, dry_run):
ctx.invoke(checkout, dry_run=dry_run)
@main.command(name="2--fix-rebase-fix-open")
@click.option("--dry-run", is_flag=True)
@click.argument("tag")
@click.argument("tag2", nargs=-1)
@click.pass_context
def x2(ctx, dry_run, tag, tag2):
ctx.invoke(fix)
ctx.invoke(rebase, dry_run=dry_run, tag=tag, tag2=tag2)
ctx.invoke(fix)
ctx.invoke(open_, dry_run=dry_run)
@main.command(name="3--configs")
@click.pass_context
def x3(ctx):
ctx.invoke(configs)
@main.command(name="4--link-dkms-close-dependents-verify")
@click.option("--dry-run", is_flag=True)
@click.option("--re-run", is_flag=True)
@click.option("--cycle", required=True, help="SRU cycle name.")
@click.option("--force", is_flag=True)
@click.pass_context
def x4(ctx, dry_run, re_run, cycle, force):
ctx.invoke(link, dry_run=dry_run, re_run=re_run, cycle=cycle)
ctx.invoke(dkms)
ctx.invoke(close_, force=force)
ctx.invoke(dependents)
ctx.invoke(verify)
@main.command(name="5--build-review")
@click.option("--no-orig", is_flag=True)
@click.option("--orig", is_flag=True)
@click.argument("pocket_offset_abi")
@click.pass_context
def x5(ctx, pocket_offset_abi, no_orig, orig):
ctx.invoke(build, pocket_offset_abi=pocket_offset_abi, no_orig=no_orig, orig=orig)
ctx.invoke(review, pocket_offset_abi=pocket_offset_abi)
@main.command(name="6--cbd",
context_settings=dict(ignore_unknown_options=True,))
@click.argument("cbd_args", nargs=-1, type=click.UNPROCESSED)
@click.pass_context
def x6(ctx, cbd_args):
ctx.invoke(cbd, cbd_args=cbd_args)
@main.command(name="7--push-dput")
@click.argument("ppa")
@click.pass_context
def x7(ctx, ppa):
ctx.invoke(push)
ctx.invoke(dput, ppa=ppa)
if __name__ == "__main__":
if "--" in sys.argv[0]:
subcmd = os.path.basename(sys.argv[0]).removeprefix("cranky-")
sys.argv[0] = sys.argv[0].removesuffix(f"-{subcmd}")
sys.argv.insert(1, subcmd)
main()