Split generate_doc.py
This commit is contained in:
parent
34b0cf429c
commit
3bfc555075
73
scripts/asciidoc2html.py
Normal file
73
scripts/asciidoc2html.py
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||||
|
|
||||||
|
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
|
|
||||||
|
# This file is part of qutebrowser.
|
||||||
|
#
|
||||||
|
# qutebrowser is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# qutebrowser 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 General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""Generate the html documentation based on the asciidoc files."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import glob
|
||||||
|
|
||||||
|
import colorama as col
|
||||||
|
|
||||||
|
|
||||||
|
def call_asciidoc(src, dst):
|
||||||
|
"""Call asciidoc for the given files.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
src: The source .asciidoc file.
|
||||||
|
dst: The destination .html file, or None to auto-guess.
|
||||||
|
"""
|
||||||
|
print("{}Calling asciidoc for {}...{}".format(
|
||||||
|
col.Fore.CYAN, os.path.basename(src), col.Fore.RESET))
|
||||||
|
if os.name == 'nt':
|
||||||
|
# FIXME this is highly specific to my machine
|
||||||
|
args = [r'C:\Python27\python', r'J:\bin\asciidoc-8.6.9\asciidoc.py']
|
||||||
|
else:
|
||||||
|
args = ['asciidoc']
|
||||||
|
if dst is not None:
|
||||||
|
args += ['--out-file', dst]
|
||||||
|
args.append(src)
|
||||||
|
try:
|
||||||
|
subprocess.check_call(args)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(''.join([col.Fore.RED, str(e), col.Fore.RESET]))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
asciidoc_files = [
|
||||||
|
('doc/qutebrowser.1.asciidoc', None),
|
||||||
|
('README.asciidoc', None),
|
||||||
|
('doc/FAQ.asciidoc', 'qutebrowser/html/doc/FAQ.html'),
|
||||||
|
]
|
||||||
|
try:
|
||||||
|
os.mkdir('qutebrowser/html/doc')
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
for src in glob.glob('doc/help/*.asciidoc'):
|
||||||
|
name, _ext = os.path.splitext(os.path.basename(src))
|
||||||
|
dst = 'qutebrowser/html/doc/{}.html'.format(name)
|
||||||
|
asciidoc_files.append((src, dst))
|
||||||
|
for src, dst in asciidoc_files:
|
||||||
|
call_asciidoc(src, dst)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import glob
|
|
||||||
import html
|
import html
|
||||||
import shutil
|
import shutil
|
||||||
import os.path
|
import os.path
|
||||||
@ -38,6 +37,7 @@ sys.path.insert(0, os.getcwd())
|
|||||||
|
|
||||||
# We import qutebrowser.app so all @cmdutils-register decorators are run.
|
# We import qutebrowser.app so all @cmdutils-register decorators are run.
|
||||||
import qutebrowser.app
|
import qutebrowser.app
|
||||||
|
from scripts import asciidoc2html
|
||||||
from qutebrowser import qutebrowser
|
from qutebrowser import qutebrowser
|
||||||
from qutebrowser.commands import cmdutils
|
from qutebrowser.commands import cmdutils
|
||||||
from qutebrowser.config import configdata
|
from qutebrowser.config import configdata
|
||||||
@ -395,30 +395,6 @@ def regenerate_manpage(filename):
|
|||||||
_format_block(filename, 'options', options)
|
_format_block(filename, 'options', options)
|
||||||
|
|
||||||
|
|
||||||
def call_asciidoc(src, dst):
|
|
||||||
"""Call asciidoc for the given files.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
src: The source .asciidoc file.
|
|
||||||
dst: The destination .html file, or None to auto-guess.
|
|
||||||
"""
|
|
||||||
print("{}Calling asciidoc for {}...{}".format(
|
|
||||||
col.Fore.CYAN, os.path.basename(src), col.Fore.RESET))
|
|
||||||
if os.name == 'nt':
|
|
||||||
# FIXME this is highly specific to my machine
|
|
||||||
args = [r'C:\Python27\python', r'J:\bin\asciidoc-8.6.9\asciidoc.py']
|
|
||||||
else:
|
|
||||||
args = ['asciidoc']
|
|
||||||
if dst is not None:
|
|
||||||
args += ['--out-file', dst]
|
|
||||||
args.append(src)
|
|
||||||
try:
|
|
||||||
subprocess.check_call(args)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print(''.join([col.Fore.RED, str(e), col.Fore.RESET]))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Regenerate all documentation."""
|
"""Regenerate all documentation."""
|
||||||
print("{}Generating asciidoc files...{}".format(
|
print("{}Generating asciidoc files...{}".format(
|
||||||
@ -427,21 +403,9 @@ def main():
|
|||||||
generate_settings('doc/help/settings.asciidoc')
|
generate_settings('doc/help/settings.asciidoc')
|
||||||
generate_commands('doc/help/commands.asciidoc')
|
generate_commands('doc/help/commands.asciidoc')
|
||||||
regenerate_authors('README.asciidoc')
|
regenerate_authors('README.asciidoc')
|
||||||
asciidoc_files = [
|
if '--html' in sys.argv:
|
||||||
('doc/qutebrowser.1.asciidoc', None),
|
asciidoc2html.main()
|
||||||
('README.asciidoc', None),
|
|
||||||
('doc/FAQ.asciidoc', 'qutebrowser/html/doc/FAQ.html'),
|
|
||||||
]
|
|
||||||
try:
|
|
||||||
os.mkdir('qutebrowser/html/doc')
|
|
||||||
except FileExistsError:
|
|
||||||
pass
|
|
||||||
for src in glob.glob('doc/help/*.asciidoc'):
|
|
||||||
name, _ext = os.path.splitext(os.path.basename(src))
|
|
||||||
dst = 'qutebrowser/html/doc/{}.html'.format(name)
|
|
||||||
asciidoc_files.append((src, dst))
|
|
||||||
for src, dst in asciidoc_files:
|
|
||||||
call_asciidoc(src, dst)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user