-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrename-bugs.py
More file actions
executable file
·59 lines (48 loc) · 1.89 KB
/
Copy pathrename-bugs.py
File metadata and controls
executable file
·59 lines (48 loc) · 1.89 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
#!/usr/bin/env python
import argparse
import os.path
import re
import bugzilla
from rich.console import Console
from rich.theme import Theme
def main():
argp = argparse.ArgumentParser()
argp.add_argument("-p", "--pretend",
action="store_true",
help="Print summary changes without applying them")
argp.add_argument("old",
help="String to replace (old package name)")
argp.add_argument("new",
help="New value (new package name)")
args = argp.parse_args()
token_file = os.path.expanduser('~/.bugz_token')
try:
with open(token_file, 'r') as f:
token = f.read().strip()
except FileNotFoundError:
argp.error("Put bugzilla API key into ~/.bugz_token")
bz = bugzilla.Bugzilla("https://bugs.gentoo.org", api_key=token)
console = Console(highlight=False,
theme=Theme({"bugno": "bright_cyan",
"old": "bright_red",
"new": "bright_green",
}))
search = bz.build_query(short_desc=args.old,
status=["UNCONFIRMED", "CONFIRMED", "IN_PROGRESS"])
for bug in bz.query(search):
pkg_re = re.compile(
f"(^|[^\\w+_-])({args.old})(?!([\\w+_]|-[a-zA-Z]))")
new_summary = pkg_re.sub(f"\\1{args.new}", bug.summary)
if new_summary == bug.summary:
continue
console.print(
f"[bugno]#{bug.id}[/bugno] - "
f"{pkg_re.sub(r'\1[old]\2[/old]', bug.summary)}")
console.print(
f"{' ' * len(str(bug.id))} + "
f"{pkg_re.sub(f'\\1[new]{args.new}[/new]', bug.summary)}")
if not args.pretend:
update = bz.build_update(summary=new_summary)
bz.update_bugs([bug.id], update)
if __name__ == "__main__":
main()