doc: Move build scripts into separate directory

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Joseph Nuthalapati authored and James Valleroy committed 2019-10-30 19:24:57 -04:00
1 parent d67412220a
commit 004ba5b3ea
6 files changed
+11 -9

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#
# This file is part of FreedomBox.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Set output method to text -->
<xsl:output method="text"/>
<!-- Process and ignore all nodes by default -->
<xsl:template match="@*|node()">
<xsl:apply-templates select="@*|node()"/>
</xsl:template>
<!-- Output URLs from imagedata nodes -->
<xsl:template match="imagedata">
<xsl:call-template name="filename">
<xsl:with-param name="path" select="@fileref"/>
</xsl:call-template>
<xsl:text> "</xsl:text>
<xsl:value-of select="@fileref"/>
<xsl:text>"&#010;</xsl:text>
</xsl:template>
<!-- Output just the filename from a URL -->
<xsl:template match="@fileref[parent::imagedata]">
<xsl:attribute name="fileref">
<xsl:call-template name="filename">
<xsl:with-param name="path" select="."/>
</xsl:call-template>
</xsl:attribute>
</xsl:template>
<xsl:template name="filename">
<xsl:param name="path"/>
<xsl:choose>
<xsl:when test="contains($path, 'target=')">
<xsl:value-of select="substring-after($path, 'target=')"/>
</xsl:when>
<xsl:when test="not(contains($path, '/'))">
<xsl:value-of select="$path"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="filename">
<xsl:with-param name="path" select="substring-after($path, '/')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
+59
View File
@@ -0,0 +1,59 @@
#!/usr/bin/python3
#
# This file is part of FreedomBox.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import re
import urllib.request
MANUAL_PAGE_URL = "https://wiki.debian.org/FreedomBox/Manual/{}?action=show&mimetype=text%2Fdocbook"
MANUAL_INDEX_RAW_URL = "https://wiki.debian.org/FreedomBox/Manual?action=raw"
manual_pages = []
to_remove = ['QuickStart', 'GettingHelp', 'Developer']
def list_manual_pages():
"""Fetch the list of manual pages and write them to a file.
"""
pattern = 'FreedomBox/Manual/\w+'
lst = list(urllib.request.urlopen(MANUAL_INDEX_RAW_URL))
global manual_pages
manual_pages = list(l[0].split('/')[-1] for l in filter(
None, map(lambda x: re.findall(pattern, x.decode()), lst)))
for entry in to_remove:
if entry in manual_pages:
manual_pages.remove(entry)
with open('manual-pages.list', 'w') as lst_file:
lst_file.write('\n'.join(manual_pages))
def fetch_manual_pages_in_docbook_format():
for page in manual_pages:
url = MANUAL_PAGE_URL.format(page)
filename = '{}.raw.xml'.format(page)
urllib.request.urlretrieve(url, filename)
def main():
list_manual_pages()
fetch_manual_pages_in_docbook_format()
if __name__ == '__main__':
main()
+122
View File
@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#
# This file is part of FreedomBox.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Set output format to Docbook -->
<xsl:output
method="xml"
encoding="utf-8"
indent="yes"
doctype-public="-//OASIS//DTD DocBook XML V4.4//EN"
doctype-system="http://www.docbook.org/xml/4.4/docbookx.dtd"/>
<!-- Copy all nodes and attributes by default -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Replace / in title with a space -->
<xsl:template match="articleinfo/title/text()">
<xsl:call-template name="clean-title">
<xsl:with-param name="title" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="clean-title">
<xsl:param name="title"/>
<xsl:choose>
<xsl:when test="contains($title, '/')">
<!-- Skip copying the language code -->
<xsl:choose>
<xsl:when test="not(string-length(substring-before($title, '/'))=2)
and
not(string-length(substring-before($title, '/'))=5 and contains(substring-before($title, '/'), '-'))">
<xsl:value-of select="substring-before($title, '/')"/>
<xsl:text> </xsl:text>
</xsl:when>
</xsl:choose>
<xsl:call-template name="clean-title">
<xsl:with-param name="title" select="substring-after($title, '/')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$title"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Remove revision history -->
<xsl:template match="revhistory"/>
<!-- Convert all image dimensions from pixels to points -->
<xsl:template match="@width[parent::imagedata]|@depth[parent::imagedata]">
<xsl:attribute name="{name()}">
<xsl:value-of select=". div 2"/>
<xsl:text>pt</xsl:text>
</xsl:attribute>
</xsl:template>
<!-- Convert all image source URLs to relative paths -->
<xsl:template match="@fileref[parent::imagedata]">
<xsl:attribute name="fileref">
<xsl:text>images/</xsl:text>
<xsl:call-template name="filename">
<xsl:with-param name="path" select="."/>
</xsl:call-template>
</xsl:attribute>
</xsl:template>
<!-- Output just the filename from a URL -->
<xsl:template name="filename">
<xsl:param name="path"/>
<xsl:choose>
<xsl:when test="contains($path, 'target=')">
<xsl:value-of select="substring-after($path, 'target=')"/>
</xsl:when>
<xsl:when test="not(contains($path, '/'))">
<xsl:value-of select="$path"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="filename">
<xsl:with-param name="path" select="substring-after($path, '/')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Fix incorrectly output wiki links -->
<xsl:template match="@url[parent::ulink]">
<xsl:attribute name="url">
<xsl:choose>
<xsl:when test="contains(., 'FreedomBox/Manual/')">
<xsl:value-of select="substring-before(., 'FreedomBox/Manual/')"/>
<xsl:value-of select="substring-after(., 'FreedomBox/Manual/')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
+99
View File
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#
# This file is part of FreedomBox.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Set output format to Docbook -->
<xsl:output
method="xml"
encoding="utf-8"
indent="yes"
doctype-public="-//OASIS//DTD DocBook XML V4.4//EN"
doctype-system="http://www.docbook.org/xml/4.4/docbookx.dtd"/>
<!-- Copy all nodes and attributes by default -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Split and get the last word in the title -->
<xsl:template match="articleinfo/title/text()">
<xsl:call-template name="clean-title">
<xsl:with-param name="title" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="clean-title">
<xsl:param name="title"/>
<xsl:choose>
<xsl:when test="contains($title, '/')">
<xsl:text></xsl:text>
<xsl:call-template name="clean-title">
<xsl:with-param name="title" select="substring-after($title, '/')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$title"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Remove revision history -->
<xsl:template match="revhistory"/>
<!-- Convert all image dimensions from pixels to points -->
<xsl:template match="@width[parent::imagedata]|@depth[parent::imagedata]">
<xsl:attribute name="{name()}">
<xsl:value-of select=". div 2"/>
<xsl:text>pt</xsl:text>
</xsl:attribute>
</xsl:template>
<!-- Convert all image source URLs to relative paths -->
<xsl:template match="@fileref[parent::imagedata]">
<xsl:attribute name="fileref">
<xsl:text>images/</xsl:text>
<xsl:call-template name="filename">
<xsl:with-param name="path" select="."/>
</xsl:call-template>
</xsl:attribute>
</xsl:template>
<!-- Output just the filename from a URL -->
<xsl:template name="filename">
<xsl:param name="path"/>
<xsl:choose>
<xsl:when test="contains($path, 'target=')">
<xsl:value-of select="substring-after($path, 'target=')"/>
</xsl:when>
<xsl:when test="not(contains($path, '/'))">
<xsl:value-of select="$path"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="filename">
<xsl:with-param name="path" select="substring-after($path, '/')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
+102
View File
@@ -0,0 +1,102 @@
#!/usr/bin/python3
#
# This file is part of FreedomBox.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import argparse
import xml.etree.ElementTree as etree
def parse_arguments():
"""Return parsed command line arguments as dictionary."""
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
subparser = subparsers.add_parser(
'remove-footer', help='Remove footer from the XML document')
subparser.add_argument('filename', help='Name of the XML file')
subparser = subparsers.add_parser('fix-wiki-urls',
help='Fix wrongly formatted wiki urls')
subparser.add_argument('filename', help='Name of the Docbook file')
subparsers.required = True
return parser.parse_args()
def subcommand_fix_wiki_urls(arguments):
file_name = arguments.filename
page_name = file_name.split('.')[0]
with open(file_name, 'r') as xml_file:
lines = xml_file.readlines()
pattern = 'FreedomBox/Manual/{0}/FreedomBox'.format(page_name)
lines = list(map(lambda s: s.replace(pattern, 'FreedomBox'), lines))
with open(file_name, 'w') as xml_file:
xml_file.writelines(lines)
def subcommand_remove_footer(arguments):
"""Remove the footer template from the given wiki page."""
filename = arguments.filename
tree = etree.parse(filename)
root = tree.getroot()
# The footer will always be in the last <section>
def find_last_section(elem):
if len(elem):
last_element = elem[-1]
if last_element.tag == 'section':
return find_last_section(last_element)
return elem
last_section = find_last_section(root)
if len(last_section):
# Remove all elements till <informaltable> is reached
while last_section[-1].tag != 'informaltable':
last_section.remove(last_section[-1])
# remove <informaltable> itself
last_section.remove(last_section[-1])
# Remove the line "Back to Features introduction or manual pages."
if last_section[-1].text.startswith('Back to'):
last_section.remove(last_section[-1])
processed_xml = etree.tostring(root, encoding='utf-8').decode()
with open(filename, 'r') as xml_file:
# <xml> and <DOCTYPE> elements which etree skips
header = xml_file.readlines()[:2]
with open(filename, 'w') as xml_file:
xml_file.writelines(header)
xml_file.write(processed_xml)
def main():
"""Parse arguments and perform all duties."""
arguments = parse_arguments()
subcommand = arguments.subcommand.replace('-', '_')
subcommand_method = globals()['subcommand_' + subcommand]
subcommand_method(arguments)
if __name__ == '__main__':
main()