]>
Commit | Line | Data |
---|---|---|
339bd66f JAG |
1 | #!/usr/bin/python3 |
2 | # | |
3 | # 2021 Jafar Al-Gharaibeh, ATCorp | |
4 | # | |
5 | # Generate a draft FRR release notes | |
6 | # | |
7 | ||
8 | import sys | |
9 | import os | |
10 | import getopt | |
11 | import subprocess | |
12 | ||
19888540 | 13 | |
339bd66f JAG |
14 | def run(cmd): |
15 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) | |
16 | rv = proc.communicate("")[0].decode("UTF-8") | |
17 | proc.wait() | |
18 | return rv | |
19 | ||
20 | ||
21 | def usage(n): | |
22 | print(os.path.basename(__file__), " [-b <branch>] [-t <tag> ]") | |
23 | print(" Generate one line logs for non merge commits") | |
24 | print(" -branch: branch name to use, default to HEAD") | |
25 | print(" -tag : generate logs up to this tag, default to latest tag") | |
26 | sys.exit(n) | |
27 | ||
28 | ||
29 | def main(argv): | |
30 | branch = tag = None | |
31 | try: | |
32 | opts, args = getopt.getopt(argv, "hb:t:", ["branch=", "tag="]) | |
33 | except getopt.GetoptError: | |
34 | usage(2) | |
35 | for opt, arg in opts: | |
36 | if opt == "-h": | |
37 | usage(0) | |
38 | elif opt in ("-b", "--branch"): | |
39 | branch = arg | |
40 | elif opt in ("-t", "--tag"): | |
41 | tag = arg | |
42 | ||
43 | if branch is None: | |
44 | branch = "HEAD" | |
45 | if tag is None: | |
46 | tag = run(["git", "describe", "--abbrev=0"]).strip("\n") | |
47 | ||
48 | chnglog = run( | |
19888540 | 49 | ["git", "log", "--no-merges", "--pretty=format:'%s'", tag + ".." + branch] |
339bd66f JAG |
50 | ) |
51 | chnglog = chnglog.split("\n") | |
52 | ||
53 | chnglist = [] | |
54 | daemons = [ | |
55 | "babel", | |
56 | "bgp", | |
57 | "eigrp", | |
58 | "nhrp", | |
59 | "ospf", | |
60 | "ospf6", | |
61 | "pbr", | |
62 | "pim", | |
63 | "rip", | |
64 | "ripng", | |
65 | "sharp", | |
66 | "vrrp", | |
67 | "zebra", | |
68 | ] | |
69 | ||
70 | for line in chnglog: | |
71 | line = line.strip("'") | |
72 | colon = line.partition(":") | |
73 | label = colon[0].strip().lower() | |
74 | if label in daemons: | |
75 | label = label + "d" | |
76 | comment = colon[2].strip().capitalize() | |
77 | chnglist.append(label + ":" + comment) | |
78 | ||
79 | chnglist.sort() | |
80 | lastlabel = "" | |
81 | for line in chnglist: | |
82 | colon = line.partition(":") | |
83 | label = colon[0] | |
84 | comment = colon[2] | |
85 | if label != lastlabel: | |
86 | print("") | |
87 | print(label) | |
88 | lastlabel = label | |
89 | ||
90 | print(" ", comment) | |
91 | ||
92 | ||
93 | if __name__ == "__main__": | |
94 | main(sys.argv[1:]) |