6
# table_type is a synonym to storage_engine
7
OPTIONS_TO_IGNORE = ["default-table-type", "new"]
9
sdoc = xml.dom.minidom.parse("structure.xml")
15
#===============================================================================
16
# Create structure first
17
def parse_configuration(sec):
18
for node in sec.childNodes:
19
if xml.dom.Node.ELEMENT_NODE == node.nodeType:
20
if node.tagName == "tab":
21
tab = (node.getAttribute("caption"), node.getAttribute("description"), [], {})
24
tabs[node.getAttribute("caption")] = tab
26
for group in node.childNodes:
27
if xml.dom.Node.ELEMENT_NODE == group.nodeType:
28
if group.tagName == "group":
30
groups.append((group.getAttribute('caption'), grp))
31
groups_map[group.getAttribute('caption')] = grp
33
for sec in sdoc.documentElement.getElementsByTagName('section'):
34
if sec.getAttribute("class") == "mycnf":
35
parse_configuration(sec)
38
misc_tab = ('Misc', 'Uncategorized', [('Misc', misc_grp)], {'Misc':misc_grp})
39
tabs['Misc'] = misc_tab
40
tabs_list.append(misc_tab)
42
#-------------------------------------------------------------------------------
43
def get_group(collection, group):
47
coll = tabs[collection]
50
print collection, group
54
#===============================================================================
55
# read controls/options
56
doc = xml.dom.minidom.parse('mysqld_new.xml')
58
#-------------------------------------------------------------------------------
59
def parse_ui_section(name, sec):
62
if sec.getAttribute('class') == "mycnf":
63
uis['class'] = "mycnf"
64
uis['collection'] = sec.getAttribute('collection')
65
uis['group'] = sec.getAttribute('group')
66
for node in sec.childNodes:
67
if xml.dom.Node.ELEMENT_NODE == node.nodeType:
68
if node.tagName == "caption":
69
uis['caption'] = node.getAttribute('value')
70
elif node.tagName == "description":
71
uis['description'] = node.getAttribute('value')
72
elif node.tagName == "type":
73
utype = node.getAttribute('value')
74
unitcontrol = node.getAttribute('unitcontrol')
76
uis['unitcontrol'] = unitcontrol
77
udefault = node.getAttribute('default')
78
uis['default'] = udefault
81
for n in node.getElementsByTagName('value'):
82
if n.nodeType == xml.dom.Node.ELEMENT_NODE:
83
for i in range(len(n.attributes)):
84
attr = n.attributes.item(i)
85
uis[attr.name] = attr.value
87
if utype == 'dropdownbox':
88
style = node.getAttribute('style')
90
uis['type'] = 'dropdownboxentry'
92
pysrc = node.getElementsByTagName('pysource')
94
srcid = pysrc[0].getAttribute('sourceid')
95
uis['choices'] = srcid
97
for n in node.childNodes:
98
if xml.dom.Node.ELEMENT_NODE == n.nodeType:
99
if n.tagName == 'choice':
100
choices.append((n.getAttribute('caption'), n.getAttribute('value')))
101
uis['choices'] = choices
103
# sys.stderr.write("Fix script: unhandled overriden type " + utype + "\n")
108
#-------------------------------------------------------------------------------
109
def parse_ui(name, ui_node):
111
for node in ui_node.childNodes:
112
if xml.dom.Node.ELEMENT_NODE == node.nodeType:
113
if node.tagName == "section":
114
uis = parse_ui_section(name, node)
115
ui[uis['class']] = uis
119
#-------------------------------------------------------------------------------
120
def add_variable(var, oclass, section, scope, versions, description):
121
#if scope == 'session':
124
# Prepare description
125
description = description.replace('\n', '')
127
new_description = description.replace(' ', ' ')
128
if new_description == description:
130
description = new_description
132
description = description.replace('\'', '\\\'')
133
res = re.search('<shortdescription>(.+)</shortdescription>', description)
135
description = res.groups()[0].strip(' ')
138
if oclass not in variables:
139
variables[oclass] = {}
140
cls = variables[oclass]
142
if section not in cls:
148
names = ('var', 'versions', 'description')
152
if value is not None:
153
if type(value) is not tuple:
154
lines.append(name + "='" + str(value) + "'")
156
lines.append(name + "=" + str(value))
158
lines.append(name + "=None")
159
sec.append("Option(" + ' ,'.join(lines) + ")")
161
#-------------------------------------------------------------------------------
162
def parse_versions(versions_node):
164
for node in versions_node.childNodes:
165
if xml.dom.Node.ELEMENT_NODE == node.nodeType:
166
if node.tagName == "manual" or node.tagName == 'introduced':
167
version_str = node.getAttribute('version')
170
tokens = re.match("([0-9]+)\.([0-9]+)\.([0-9]+)|([0-9]+)\.([0-9]+)", version_str).groups()
171
if tokens[0] is not None:
172
version = (int(tokens[0]), int(tokens[1]), int(tokens[2]))
174
version = (int(tokens[3]), int(tokens[4]))
176
except ValueError, e:
177
print "ERROR! incorrect version attribute value '" + version_str + "', ", type(version_str)
183
for i in range(0, len(vers)-1):
185
if vers[i][0:2] == vers[i+1][0:2]:
186
res.append(max(vers[i], vers[i+1]))
197
#-------------------------------------------------------------------------------
198
def parse_opt_values(name, node):
201
for i in range(len(node.attributes)):
202
attr = node.attributes.item(i)
204
if aname == 'vartype':
207
if avalue == 'enumeration':
208
avalue = 'dropdownbox'
216
if optype == 'numeric' or optype == 'string' or optype == 'boolean' or optype == 'filename':
217
for n in node.childNodes:
218
if xml.dom.Node.ELEMENT_NODE == n.nodeType:
219
for i in range(len(n.attributes)):
220
attr = n.attributes.item(i)
221
opt[attr.name] = attr.value
222
elif optype == 'dropdownbox':
224
for n in node.childNodes:
225
if xml.dom.Node.ELEMENT_NODE == n.nodeType:
226
for i in range(len(n.attributes)):
227
attr = n.attributes.item(i)
228
if attr.name == 'value':
229
choices.append((attr.value, attr.value))
230
elif attr.name == 'default':
231
opt['default'] = attr.value
232
opt['choices'] = choices
234
sys.stderr.write("Unhandled " + optype + " in " + name + "\n")
240
#-------------------------------------------------------------------------------
241
for option in doc.documentElement.getElementsByTagName('mysqloption'):
251
optid = option.getAttribute('id')
252
optsection = option.getAttribute('section')
254
for node in option.getElementsByTagName('shortdescription'):
255
shortdesc += node.firstChild.data.encode('ascii')
259
for node in option.getElementsByTagName('optype'):
260
if node.getAttribute('class') == 'mycnf':
261
name = node.getAttribute('format') # Try to pick name from optype tag's attribute
262
split_name = name.split("=")
263
if len(split_name) > 0:
264
name = split_name[0].strip(" \r\t\n")
267
for node in option.getElementsByTagName('vartype'):
268
varcls = node.getAttribute('class')
269
varscope = node.getAttribute('scope')
270
nm = node.getAttribute('format') # Try to pick name from optype tag's attribute
271
nm = nm.strip(' \r\n\t')
272
if nm != '' or nm is not None:
279
if variable_name is None or variable_name == '':
280
variable_name = optid
282
if name in OPTIONS_TO_IGNORE:
285
for node in option.childNodes:
286
if xml.dom.Node.ELEMENT_NODE == node.nodeType:
287
if node.tagName == "name":
288
nm = node.firstChild.data.encode('ascii')
291
if variable_name == "":
293
elif node.tagName == "values":
295
optype = parse_opt_values(name, node)
296
elif node.tagName == "versions":
297
versions = parse_versions(node)
298
elif node.tagName == "ui":
299
ui = parse_ui(name, node)
302
add_variable(variable_name, varcls, optsection, varscope, versions, shortdesc)
304
# if is_opt and optype is None and ui is None:
310
if 'type' not in optype:
311
optype['type'] = 'string'
313
optype['name'] = name
314
optype['versions'] = versions
318
for k,v in uiopt.iteritems():
319
if 'collection' != k and 'class' != k and 'group' != k and 'platform' != k:
322
grp = get_group(uiopt['collection'], uiopt['group'])
325
optype['caption'] = name
326
optype['description'] = " "
328
grp = get_group('Misc', 'Misc')
332
#===============================================================================
336
f = open('opts.py', 'w')
338
def build_group(name, group, ind):
339
grp = "{'caption' : \"" + name + "\",\n"
340
grp += ind + "'controls':\n" + ind + " (\n"
342
single = len(group) == 1
347
for k,v in optype.iteritems():
350
if optype['type'] == 'dropdownbox' or optype['type'] == 'dropdownboxentry':
351
line = ind + " 'items' : {"
353
for caption, value in v:
354
items.append("\"" + caption + "\":\"" + value + "\"")
355
line += ", ".join(items) + "}"
358
if type(v) is not tuple:
359
lines.append(ind + " '" + k + "' : \"" + str(v) + "\"")
361
lines.append(ind + " '" + k + "' : " + str(v))
363
ctrl += ",\n".join(lines)
367
grp += (",\n").join(ctrls)
371
grp += ind + " ) #End of controls list in group " + name + "\n"
372
grp += ind + "} #End of group " + name + "\n"
375
f.write("opts_list = {\n")
377
for (pos, (tab_name,tab_desc, groups, groups_map)) in enumerate(tabs_list):
378
text = ind + "'" + tab_name + "' : { '"
379
indent = " "*len(text)
380
text += "description' : \"" + tab_desc + "\",\n"
381
text += indent + " 'position' : " + str(pos+1) + ",\n"
383
single_group = len(groups) == 1
385
group_text_list.append(build_group(group[0], group[1], indent + " "))
386
text += indent + " 'groups':( "
387
text += (indent + " ,").join(group_text_list)
389
text += indent + " ,"
390
text += indent + " ) # end of groups in tab " + tab_name + "\n"
391
text += indent + "} # end of tab " + tab_name +"\n"
392
tab_text.append(text)
394
f.write((ind + ",").join(tab_text) + "\n")
395
f.write("} #End of opts_list\n")
398
# Write out variables
399
f = open('wb_admin_variable_list.py', 'w')
401
def generate_Option_class(fields):
402
cls = 'class Option:\n'
403
cls += ' def __init__(self, ' + ', '.join(fields) + "):\n"
405
cls += ' self.' + field + " = " + field + "\n"
407
cls += ' def __repr__(self):\n'
409
cls += ' for attr in dir(self):\n'
410
cls += ' if attr[0] == \'_\':\n'
413
cls += ' s.append("\'" + attr + "\':" + str(getattr(self, attr)))\n'
414
cls += ' return \'(\' + (\',\'.join(s)) + \')\'\n'
418
f.write(generate_Option_class(('var', 'versions', 'description')))
420
f.write('vars_list = {\n')
422
for cn, cv in variables.iteritems():
423
cls = "'" + cn + "' : {\n"
425
for sn, sv in cv.iteritems():
426
if sn is None or sn == '':
428
sn = sn[0].upper() + sn[1:]
429
section = "'" + sn + "' : (\n"
435
section += ' ,'.join(vs)
438
section += " ) # End of section " + sn + "\n"
439
sections.append(section)
440
cls += " " + (" ,".join(sections))
441
cls += " } # End of class " + cn + "\n"
443
f.write(" ,".join(classes))
445
f.write('} # End of \n')