-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathBuildHHP.py
126 lines (110 loc) · 3.71 KB
/
BuildHHP.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import os
import sys
import glob
import shutil
"""
BuildHHP.py
Build HTML Help project file.
"""
sHHPFormat = """
[OPTIONS]
Binary TOC=Yes
Compatibility=1.1 or later
Compiled file=%(output)s.chm
Contents file=%(output)s.hhc
Default Window=Home
Default topic=%(target)s.HTML
Display compile progress=Yes
Full-text search=Yes
Index file=%(output)s.hhk
Language=0x409 English (United States)
[WINDOWS]
Home="%(target)s","%(target)s.hhc","%(target)s.hhk","%(target)s.HTML","%(target)s.HTML",,,,,0x63520,,0x387e,,,,,,2,,0
[FILES]
%(output)s.HTML
%(html_files)s
[INFOTYPES]
"""
def handle_globs(lGlobs):
assert lGlobs, "you must pass some patterns!"
lFiles = []
for g in lGlobs:
new = glob.glob(g)
if len(new) == 0:
print(("The pattern '%s' yielded no files!" % (g,)))
lFiles = lFiles + new
# lFiles is now the list of origin files.
# Normalize all of the paths:
cFiles = len(lFiles)
for i in range(cFiles):
lFiles[i] = os.path.normpath(lFiles[i])
# If it isn't a file, ignore it.
i = 0
while i < cFiles:
if not os.path.isfile(lFiles[i]):
del lFiles[i]
cFiles = cFiles - 1
continue
i = i + 1
# Find the common prefix of all of the files
sCommonPrefix = os.path.commonprefix(lFiles)
# Damn - more commonprefix problems
# "win32com" and "win32comext" appear, screwing things :-(
if sCommonPrefix[-1] not in "\\/":
# No trailing slash - the common prefix is not always used as a path
# (eg, "win32com/" vs "win32comext/"
sCommonPrefix = os.path.split(sCommonPrefix)[0]
sCommonPrefix = os.path.normpath(sCommonPrefix) + "\\"
# else we have a trailing slash - it means we _expect_ it to be a patch
# as-is.
assert os.path.isdir(sCommonPrefix) and sCommonPrefix[
-1] == "\\", "commonprefix splitting aint gunna work!"
print(("sCommonPrefix=", sCommonPrefix))
# Ok, now remove this common prefix from every file:
lRelativeFiles = []
for file in lFiles:
lRelativeFiles.append(file[len(sCommonPrefix):])
return (lRelativeFiles, lFiles)
import document_object
def main():
doc = document_object.GetDocument()
output = os.path.abspath(sys.argv[1])
target = sys.argv[2]
f = open(output + ".hhp", "w")
html_files = ""
if len(sys.argv) > 2:
# sys.argv[3] == html_dir
# sys.argv[4:] == html_files (globbed)
output_dir = os.path.abspath(sys.argv[3])
html_dir = os.path.abspath(os.path.join(output_dir, "html"))
if not os.path.isdir(html_dir):
os.makedirs(html_dir)
lGlobs = sys.argv[4:]
lDestFiles, lSrcFiles = handle_globs(lGlobs)
# ensure HTML Help build directory exists.
try:
os.makedirs(html_dir)
except:
pass
# copy files into html_dir
for i in range(len(lDestFiles)):
file = lDestFiles[i]
file = os.path.join(html_dir, file)
# ensure any directories under html_dir get created.
try:
os.makedirs(os.path.split(file)[0])
except:
pass
shutil.copyfile(lSrcFiles[i], file)
for file in lDestFiles:
html_files = html_files + '%s\\%s\n' % (html_dir, file)
for cat in doc:
html_files = html_files + '%s\\%s.html\n' % (output_dir, cat.id)
for suffix in "_overview _modules _objects _constants".split():
html_files = html_files + \
'%s\\%s%s.html\n' % (output_dir, cat.id, suffix)
f.write(sHHPFormat % {"output": output, "target": target,
"html_files": html_files})
f.close()
if __name__ == "__main__":
main()