update changelog collection script to cope with multiple flavours, while here, also swich to python3

pull/308/head
Ad Schellevis 3 years ago
parent 9edba62645
commit ea214e1ab0

@ -1,6 +1,6 @@
#!/usr/local/bin/python #!/usr/local/bin/python3
""" """
Copyright (c) 2020 Ad Schellevis <ad@opnsense.org> Copyright (c) 2020-2021 Ad Schellevis <ad@opnsense.org>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -31,6 +31,7 @@ import requests
import zipfile import zipfile
import collections import collections
import re import re
import pathlib
from packaging import version from packaging import version
from jinja2 import Template from jinja2 import Template
@ -120,42 +121,65 @@ if __name__ == '__main__':
download_zip(changelog_zip) download_zip(changelog_zip)
if os.path.isfile(changelog_zip): if os.path.isfile(changelog_zip):
template_data = { version_metadata = {
'major_versions': collections.OrderedDict(), 'community': {
'versions': collections.OrderedDict(), 'prefix': 'CE',
'nicknames': collections.OrderedDict(), 'name': 'Community Edition'
},
'business': {
'prefix': 'BE',
'name': 'Business Edition'
}
} }
all_versions = dict() all_versions = {'community': dict(), 'business': dict()}
# read all changelogs (from zip) # read all changelogs (from zip)
this_dir = str(pathlib.Path(".").resolve())
with zipfile.ZipFile(changelog_zip, mode='r', compression=zipfile.ZIP_DEFLATED) as zf: with zipfile.ZipFile(changelog_zip, mode='r', compression=zipfile.ZIP_DEFLATED) as zf:
for item in zf.infolist(): for item in zf.infolist():
fparts = item.filename.split('/') fparts = item.filename.split('/')
if len(fparts) > 3 and fparts[1] == 'doc' and item.file_size > 0: if len(fparts) > 3 and fparts[1] in all_versions and item.file_size > 0:
all_versions[fparts[3]] = zf.open(item).read().decode() all_versions[fparts[1]][fparts[3]] = zf.open(item).read().decode()
if len(fparts) == 3 and fparts[1] in all_versions and not item.is_dir():
for my_version in sorted(all_versions, key=lambda x: version.Version(x.replace('.r','rc')), reverse=True): # resolve links
major_version = ".".join(my_version.split('.')[:2]) tmp = pathlib.Path("%s/%s" % (os.path.dirname(item.filename), zf.open(item).read().decode()))
if major_version not in template_data['major_versions']: link_to = str(tmp.resolve()).replace(this_dir, '')[1:]
template_data['major_versions'][major_version] = dict() for item2 in zf.infolist():
template_data['versions'][my_version] = parse_change_log(all_versions[my_version], my_version) if item2.filename.startswith(link_to) and not item2.is_dir():
all_versions[fparts[1]][os.path.basename(item2.filename)] = zf.open(item2).read().decode()
if major_version == my_version:
template_data['nicknames'][my_version] = "" for flavour in all_versions:
tmp = all_versions[my_version].replace('\n', ' ') version_prefix = version_metadata[flavour]['prefix']
m = re.match(r'.*nicknamed ["\'](?P<nickname>[^"\']+)', tmp) template_data = {
if m: 'major_versions': collections.OrderedDict(),
template_data['nicknames'][my_version] = m.groupdict()['nickname'] 'versions': collections.OrderedDict(),
'nicknames': collections.OrderedDict(),
# root menu index 'flavour': flavour
with open("%s/source/releases.rst" % root_dir, 'w') as f_out: }
template = Template(open("%s/source/releases.rst.in" % root_dir, "r").read()) template_data.update(version_metadata[flavour])
f_out.write(template.render(template_data)) versions = all_versions[flavour]
for my_version in sorted(versions, key=lambda x: version.Version(x.replace('.r','rc')), reverse=True):
# per version rst file major_version = ".".join(my_version.split('.')[:2])
template = Template(open("%s/source/releases/default.rst.in" % root_dir, "r").read()) if major_version not in template_data['major_versions']:
for major_version in template_data['major_versions']: template_data['major_versions'][major_version] = dict()
if major_version in template_data['versions']: template_data['versions'][my_version] = parse_change_log(versions[my_version], my_version)
# wait for the main version before writing a changelog
with open("%s/source/releases/%s.rst" % (root_dir, major_version), 'w') as f_out: if major_version == my_version:
template_data['this_version'] = major_version template_data['nicknames'][my_version] = ""
f_out.write(template.render(template_data)) tmp = versions[my_version].replace('\n', ' ')
m = re.match(r'.*nicknamed ["\'](?P<nickname>[^"\']+)', tmp)
if m:
template_data['nicknames'][my_version] = m.groupdict()['nickname']
# root menu index
with open("%s/source/%s_releases.rst" % (root_dir, version_prefix), 'w') as f_out:
template = Template(open("%s/source/releases.rst.in" % root_dir, "r").read())
f_out.write(template.render(template_data))
# per version rst file
template = Template(open("%s/source/releases/default.rst.in" % root_dir, "r").read())
for major_version in template_data['major_versions']:
if major_version in template_data['versions']:
# wait for the main version before writing a changelog
with open("%s/source/releases/%s_%s.rst" % (root_dir, version_prefix, major_version), 'w') as f_out:
template_data['this_version'] = major_version
f_out.write(template.render(template_data))

@ -1,7 +1,9 @@
==================================== ====================================
Releases {{name}}
==================================== ====================================
{% if prefix == 'CE' %}
.. image:: /development/images/ideas_join_the_development.jpg .. image:: /development/images/ideas_join_the_development.jpg
:width: 600px :width: 600px
:align: center :align: center
@ -9,6 +11,18 @@ Releases
As of January 2015 there have been *{{ versions|length }}* releases leading to the latest version *{{ versions|first }}* As of January 2015 there have been *{{ versions|length }}* releases leading to the latest version *{{ versions|first }}*
named "{{nicknames.items()|list|first|last}}". named "{{nicknames.items()|list|first|last}}".
{% elif prefix == 'BE' %}
.. image:: images/architecture-blue-sky-business-2599538.jpg
:width: 600px
:align: center
OPNsense Business Edition is intended for companies, enterprises and professionals looking for a more
selective upgrade path (lags behind the community edition), additional commercial features and who want to
support the project in a more commercial way compared to donating.
{% endif %}
The list below contains all releases, ordered by version number categorized by major version. The list below contains all releases, ordered by version number categorized by major version.
.. toctree:: .. toctree::
@ -17,6 +31,6 @@ The list below contains all releases, ordered by version number categorized by m
:glob: :glob:
{% for major_version in major_versions%} {% for major_version in major_versions%}
{%- if major_version in versions %} {%- if major_version in versions %}
releases/{{major_version}} releases/{{prefix}}_{{major_version}}
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}

Loading…
Cancel
Save