2019-10-18 18:57:46 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2022-03-12 00:13:17 +00:00
|
|
|
# update-appdata.py - Update the <releases/> section of resources/freedesktop/org.wireshark.Wireshark.metainfo.xml.
|
2019-10-18 18:57:46 +00:00
|
|
|
#
|
|
|
|
# Wireshark - Network traffic analyzer
|
|
|
|
# By Gerald Combs <gerald@wireshark.org>
|
|
|
|
# Copyright 1998 Gerald Combs
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2022-03-12 00:13:17 +00:00
|
|
|
'''Update the <release> tag in resources/freedesktop/org.wireshark.Wireshark.metainfo.xml
|
2019-10-18 18:57:46 +00:00
|
|
|
|
|
|
|
According to https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html
|
2022-03-12 00:13:17 +00:00
|
|
|
the <releases/> tag in resources/freedesktop/org.wireshark.Wireshark.metainfo.xml should contain release
|
2019-10-18 18:57:46 +00:00
|
|
|
information sorted newest to oldest.
|
|
|
|
|
|
|
|
As part of our release process, when we create release tag x.y.z, we tag
|
|
|
|
the next commit x.y.z+1rc0, e.g.
|
|
|
|
|
|
|
|
v3.0.0 2019-02-28 release tag
|
|
|
|
v3.0.1rc0 2019-02-28 next commit after v3.0.0
|
|
|
|
v3.0.1 2019-04-08 release tag
|
|
|
|
v3.0.2rc0 2019-04-08 next commit after v3.0.1
|
|
|
|
|
|
|
|
Find a list of release versions based on our most recent rc0 tag and
|
2022-03-12 00:13:17 +00:00
|
|
|
update the <releases/> section of resources/freedesktop/org.wireshark.Wireshark.metainfo.xml accordingly.
|
2019-10-18 18:57:46 +00:00
|
|
|
Assume that the tag for the most recent release doesn't exist and use
|
|
|
|
today's date for it.
|
|
|
|
'''
|
|
|
|
|
|
|
|
from datetime import date
|
|
|
|
import io
|
|
|
|
import os.path
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
def main():
|
|
|
|
this_dir = os.path.dirname(__file__)
|
2022-03-12 00:13:17 +00:00
|
|
|
appdata_xml = os.path.join(this_dir, '..', 'resources', 'freedesktop', 'org.wireshark.Wireshark.metainfo.xml')
|
2019-10-18 18:57:46 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
cur_rc0 = subprocess.run(
|
|
|
|
['git', 'describe', '--match', 'v*rc0'],
|
|
|
|
check=True,
|
|
|
|
encoding='UTF-8',
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout
|
Fix issues discovered by common python linters
Fix some issues discovered by common python linters including:
* switch `None` comparisons to use `is` rather than `==`. Identity !=
equality, and I've spent 40+ hours before tracking down a subtle bug
caused by exactly this issue. Note that this may introduce a problem if
one of the scripts is depending on this behavior, in which case the
comparison should be changed to `True`/`False` rather than `None`.
* Use `except Exception:` as bare `except:` statements have been
discouraged for years. Ideally for some of these we'd examine if there
were specific exceptions that should be caught, but for now I simply
caught all. Again, this could introduce very subtle behavioral changes
under Python 2, but IIUC, that was all fixed in Python 3, so safe to
move to `except Exception:`.
* Use more idiomatic `if not x in y`--> `if x not in y`
* Use more idiomatic 2 blank lines. I only did this at the beginning,
until I realized how overwhelming this was going to be to apply, then I
stopped.
* Add a TODO where an undefined function name is called, so will fail
whenever that code is run.
* Add more idiomatic spacing around `:`. This is also only partially
cleaned up, as I gave up when I saw how `asn2wrs.py` was clearly
infatuated with the construct.
* Various other small cleanups, removed some trailing whitespace and
improper indentation that wasn't a multiple of 4, etc.
There is still _much_ to do, but I haven't been heavily involved with
this project before, so thought this was a sufficient amount to put up
and see what the feedback is.
Linters that I have enabled which highlighted some of these issues
include:
* `pylint`
* `flake8`
* `pycodestyle`
2020-09-21 05:44:41 +00:00
|
|
|
except Exception:
|
2019-10-18 18:57:46 +00:00
|
|
|
print('Unable to fetch most recent rc0.')
|
|
|
|
raise
|
|
|
|
|
|
|
|
try:
|
|
|
|
ver_m = re.match('v(\d+\.\d+)\.(\d+)rc0.*', cur_rc0)
|
|
|
|
maj_min = ver_m.group(1)
|
|
|
|
next_micro = ver_m.group(2)
|
Fix issues discovered by common python linters
Fix some issues discovered by common python linters including:
* switch `None` comparisons to use `is` rather than `==`. Identity !=
equality, and I've spent 40+ hours before tracking down a subtle bug
caused by exactly this issue. Note that this may introduce a problem if
one of the scripts is depending on this behavior, in which case the
comparison should be changed to `True`/`False` rather than `None`.
* Use `except Exception:` as bare `except:` statements have been
discouraged for years. Ideally for some of these we'd examine if there
were specific exceptions that should be caught, but for now I simply
caught all. Again, this could introduce very subtle behavioral changes
under Python 2, but IIUC, that was all fixed in Python 3, so safe to
move to `except Exception:`.
* Use more idiomatic `if not x in y`--> `if x not in y`
* Use more idiomatic 2 blank lines. I only did this at the beginning,
until I realized how overwhelming this was going to be to apply, then I
stopped.
* Add a TODO where an undefined function name is called, so will fail
whenever that code is run.
* Add more idiomatic spacing around `:`. This is also only partially
cleaned up, as I gave up when I saw how `asn2wrs.py` was clearly
infatuated with the construct.
* Various other small cleanups, removed some trailing whitespace and
improper indentation that wasn't a multiple of 4, etc.
There is still _much_ to do, but I haven't been heavily involved with
this project before, so thought this was a sufficient amount to put up
and see what the feedback is.
Linters that I have enabled which highlighted some of these issues
include:
* `pylint`
* `flake8`
* `pycodestyle`
2020-09-21 05:44:41 +00:00
|
|
|
except Exception:
|
2019-10-18 18:57:46 +00:00
|
|
|
print('Unable to fetch major.minor version.')
|
|
|
|
raise
|
|
|
|
|
|
|
|
# https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-releases
|
|
|
|
release_tag_fmt = '''\
|
|
|
|
<release version="{0}.{1}" date="{2}">
|
|
|
|
<url>https://www.wireshark.org/docs/relnotes/wireshark-{0}.{1}.html</url>
|
|
|
|
</release>
|
|
|
|
'''
|
2023-10-08 00:49:52 +00:00
|
|
|
cur_date = date.fromtimestamp(time.time()).isoformat()
|
2019-10-18 18:57:46 +00:00
|
|
|
release_tag_l = [
|
2023-10-06 20:48:51 +00:00
|
|
|
f' <!-- Automatically generated by tools/{os.path.basename(__file__)} -->\n',
|
2023-10-08 00:49:52 +00:00
|
|
|
release_tag_fmt.format(maj_min, next_micro, cur_date)
|
2019-10-18 18:57:46 +00:00
|
|
|
]
|
2023-10-08 00:49:52 +00:00
|
|
|
print(f'Added {maj_min}.{next_micro}, {cur_date}')
|
|
|
|
|
2019-10-18 18:57:46 +00:00
|
|
|
for micro in range(int(next_micro) - 1, -1, -1):
|
|
|
|
try:
|
|
|
|
tag_date = subprocess.run(
|
|
|
|
['git', 'log', '-1', '--format=%cd', '--date=format:%F', 'v{}.{}'.format(maj_min, micro)],
|
|
|
|
check=True,
|
|
|
|
encoding='UTF-8',
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.strip()
|
|
|
|
release_tag_l.append(release_tag_fmt.format(maj_min, micro, tag_date))
|
2023-10-08 00:49:52 +00:00
|
|
|
print(f'Added {maj_min}.{micro}, {tag_date}')
|
Fix issues discovered by common python linters
Fix some issues discovered by common python linters including:
* switch `None` comparisons to use `is` rather than `==`. Identity !=
equality, and I've spent 40+ hours before tracking down a subtle bug
caused by exactly this issue. Note that this may introduce a problem if
one of the scripts is depending on this behavior, in which case the
comparison should be changed to `True`/`False` rather than `None`.
* Use `except Exception:` as bare `except:` statements have been
discouraged for years. Ideally for some of these we'd examine if there
were specific exceptions that should be caught, but for now I simply
caught all. Again, this could introduce very subtle behavioral changes
under Python 2, but IIUC, that was all fixed in Python 3, so safe to
move to `except Exception:`.
* Use more idiomatic `if not x in y`--> `if x not in y`
* Use more idiomatic 2 blank lines. I only did this at the beginning,
until I realized how overwhelming this was going to be to apply, then I
stopped.
* Add a TODO where an undefined function name is called, so will fail
whenever that code is run.
* Add more idiomatic spacing around `:`. This is also only partially
cleaned up, as I gave up when I saw how `asn2wrs.py` was clearly
infatuated with the construct.
* Various other small cleanups, removed some trailing whitespace and
improper indentation that wasn't a multiple of 4, etc.
There is still _much_ to do, but I haven't been heavily involved with
this project before, so thought this was a sufficient amount to put up
and see what the feedback is.
Linters that I have enabled which highlighted some of these issues
include:
* `pylint`
* `flake8`
* `pycodestyle`
2020-09-21 05:44:41 +00:00
|
|
|
except Exception:
|
2019-10-18 18:57:46 +00:00
|
|
|
print('Unable to fetch release tag')
|
|
|
|
raise
|
|
|
|
|
|
|
|
ax_lines = []
|
|
|
|
with io.open(appdata_xml, 'r', encoding='UTF-8') as ax_fd:
|
|
|
|
in_releases = False
|
|
|
|
for line in ax_fd:
|
|
|
|
if '</releases>' in line:
|
|
|
|
in_releases = False
|
|
|
|
if in_releases:
|
|
|
|
continue
|
|
|
|
ax_lines.append(line)
|
|
|
|
if '<releases>' in line:
|
|
|
|
in_releases = True
|
|
|
|
ax_lines.extend(release_tag_l)
|
|
|
|
|
|
|
|
with io.open(appdata_xml, 'w', encoding='UTF-8') as ax_fd:
|
|
|
|
ax_fd.write(''.join(ax_lines))
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|