| 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 |
|
| 17 |
def parse_args(depdiagram_available): |
| 18 |
import textwrap |
| 19 |
parser = argparse.ArgumentParser( |
| 20 |
formatter_class=argparse.RawDescriptionHelpFormatter, |
| 21 |
description=textwrap.dedent('''Generate API documentation of complex projects. |
| 22 |
|
| 23 |
>> This function must be run from an empty directory (where the documentation will be built).''') |
| 24 |
) |
| 25 |
group = add_sources_group(parser) |
| 26 |
group.add_argument('sourcesdir', type=normalized_path, |
| 27 |
help='Location of the sources.') |
| 28 |
group.add_argument('--depdiagram-dot-dir', type=normalized_path, |
| 29 |
help='Generate dependency diagrams, using the .dot files from DIR.', |
| 30 |
metavar="DIR") |
| 31 |
add_output_group(parser) |
| 32 |
add_qt_doc_group(parser) |
| 33 |
add_paths_group(parser) |
| 34 |
add_misc_group(parser) |
| 35 |
args = parser.parse_args() |
| 36 |
check_common_args(args) |
| 37 |
|
| 38 |
if args.depdiagram_dot_dir and not depdiagram_available: |
| 39 |
logging.error('You need to install the Graphviz Python bindings to ' |
| 40 |
'generate dependency diagrams.\n' |
| 41 |
'See <https://www.graphviz.org/download/>.') |
| 42 |
exit(1) |
| 43 |
|
| 44 |
if not os.path.isdir(args.sourcesdir): |
| 45 |
logging.error(args.sourcesdir + " is not a directory") |
| 46 |
exit(2) |
| 47 |
|
| 48 |
return args |
| 49 |
|
| 50 |
|
| 51 |
def add_sources_group(parser): |
| 52 |
group = parser.add_argument_group('sources') |
| 53 |
group.add_argument('--accountsfile', type=normalized_path, |
| 54 |
help='File with accounts information of SVN contributors.') |
| 55 |
return group |
| 56 |
|
| 57 |
|
| 58 |
def add_output_group(parser): |
| 59 |
group = parser.add_argument_group('output options') |
| 60 |
group.add_argument('--title', default='API Documentation', |
| 61 |
help='String to use for page titles.') |
| 62 |
group.add_argument('--man-pages', action='store_true', |
| 63 |
help='Generate man page documentation.') |
| 64 |
group.add_argument('--qhp', action='store_true', |
| 65 |
help='Generate Qt Compressed Help documentation.') |
| 66 |
return group |
| 67 |
|
| 68 |
|
| 69 |
def add_qt_doc_group(parser): |
| 70 |
group = parser.add_argument_group('Qt documentation') |
| 71 |
group.add_argument('--qtdoc-dir', type=normalized_path, |
| 72 |
help='Location of (local) Qt documentation; this is searched ' + |
| 73 |
'for tag files to create links to Qt classes.') |
| 74 |
group.add_argument('--qtdoc-link', |
| 75 |
help='Override Qt documentation location for the links in the ' + |
| 76 |
'html files. May be a path or URL.') |
| 77 |
group.add_argument('--qtdoc-flatten-links', action='store_true', |
| 78 |
help='Whether to assume all Qt documentation html files ' + |
| 79 |
'are immediately under QTDOC_LINK (useful if you set ' + |
| 80 |
'QTDOC_LINK to the online Qt documentation). Ignored ' + |
| 81 |
'if QTDOC_LINK is not set.') |
| 82 |
return group |
| 83 |
|
| 84 |
|
| 85 |
def add_paths_group(parser): |
| 86 |
group = parser.add_argument_group('paths') |
| 87 |
group.add_argument('--doxygen', default='doxygen', type=normalized_path, |
| 88 |
help='(Path to) the doxygen executable.') |
| 89 |
group.add_argument('--qhelpgenerator', default='qhelpgenerator', type=normalized_path, |
| 90 |
help='(Path to) the qhelpgenerator executable.') |
| 91 |
return group |
| 92 |
|
| 93 |
|
| 94 |
def add_misc_group(parser): |
| 95 |
scriptdir = os.path.dirname(os.path.realpath(__file__)) |
| 96 |
doxdatadir = os.path.join(scriptdir, 'data') |
| 97 |
|
| 98 |
group = parser.add_argument_group('misc') |
| 99 |
group.add_argument('--doxdatadir', default=doxdatadir, type=normalized_path, |
| 100 |
help='Location of the HTML header files and support graphics.') |
| 101 |
group.add_argument('--keep-temp-dirs', action='store_true', |
| 102 |
help='Do not delete temporary dirs, useful for debugging.') |
| 103 |
return parser |
| 104 |
|
| 105 |
|
| 106 |
def check_common_args(args): |
| 107 |
if not _is_doxdatadir(args.doxdatadir): |
| 108 |
logging.error(f'{args.doxdatadir} is not a valid doxdatadir') |
| 109 |
sys.exit(1) |
| 110 |
|
| 111 |
|
| 112 |
def _is_doxdatadir(directory): |
| 113 |
for name in ['header.html', 'footer.html', 'htmlresource']: |
| 114 |
if not os.path.exists(os.path.join(directory, name)): |
| 115 |
return False |
| 116 |
return True |