TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / tools / update-appdata.py
blob4b8ee7da872c55cb40590af58487c7d9710a501c
1 #!/usr/bin/env python3
3 # update-appdata.py - Update the <releases/> section of resources/freedesktop/org.wireshark.Wireshark.metainfo.xml.
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 1998 Gerald Combs
9 # SPDX-License-Identifier: GPL-2.0-or-later
10 '''Update the <release> tag in resources/freedesktop/org.wireshark.Wireshark.metainfo.xml
12 According to https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html
13 the <releases/> tag in resources/freedesktop/org.wireshark.Wireshark.metainfo.xml should contain release
14 information sorted newest to oldest.
16 As part of our release process, when we create release tag x.y.z, we tag
17 the next commit x.y.z+1rc0, e.g.
19 v3.0.0 2019-02-28 release tag
20 v3.0.1rc0 2019-02-28 next commit after v3.0.0
21 v3.0.1 2019-04-08 release tag
22 v3.0.2rc0 2019-04-08 next commit after v3.0.1
24 Find a list of release versions based on our most recent rc0 tag and
25 update the <releases/> section of resources/freedesktop/org.wireshark.Wireshark.metainfo.xml accordingly.
26 Assume that the tag for the most recent release doesn't exist and use
27 today's date for it.
28 '''
30 from datetime import date
31 import io
32 import os.path
33 import re
34 import subprocess
35 import time
37 def main():
38 this_dir = os.path.dirname(__file__)
39 appdata_xml = os.path.join(this_dir, '..', 'resources', 'freedesktop', 'org.wireshark.Wireshark.metainfo.xml')
41 try:
42 cur_rc0 = subprocess.run(
43 ['git', 'describe', '--match', 'v*rc0'],
44 check=True,
45 encoding='UTF-8',
46 stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout
47 except Exception:
48 print('Unable to fetch most recent rc0.')
49 raise
51 try:
52 ver_m = re.match('v(\d+\.\d+)\.(\d+)rc0.*', cur_rc0)
53 maj_min = ver_m.group(1)
54 next_micro = ver_m.group(2)
55 except Exception:
56 print('Unable to fetch major.minor version.')
57 raise
59 # https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-releases
60 release_tag_fmt = '''\
61 <release version="{0}.{1}" date="{2}">
62 <url>https://www.wireshark.org/docs/relnotes/wireshark-{0}.{1}.html</url>
63 </release>
64 '''
65 cur_date = date.fromtimestamp(time.time()).isoformat()
66 release_tag_l = [
67 f' <!-- Automatically generated by tools/{os.path.basename(__file__)} -->\n',
68 release_tag_fmt.format(maj_min, next_micro, cur_date)
70 print(f'Added {maj_min}.{next_micro}, {cur_date}')
72 for micro in range(int(next_micro) - 1, -1, -1):
73 try:
74 tag_date = subprocess.run(
75 ['git', 'log', '-1', '--format=%cd', '--date=format:%F', 'v{}.{}'.format(maj_min, micro)],
76 check=True,
77 encoding='UTF-8',
78 stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.strip()
79 release_tag_l.append(release_tag_fmt.format(maj_min, micro, tag_date))
80 print(f'Added {maj_min}.{micro}, {tag_date}')
81 except Exception:
82 print('Unable to fetch release tag')
83 raise
85 ax_lines = []
86 with io.open(appdata_xml, 'r', encoding='UTF-8') as ax_fd:
87 in_releases = False
88 for line in ax_fd:
89 if '</releases>' in line:
90 in_releases = False
91 if in_releases:
92 continue
93 ax_lines.append(line)
94 if '<releases>' in line:
95 in_releases = True
96 ax_lines.extend(release_tag_l)
98 with io.open(appdata_xml, 'w', encoding='UTF-8') as ax_fd:
99 ax_fd.write(''.join(ax_lines))
101 if __name__ == '__main__':
102 main()