KApiDox

hlfunctions.py
1 # -*- coding: utf-8 -*-
2 #
3 # SPDX-FileCopyrightText: 2014 Alex Merry <[email protected]>
4 # SPDX-FileCopyrightText: 2014 Aurélien Gâteau <[email protected]>
5 # SPDX-FileCopyrightText: 2014 Alex Turbov <[email protected]>
6 # SPDX-FileCopyrightText: 2016 Olivier Churlaud <[email protected]>
7 #
8 # SPDX-License-Identifier: BSD-2-Clause
9 
10 import logging
11 import os
12 import shutil
13 import sys
14 import tempfile
15 import json
16 
17 from urllib.request import urlretrieve
18 
19 from . import generator, utils, argparserutils, preprocessing
20 
21 try:
22  from kapidox import depdiagram
23  DEPDIAGRAM_AVAILABLE = True
24 except ImportError:
25  DEPDIAGRAM_AVAILABLE = False
26 
27 
28 def do_it(maintainers_fct, copyright, searchpaths=None):
29  utils.setup_logging()
30  if searchpaths is None:
31  searchpaths = searchpaths=['/usr/share/doc/qt5', '/usr/share/doc/qt']
32  args = argparserutils.parse_args(DEPDIAGRAM_AVAILABLE)
33 
34  if len(os.listdir(os.getcwd())) > 0:
35  logging.error("Run this command from an empty directory.")
36  exit(2)
37 
38  if not DEPDIAGRAM_AVAILABLE:
39  logging.warning("Missing Graphviz dependency: diagrams will not be generated.")
40 
41  tagfiles = generator.search_for_tagfiles(
42  suggestion=args.qtdoc_dir,
43  doclink=args.qtdoc_link,
44  flattenlinks=args.qtdoc_flatten_links,
45  searchpaths=searchpaths)
46 
47  rootdir = args.sourcesdir
48  maintainers = maintainers_fct()
49 
50  metalist = preprocessing.parse_tree(rootdir)
51  products, groups, libraries, available_platforms = preprocessing.sort_metainfo(metalist, maintainers)
52 
53  dirsrc = os.path.join(args.doxdatadir, 'htmlresource')
54  dirdest = 'resources'
55  if os.path.isdir(dirdest):
56  shutil.rmtree(dirdest)
57  shutil.copytree(dirsrc, dirdest)
58  os.rename(dirdest+'/favicon.ico', './favicon.ico')
59  os.rename(dirdest+'/worker.js', './worker.js')
60 
61  generator.process_toplevel_html_file('index.html',
62  args.doxdatadir,
63  title=args.title,
64  products=products,
65  qch_enabled=args.qhp
66  )
67  generator.process_subgroup_html_files('index.html',
68  args.doxdatadir,
69  title=args.title,
70  groups=groups,
71  available_platforms=available_platforms,
72  qch_enabled=args.qhp
73  )
74  tmp_dir = tempfile.mkdtemp(prefix='kapidox-')
75 
76  try:
77  if args.depdiagram_dot_dir:
78  dot_files = utils.find_dot_files(args.depdiagram_dot_dir)
79  assert(dot_files)
80  for lib in libraries:
81  logging.info('# Generating doc for {}'.format(lib.fancyname))
82  if args.depdiagram_dot_dir:
83  png_path = os.path.join(tmp_dir, lib.name) + '.png'
84  ok = generator.generate_diagram(png_path, lib.fancyname,
85  dot_files, tmp_dir)
86  if ok:
87  lib.dependency_diagram = png_path
88 
89  # store this as we won't use that every time
90  create_qhp = args.qhp
91  args.qhp = False
92  ctx = generator.create_fw_context(args, lib, tagfiles)
93  # set it back
94  args.qhp = create_qhp
95 
96  generator.gen_fw_apidocs(ctx, tmp_dir)
97  tagfiles.insert(0, generator.create_fw_tagfile_tuple(lib))
98 
99  # Rebuild for interdependencies
100  for lib in libraries:
101  logging.info('# Rebuilding {} for interdependencies'
102  .format(lib.fancyname))
103  shutil.rmtree(lib.outputdir)
104  ctx = generator.create_fw_context(args, lib, tagfiles, copyright)
105  generator.gen_fw_apidocs(ctx, tmp_dir)
106  generator.finish_fw_apidocs(ctx, None)
107  logging.info('# Generate indexing files')
108  generator.indexer(lib)
109  for product in products:
110  generator.create_product_index(product)
111  if product.logo_url is not None:
112  logodir = os.path.dirname(product.logo_url)
113  if not os.path.isdir(logodir):
114  os.mkdir(logodir)
115  shutil.copy(product.logo_url_src, product.logo_url)
116  generator.create_global_index(products)
117  if args.qhp:
118  logging.info('# Merge qch files'
119  .format(lib.fancyname))
120  generator.create_qch(products, tagfiles)
121  logging.info("# Writing metadata... ")
122  with open('metadata.json', 'w') as file:
123  json.dump(metalist, file)
124  libs = []
125  for lib in libraries:
126  libs.append({"name": lib.name, "outputdir": lib.outputdir})
127  with open('outputs.json', 'w') as file:
128  json.dump(libs, file)
129  logging.info('# Done')
130  finally:
131  if args.keep_temp_dirs:
132  logging.info('Kept temp dir at {}'.format(tmp_dir))
133  else:
134  shutil.rmtree(tmp_dir)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Sep 20 2020 22:53:29 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.