diff --git a/src/kapidox/generator.py b/src/kapidox/generator.py --- a/src/kapidox/generator.py +++ b/src/kapidox/generator.py @@ -37,6 +37,7 @@ import subprocess import tempfile import sys +import xml.etree.ElementTree as ET import jinja2 @@ -621,6 +622,7 @@ writer.write_entries( GENERATE_MAN=ctx.man_pages, GENERATE_QHP=ctx.qhp) + #, SEARCHENGINE=ctx.searchengine) if doxyfile_entries: @@ -883,3 +885,80 @@ with open('searchdata.json', 'w') as f: for chunk in json.JSONEncoder().iterencode(indexdic): f.write(chunk) + +def create_qch(products, tagfiles): + tag_root = "QtHelpProject" + tag_files = "files" + tag_filterSection = "filterSection" + tag_keywords = "keywords" + tag_toc = "toc" + for product in products: + tree_out = ET.ElementTree(ET.Element("QtHelpProject")) + root_out = tree_out.getroot() + root_out.set("version", "1.0") + namespace = ET.SubElement(root_out, "namespace") + namespace.text = "org.kde." + product.name + virtualFolder = ET.SubElement(root_out, "virtualFolder") + virtualFolder.text = product.name + filterSection = ET.SubElement(root_out, tag_filterSection) + filterAttribute = ET.SubElement(filterSection, "filterAttribute") + filterAttribute.text = "doxygen" + toc = ET.SubElement(filterSection, "toc") + keywords = ET.SubElement(filterSection, tag_keywords) + if len(product.libraries) > 0: + if product.libraries[0].part_of_group: + product_indexSection = ET.SubElement(toc, "section", {'ref': product.name + "/index.html", 'title': product.fancyname}) + files = ET.SubElement(filterSection, tag_files) + + for lib in sorted(product.libraries, key=lambda lib: lib.name): + tree = ET.parse(lib.outputdir + '/html/index.qhp') + root = tree.getroot() + for child in root.findall(".//*[@ref]"): + if lib.part_of_group: + child.attrib['ref'] = lib.name + "/html/" + child.attrib['ref'] + else: + child.attrib['ref'] = "html/" + child.attrib['ref'] + child.attrib['ref'] = product.name + '/' +child.attrib['ref'] + + for child in root.find(".//"+tag_toc): + print(child.attrib['ref']) + if lib.part_of_group: + product_indexSection.append(child) + else: + toc.append(child) + + for child in root.find(".//keywords"): + keywords.append(child) + + resources = [ + "*.json", + product.name + "/*.json", + product.name +"/" + lib.name +"/html/*.json", + product.name + "/*.html", + product.name + "/html/*.html", + product.name +"/html/*.png", + product.name +"/html/*.css", + product.name +"/html/*.js", + product.name +"/" + lib.name +"/html/*.html", + product.name +"/" + lib.name +"/html/*.png", + product.name +"/" + lib.name +"/html/*.css", + product.name +"/" + lib.name +"/html/*.js", + "resources/css/*.css", + "resources/3rd-party/bootstrap/css/*.css", + "resources/3rd-party/jquery/jquery-3.1.0.min.js", + "resources/*.svg", + "resources/js/*.js", + "resources/icons/*", + ] + for resource in resources: + file_elem = ET.SubElement(files, "file") + file_elem.text = resource + + if not os.path.isdir('qch'): + os.mkdir('qch') + + name = product.name+".qhp" + outname = product.name+".qch" + tree_out.write(name, encoding="utf-8", xml_declaration=True) + subprocess.call(["qhelpgenerator", name, '-o', 'qch/'+outname]) + os.remove(name) diff --git a/src/kapidox_generate b/src/kapidox/hlfunctions.py old mode 100755 new mode 100644 copy from src/kapidox_generate copy to src/kapidox/hlfunctions.py --- a/src/kapidox_generate +++ b/src/kapidox/hlfunctions.py @@ -31,95 +31,36 @@ from __future__ import division, absolute_import, print_function, unicode_literals import logging -import codecs import os import shutil import sys import tempfile -import time -import datetime if sys.version_info.major < 3: from urllib import urlretrieve else: from urllib.request import urlretrieve -from kapidox import generator, utils, argparserutils, preprocessing +from . import generator, utils, argparserutils, preprocessing try: from kapidox import depdiagram DEPDIAGRAM_AVAILABLE = True except ImportError: DEPDIAGRAM_AVAILABLE = False - -def find_dot_files(dot_dir): - """Returns a list of path to files ending with .dot in subdirs of `dot_dir`.""" - lst = [] - for (root, dirs, files) in os.walk(dot_dir): - lst.extend([os.path.join(root, x) for x in files if x.endswith('.dot')]) - return lst - - -def download_kde_identities(): - """Download the "accounts" file on the KDE SVN repository in order to get - the KDE identities with their name and e-mail address - """ - cache_file = os.path.join(utils.cache_dir(), 'kde-accounts') - needs_download = True - if os.path.exists(cache_file): - logging.debug("Found cached identities file at %s", cache_file) - # not quite a day, so that generation on api.kde.org gets a fresh - # copy every time the daily cron job runs it - yesterday = time.time() - (23.5 * 3600) - if os.path.getmtime(cache_file) > yesterday: - needs_download = False - else: - logging.debug("Cached file too old; updating") - if needs_download: - logging.info("Downloading KDE identities") - try: - if not utils.svn_export( - 'svn://anonsvn.kde.org/home/kde/trunk/kde-common/accounts', - cache_file, - overwrite=True): - logging.debug("Falling back to using websvn to fetch " - "identities file") - urlretrieve('http://websvn.kde.org/*checkout*/trunk/kde-common/accounts', - cache_file) - except Exception as e: - if os.path.exists(cache_file): - logging.error('Failed to update KDE identities: %s', e) - else: - logging.error('Failed to fetch KDE identities: %s', e) - return None - - maintainers = {} - - with codecs.open(cache_file, 'r', encoding='utf8') as f: - for line in f: - parts = line.strip().split() - if len(parts) >= 3: - maintainers[parts[0]] = { - 'name': ' '.join(parts[1:-1]), - 'email': parts[-1] - } - - return maintainers - - -def main(): - kde_copyright = '1996-' + str(datetime.date.today().year) + ' The KDE developers' +def do_it(maintainers, copyright, searchpaths=None): + if searchpaths is None: + searchpaths = searchpaths=['/usr/share/doc/qt5', '/usr/share/doc/qt'] utils.setup_logging() args = argparserutils.parse_args(DEPDIAGRAM_AVAILABLE) tagfiles = generator.search_for_tagfiles( suggestion=args.qtdoc_dir, doclink=args.qtdoc_link, flattenlinks=args.qtdoc_flatten_links, - searchpaths=['/usr/share/doc/qt5', '/usr/share/doc/qt']) + searchpaths=searchpaths) - maintainers = download_kde_identities() rootdir = args.sourcesdir metalist = preprocessing.parse_tree(rootdir) @@ -149,9 +90,8 @@ try: if args.depdiagram_dot_dir: - dot_files = find_dot_files(args.depdiagram_dot_dir) + dot_files = utils.find_dot_files(args.depdiagram_dot_dir) assert(dot_files) - for lib in libraries: logging.info('# Generating doc for {}'.format(lib.fancyname)) if args.depdiagram_dot_dir: @@ -169,7 +109,7 @@ logging.info('# Rebuilding {} for interdependencies' .format(lib.fancyname)) shutil.rmtree(lib.outputdir) - ctx = generator.create_fw_context(args, lib, tagfiles, kde_copyright) + ctx = generator.create_fw_context(args, lib, tagfiles, copyright) generator.gen_fw_apidocs(ctx, tmp_dir) generator.finish_fw_apidocs(ctx, None) logging.info('# Generate indexing files') @@ -183,12 +123,10 @@ os.mkdir(logodir) shutil.copy(product.logo_url_src, product.logo_url) generator.create_global_index(products) + if args.qhp: + generator.create_qch(products, tagfiles) finally: if args.keep_temp_dirs: logging.info('Kept temp dir at {}'.format(tmp_dir)) else: shutil.rmtree(tmp_dir) - - -if __name__ == "__main__": - main() diff --git a/src/kapidox/utils.py b/src/kapidox/utils.py --- a/src/kapidox/utils.py +++ b/src/kapidox/utils.py @@ -264,3 +264,11 @@ # cause the code to fail logging.warning("Getting git info failed: {}".format(exc)) return _KAPIDOX_VERSION + + +def find_dot_files(dot_dir): + """Returns a list of path to files ending with .dot in subdirs of `dot_dir`.""" + lst = [] + for (root, dirs, files) in os.walk(dot_dir): + lst.extend([os.path.join(root, x) for x in files if x.endswith('.dot')]) + return lst diff --git a/src/kapidox_generate b/src/kapidox_generate --- a/src/kapidox_generate +++ b/src/kapidox_generate @@ -33,34 +33,24 @@ import logging import codecs import os -import shutil import sys -import tempfile import time import datetime if sys.version_info.major < 3: from urllib import urlretrieve else: from urllib.request import urlretrieve -from kapidox import generator, utils, argparserutils, preprocessing +from kapidox import generator, utils, argparserutils, preprocessing, hlfunctions try: from kapidox import depdiagram DEPDIAGRAM_AVAILABLE = True except ImportError: DEPDIAGRAM_AVAILABLE = False -def find_dot_files(dot_dir): - """Returns a list of path to files ending with .dot in subdirs of `dot_dir`.""" - lst = [] - for (root, dirs, files) in os.walk(dot_dir): - lst.extend([os.path.join(root, x) for x in files if x.endswith('.dot')]) - return lst - - def download_kde_identities(): """Download the "accounts" file on the KDE SVN repository in order to get the KDE identities with their name and e-mail address @@ -109,85 +99,12 @@ def main(): - kde_copyright = '1996-' + str(datetime.date.today().year) + ' The KDE developers' utils.setup_logging() - args = argparserutils.parse_args(DEPDIAGRAM_AVAILABLE) - - tagfiles = generator.search_for_tagfiles( - suggestion=args.qtdoc_dir, - doclink=args.qtdoc_link, - flattenlinks=args.qtdoc_flatten_links, - searchpaths=['/usr/share/doc/qt5', '/usr/share/doc/qt']) - + kde_copyright = '1996-' + str(datetime.date.today().year) + ' The KDE developers' maintainers = download_kde_identities() - rootdir = args.sourcesdir - metalist = preprocessing.parse_tree(rootdir) - products, groups, libraries, available_platforms = preprocessing.sort_metainfo(metalist, maintainers) - - dirsrc = os.path.join(args.doxdatadir, 'htmlresource') - dirdest = 'resources' - if os.path.isdir(dirdest): - shutil.rmtree(dirdest) - shutil.copytree(dirsrc, dirdest) - os.rename(dirdest+'/favicon.ico', './favicon.ico') - - generator.process_toplevel_html_file('index.html', - args.doxdatadir, - title=args.title, - products=products, - api_searchbox=args.api_searchbox - ) - generator.process_subgroup_html_files('index.html', - args.doxdatadir, - title=args.title, - groups=groups, - available_platforms=available_platforms, - api_searchbox=args.api_searchbox - ) - tmp_dir = tempfile.mkdtemp(prefix='kapidox-') - - try: - if args.depdiagram_dot_dir: - dot_files = find_dot_files(args.depdiagram_dot_dir) - assert(dot_files) - - for lib in libraries: - logging.info('# Generating doc for {}'.format(lib.fancyname)) - if args.depdiagram_dot_dir: - png_path = os.path.join(tmp_dir, lib.name) + '.png' - ok = generator.generate_diagram(png_path, lib.fancyname, - dot_files, tmp_dir) - if ok: - lib.dependency_diagram = png_path - ctx = generator.create_fw_context(args, lib, tagfiles) - generator.gen_fw_apidocs(ctx, tmp_dir) - tagfiles.append(generator.create_fw_tagfile_tuple(lib)) - - # Rebuild for interdependencies - for lib in libraries: - logging.info('# Rebuilding {} for interdependencies' - .format(lib.fancyname)) - shutil.rmtree(lib.outputdir) - ctx = generator.create_fw_context(args, lib, tagfiles, kde_copyright) - generator.gen_fw_apidocs(ctx, tmp_dir) - generator.finish_fw_apidocs(ctx, None) - logging.info('# Generate indexing files') - generator.indexer(lib) - logging.info('# Done') - for product in products: - generator.create_product_index(product) - if product.logo_url is not None: - logodir = os.path.dirname(product.logo_url) - if not os.path.isdir(logodir): - os.mkdir(logodir) - shutil.copy(product.logo_url_src, product.logo_url) - generator.create_global_index(products) - finally: - if args.keep_temp_dirs: - logging.info('Kept temp dir at {}'.format(tmp_dir)) - else: - shutil.rmtree(tmp_dir) + hlfunctions.do_it(maintainers=maintainers, + copyright=kde_copyright) if __name__ == "__main__":