KApiDox

argparserutils.py
1 # -*- coding: utf-8 -*-
2 #
3 # SPDX-FileCopyrightText: 2014 Aurélien Gâteau <[email protected]>
4 #
5 # SPDX-License-Identifier: BSD-2-Clause
6 
7 import argparse
8 import logging
9 import os
10 import sys
11 
12 
13 def normalized_path(inputpath):
14  return os.path.normpath(inputpath)
15 
16 def parse_args(depdiagram_available):
17  import textwrap
18  parser = argparse.ArgumentParser(
19  formatter_class=argparse.RawDescriptionHelpFormatter,
20  description=textwrap.dedent('''Generate API documentations of complex projects.
21 
22 >> This function must be run from an empty directory (where the documentation will be build).''')
23  )
24  group = add_sources_group(parser)
25  group.add_argument('sourcesdir', type=normalized_path,
26  help='Location of the sources.')
27  group.add_argument('--depdiagram-dot-dir', type=normalized_path,
28  help='Generate dependency diagrams, using the .dot files from DIR.',
29  metavar="DIR")
30  add_output_group(parser)
31  add_qt_doc_group(parser)
32  add_paths_group(parser)
33  add_misc_group(parser)
34  args = parser.parse_args()
35  check_common_args(args)
36 
37  if args.depdiagram_dot_dir and not depdiagram_available:
38  logging.error('You need to install the Graphviz Python bindings to '
39  'generate dependency diagrams.\n'
40  'See <https://www.graphviz.org/download/>.')
41  exit(1)
42 
43  if not os.path.isdir(args.sourcesdir):
44  logging.error(args.sourcesdir + " is not a directory")
45  exit(2)
46 
47  return args
48 
49 
50 def add_sources_group(parser):
51  return parser.add_argument_group('sources')
52 
53 
54 def add_output_group(parser):
55  group = parser.add_argument_group('output options')
56  group.add_argument('--title', default='API Documentation',
57  help='String to use for page titles.')
58  group.add_argument('--man-pages', action='store_true',
59  help='Generate man page documentation.')
60  group.add_argument('--qhp', action='store_true',
61  help='Generate Qt Compressed Help documentation.')
62  return group
63 
64 
65 def add_qt_doc_group(parser):
66  group = parser.add_argument_group('Qt documentation')
67  group.add_argument('--qtdoc-dir', type=normalized_path,
68  help='Location of (local) Qt documentation; this is searched ' +
69  'for tag files to create links to Qt classes.')
70  group.add_argument('--qtdoc-link',
71  help='Override Qt documentation location for the links in the ' +
72  'html files. May be a path or URL.')
73  group.add_argument('--qtdoc-flatten-links', action='store_true',
74  help='Whether to assume all Qt documentation html files ' +
75  'are immediately under QTDOC_LINK (useful if you set ' +
76  'QTDOC_LINK to the online Qt documentation). Ignored ' +
77  'if QTDOC_LINK is not set.')
78  return group
79 
80 
81 def add_paths_group(parser):
82  group = parser.add_argument_group('paths')
83  group.add_argument('--doxygen', default='doxygen', type=normalized_path,
84  help='(Path to) the doxygen executable.')
85  group.add_argument('--qhelpgenerator', default='qhelpgenerator', type=normalized_path,
86  help='(Path to) the qhelpgenerator executable.')
87  return group
88 
89 
90 def add_misc_group(parser):
91  scriptdir = os.path.dirname(os.path.realpath(__file__))
92  doxdatadir = os.path.join(scriptdir, 'data')
93 
94  group = parser.add_argument_group('misc')
95  group.add_argument('--doxdatadir', default=doxdatadir, type=normalized_path,
96  help='Location of the HTML header files and support graphics.')
97  group.add_argument('--keep-temp-dirs', action='store_true',
98  help='Do not delete temporary dirs, useful for debugging.')
99  return parser
100 
101 
102 def check_common_args(args):
103  if not _is_doxdatadir(args.doxdatadir):
104  logging.error("{} is not a valid doxdatadir".format(args.doxdatadir))
105  sys.exit(1)
106 
107 
108 def _is_doxdatadir(directory):
109  for name in ['header.html', 'footer.html', 'htmlresource']:
110  if not os.path.exists(os.path.join(directory, name)):
111  return False
112  return True
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Nov 30 2020 22:54:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.