forked from ruslo/hunter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocs_create_missing_stubs.py
78 lines (56 loc) · 2.22 KB
/
docs_create_missing_stubs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import subprocess
# hardcoded paths
HUNTER_DIR='..'
PACKAGES_DIR=os.path.join(HUNTER_DIR, 'cmake/projects')
DOCS_PKG_DIR=os.path.join(HUNTER_DIR, 'docs', 'packages', 'pkg')
# get all wiki entries
docs_filenames = [x for x in os.listdir(DOCS_PKG_DIR) if x.endswith('.rst')]
docs_entries = [x[:-4] for x in docs_filenames]
# get all hunter package entries
pkg_entries = [x for x in os.listdir(PACKAGES_DIR) if os.path.isdir(os.path.join(PACKAGES_DIR, x))]
pkg_entries_lower = [x.lower() for x in pkg_entries]
# packages both in hunter and wiki
pkg_match = [x for x in pkg_entries if x in docs_entries]
# packages only in hunter
pkg_only_hunter = [x for x in pkg_entries if x not in pkg_match]
# output directories
packages_dir = 'packages'
only_hunter_dir = 'packages/only_hunter'
# create if not exist
for d in [packages_dir, only_hunter_dir]:
if not os.path.exists(d):
os.mkdir(d)
# header for rst files
header_format_string = """.. spelling::
{}
.. index:: unsorted ; {}
.. _pkg.{}:
{}
{}
"""
template_string = """
.. warning::
This page is a template and contains no real information.
Please send pull request with real description.
- `__FIXME__ Official <https://__FIXME__>`__
- `__FIXME__ Hunterized <https://github.com/hunter-packages/__FIXME__>`__
- `__FIXME__ Example <https://github.com/ruslo/hunter/blob/master/examples/__FIXME__/CMakeLists.txt>`__
- Available since `__FIXME__ vX.Y.Z <https://github.com/ruslo/hunter/releases/tag/vX.Y.Z>`__
- Added by `__FIXME__ <https://github.com/__FIXME__>`__ (`__FIXME__ pr-N <https://github.com/ruslo/hunter/pull/N>`__)
.. code-block:: cmake
hunter_add_package(__FIXME__)
find_package(__FIXME__ CONFIG REQUIRED)
target_link_libraries(foo __FIXME__::__FIXME__)
"""
# create dummy entries for packages only in hunter
for entry in pkg_only_hunter:
target_rst = os.path.join(only_hunter_dir, entry + '.rst')
underscores = "=" * len(entry)
header = header_format_string.format(entry, entry, entry, entry, underscores)
#print(header)
with open(target_rst, 'w') as f:
f.write(header)
f.write(template_string)
print("pkg_match entries: ", len(pkg_match))
print("pkg_only_hunter entries: ", len(pkg_only_hunter))