mirror of
https://github.com/opnsense/docs.git
synced 2025-12-15 13:41:32 -06:00
update changelog collection script to cope with multiple flavours, while here, also swich to python3
This commit is contained in:
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.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@ -31,6 +31,7 @@ import requests
|
||||
import zipfile
|
||||
import collections
|
||||
import re
|
||||
import pathlib
|
||||
from packaging import version
|
||||
from jinja2 import Template
|
||||
|
||||
@ -120,42 +121,65 @@ if __name__ == '__main__':
|
||||
download_zip(changelog_zip)
|
||||
|
||||
if os.path.isfile(changelog_zip):
|
||||
template_data = {
|
||||
'major_versions': collections.OrderedDict(),
|
||||
'versions': collections.OrderedDict(),
|
||||
'nicknames': collections.OrderedDict(),
|
||||
version_metadata = {
|
||||
'community': {
|
||||
'prefix': 'CE',
|
||||
'name': 'Community Edition'
|
||||
},
|
||||
'business': {
|
||||
'prefix': 'BE',
|
||||
'name': 'Business Edition'
|
||||
}
|
||||
}
|
||||
all_versions = dict()
|
||||
all_versions = {'community': dict(), 'business': dict()}
|
||||
# read all changelogs (from zip)
|
||||
this_dir = str(pathlib.Path(".").resolve())
|
||||
with zipfile.ZipFile(changelog_zip, mode='r', compression=zipfile.ZIP_DEFLATED) as zf:
|
||||
for item in zf.infolist():
|
||||
fparts = item.filename.split('/')
|
||||
if len(fparts) > 3 and fparts[1] == 'doc' and item.file_size > 0:
|
||||
all_versions[fparts[3]] = zf.open(item).read().decode()
|
||||
if len(fparts) > 3 and fparts[1] in all_versions and item.file_size > 0:
|
||||
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():
|
||||
# resolve links
|
||||
tmp = pathlib.Path("%s/%s" % (os.path.dirname(item.filename), zf.open(item).read().decode()))
|
||||
link_to = str(tmp.resolve()).replace(this_dir, '')[1:]
|
||||
for item2 in zf.infolist():
|
||||
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()
|
||||
|
||||
for my_version in sorted(all_versions, key=lambda x: version.Version(x.replace('.r','rc')), reverse=True):
|
||||
major_version = ".".join(my_version.split('.')[:2])
|
||||
if major_version not in template_data['major_versions']:
|
||||
template_data['major_versions'][major_version] = dict()
|
||||
template_data['versions'][my_version] = parse_change_log(all_versions[my_version], my_version)
|
||||
for flavour in all_versions:
|
||||
version_prefix = version_metadata[flavour]['prefix']
|
||||
template_data = {
|
||||
'major_versions': collections.OrderedDict(),
|
||||
'versions': collections.OrderedDict(),
|
||||
'nicknames': collections.OrderedDict(),
|
||||
'flavour': flavour
|
||||
}
|
||||
template_data.update(version_metadata[flavour])
|
||||
versions = all_versions[flavour]
|
||||
for my_version in sorted(versions, key=lambda x: version.Version(x.replace('.r','rc')), reverse=True):
|
||||
major_version = ".".join(my_version.split('.')[:2])
|
||||
if major_version not in template_data['major_versions']:
|
||||
template_data['major_versions'][major_version] = dict()
|
||||
template_data['versions'][my_version] = parse_change_log(versions[my_version], my_version)
|
||||
|
||||
if major_version == my_version:
|
||||
template_data['nicknames'][my_version] = ""
|
||||
tmp = all_versions[my_version].replace('\n', ' ')
|
||||
m = re.match(r'.*nicknamed ["\'](?P<nickname>[^"\']+)', tmp)
|
||||
if m:
|
||||
template_data['nicknames'][my_version] = m.groupdict()['nickname']
|
||||
if major_version == my_version:
|
||||
template_data['nicknames'][my_version] = ""
|
||||
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/releases.rst" % root_dir, 'w') as f_out:
|
||||
template = Template(open("%s/source/releases.rst.in" % root_dir, "r").read())
|
||||
f_out.write(template.render(template_data))
|
||||
# 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.rst" % (root_dir, major_version), 'w') as f_out:
|
||||
template_data['this_version'] = major_version
|
||||
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
|
||||
:width: 600px
|
||||
:align: center
|
||||
@ -9,6 +11,18 @@ Releases
|
||||
As of January 2015 there have been *{{ versions|length }}* releases leading to the latest version *{{ versions|first }}*
|
||||
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.
|
||||
|
||||
.. toctree::
|
||||
@ -17,6 +31,6 @@ The list below contains all releases, ordered by version number categorized by m
|
||||
:glob:
|
||||
{% for major_version in major_versions%}
|
||||
{%- if major_version in versions %}
|
||||
releases/{{major_version}}
|
||||
releases/{{prefix}}_{{major_version}}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user