forked from openshift/openshift-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeBuild.py
executable file
·144 lines (110 loc) · 4.63 KB
/
makeBuild.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import sys
import os
import logging
from lxml.etree import XMLSyntaxError, XIncludeError
from aura import cli, utils
from aura.exceptions import InvalidInputException
from aura.transformers.tf_asciidoc import AsciiDocPublicanTransformer, XML_NS, LXML_XML_NS
#branch = os.system("git symbolic-ref -q --short HEAD")
#print(branch)
# list of books - CHANGE HERE
book_list = ['admin_guide', 'apb_devel', 'architecture',
'creating_images', 'day_two_guide', 'dev_guide',
'getting_started', 'install_config', 'release_notes', 'scaling_performance',
'security', 'upgrading', 'using_images']
# function to convert XML ids to HTML 4 compatible ids from ccutil
def _fix_ids_for_html4(tree):
"""
Fixes any id elements that aren't html4 compatible.
:param tree:
"""
xmlroot = tree.getroot()
namespaces = {'xml': XML_NS}
# Find all the elements with an id
id_eles = xmlroot.findall(".//*[@xml:id]", namespaces=namespaces)
ids = []
# Filter the elements that start with an underscore
underscore_id_eles = []
for ele in id_eles:
id_val = ele.get(LXML_XML_NS + 'id')
if id_val.startswith("_"):
underscore_id_eles.append(ele)
else:
ids.append(id_val)
# Get the linkend and endterm eles
old_linkend_eles = xmlroot.findall(".//*[@linkend]")
old_endterm_eles = xmlroot.findall(".//*[@endterm]")
# Fix each underscore id
for id_ele in underscore_id_eles:
id_val = id_ele.get(LXML_XML_NS + 'id')
# Remove the underscore and if it now starts with a number, change the number to a word
new_id = utils.create_xml_id(id_val)
# Make sure the new id is unique, by adding a number to the end
base_new_id = new_id
count = 0
while new_id in ids:
count += 1
new_id = base_new_id + "-" + str(count)
# Set the new id
if new_id != id_val:
ids.append(new_id)
id_ele.set(LXML_XML_NS + 'id', new_id)
id_ele.set("remap", id_val)
# update any old references
for old_linkend in old_linkend_eles:
if old_linkend.get("linkend") == id_val:
old_linkend.set('linkend', new_id)
for old_endterm in old_endterm_eles:
if old_endterm.get("endterm") == id_val:
old_endterm.set('endterm', new_id)
# all validated?
all_validated = True
# Initialize logging
cli.init_logging(False, False)
for distro in os.listdir("drupal-build"):
print("---------------------------------------")
print("BUILDING " + distro + " BOOKS")
print("---------------------------------------")
for book in os.listdir(os.path.join("drupal-build", distro)):
#print(os.getcwd() + "\n")
#if not os.path.isdir("drupal-build/" + distro + "/" + book):
#print("---------------------------------------")
#print(">>> No Book " + book + " in this repo. Skipping <<<")
#print("---------------------------------------")
#continue
# rest api book is a pain and doesn't convert well
if book == "rest_api":
continue
os.chdir("drupal-build/" + distro + "/" + book)
#print(os.getcwd() + "\n")
# Create the transformer instance
transformer = AsciiDocPublicanTransformer()
try:
# Transform the AsciiDoc to DocBook XML
print(">>> Working on " + book + " book in " + distro + " <<<")
if not transformer._build_docbook_src("master.adoc", "build"):
print("Could not transform book " + book)
all_validated = False
continue
# Parse the transformed XML
transformer._before_xml_parse("build/master.xml")
# Parse the XML content
tree = utils.parse_xml("build/master.xml")
# Apply XML updates from aura/ccutil
transformer._fix_uncoverted_xrefs_with_file_paths(tree)
_fix_ids_for_html4(tree)
# Validate the transformed XML
if not transformer._validate_docbook_idrefs(tree):
logging.error(">>> Validation of book " + book + " in " + distro + " failed <<<")
all_validated = False
except (XMLSyntaxError, XIncludeError, InvalidInputException) as e:
logging.error(e)
all_validated = False
finally:
print(">>> Finished with " + book + " book in " + distro + " <<<")
print("---------------------------------------")
os.chdir("../../../")
if not all_validated:
sys.exit(-1)
else:
print("All Successful")