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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
|
#!/usr/bin/python
import xml.dom.minidom
import re
import pprint
import missing_info
skip_list = set(['version', 'help', 'license', 'version_comment', 'version_compile_machine', 'version_compile_os'])
# variables that should be also treated as mycnf options
mycnf_vars = ['old_passwords',
'validate_password_dictionary_file',
'validate_password_length',
'validate_password_mixed_case_count',
'validate_password_number_count',
'validate_password_policy_number',
'validate_password_special_char_count']
# table_type is a synonym to storage_engine
OPTIONS_TO_IGNORE = ["default-table-type", "new"]
doc = xml.dom.minidom.parse('mysqld.xml')
opts = []
sys_vars = []
stat_vars = []
stat_var_sections = []
bool_tuples = (('off', 'on'), ('no','yes'), ('0','1'), ('false','true'))
bool_dict = {}
for tup in bool_tuples:
bool_dict[tup[0]] = tup
bool_dict[tup[1]] = tup
tags = {}
types = {}
def count_tag(dic, tag):
if tag in dic:
dic[tag] += 1
else:
dic[tag] = 1
#-------------------------------------------------------------------------------
def parse_boolean(node, value, opt):
disabledby = None
if 'disabledby' in opt:
disabledby = opt['disabledby']
for t in node.childNodes:
if t.nodeType == t.ELEMENT_NODE:
if t.tagName == 'value':
for (aname, aval) in t.attributes.items():
if aname == 'default':
if aname in value:
print "existing bool value tag", aname, value
else:
value[str(aname)] = str(aval.lower())
else:
print "Uknown attr in value", aname, opt['name']
quit()
elif t.tagName == 'choice':
for (aname, aval) in t.attributes.items():
if aname == 'value':
if 'choice' in value:
value['choice'].append(str(aval.lower()))
else:
value['choice'] = [str(aval.lower())]
else:
print "Uknown attr in choice", aname, opt['name']
quit()
else:
print "Warning unkown tag in boolean value", aname, aval
quit()
default = None
if 'default' in value:
default = value['default'].lower()
switch = bool_dict['0'] # pick 0|1 as a default assignable items
if default in bool_dict:
switch = bool_dict[default]
if disabledby is None:
value['off'] = switch[0]
else:
value['off'] = 'disabledby'
value['on'] = switch[1]
#-------------------------------------------------------------------------------
def parse_set(node, value, opt):
parse_enumeration(node, value, opt)
value['type'] = 'set'
#-------------------------------------------------------------------------------
def parse_string(node, value, opt):
for t in node.childNodes:
if t.nodeType == t.ELEMENT_NODE:
if t.tagName == 'value':
for (aname, aval) in t.attributes.items():
if aname in value:
print "existing str value tag", aname, value
else:
value[str(aname)] = str(aval)
elif t.tagName == 'choice':
for (aname, aval) in t.attributes.items():
if aname == 'value':
if 'choice' in value:
value['choice'].append(str(aval))
else:
value['choice'] = [str(aval)]
else:
print "Uknown attr in choice", aname, opt['name']
quit()
else:
print "Warning unkown tag in boolean value", aname, aval
quit()
#-------------------------------------------------------------------------------
def parse_numeric(node, value, opt):
for t in node.childNodes:
if t.nodeType == t.ELEMENT_NODE:
if t.tagName == 'value':
for (aname, aval) in t.attributes.items():
if aname in value:
print "existing num value tag", opt.get("name"), aname, value
else:
value[str(aname)] = str(aval)
elif t.tagName == 'choice':
for (aname, aval) in t.attributes.items():
if aname == 'value':
if 'choice' in value:
value['choice'].append(str(aval))
else:
value['choice'] = [str(aval)]
else:
print "Uknown attr in choice", aname, opt['name']
quit()
else:
print "Warning unkown tag in boolean value", aname, aval
quit()
#-------------------------------------------------------------------------------
def parse_filename(node, value, opt):
for t in node.childNodes:
if t.nodeType == t.ELEMENT_NODE:
if t.tagName == 'value':
for (aname, aval) in t.attributes.items():
value[str(aname)] = str(aval)
#-------------------------------------------------------------------------------
def parse_enumeration(node, value, opt):
for t in node.childNodes:
if t.nodeType == t.ELEMENT_NODE:
if t.tagName == 'value':
for (aname, aval) in t.attributes.items():
if aname == 'default':
if aname in value:
print "existing enum value tag", aname, value
else:
value[str(aname)] = str(aval)
elif aname == 'se':
pass
else:
print "Uknown attr in value", aname, opt['name']
#quit()
elif t.tagName == 'choice':
for (aname, aval) in t.attributes.items():
if aname == 'value':
if 'choice' in value:
value['choice'].append(str(aval))
else:
value['choice'] = [str(aval)]
else:
print "Uknown attr in choice", aname, opt['name']
quit()
else:
print "Warning unkown tag in boolean value", aname, aval
quit()
value['type'] = 'enum'
#-------------------------------------------------------------------------------
def parse_bitmap(node, value, opt):
pass
#-------------------------------------------------------------------------------
def parse_date_time(node, value, opt):
pass
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
type_parsers = {'boolean':parse_boolean
,'set':parse_set
,'string':parse_string
,'numeric':parse_numeric
,'filename':parse_filename
,'dirname':parse_filename
,'enumeration':parse_enumeration
,'bitmap':parse_bitmap
,'datetime':parse_date_time
,'integer':parse_numeric
}
#-------------------------------------------------------------------------------
def parse_version_str(version_str):
version = None
try:
res = re.match("([0-9]+)\.([0-9]+)\.([0-9]+)|([0-9]+)\.([0-9]+)", version_str)
if res:
tokens = res.groups()
if tokens[0] is not None:
version = (int(tokens[0]), int(tokens[1]), int(tokens[2]))
else:
version = (int(tokens[3]), int(tokens[4]))
except ValueError:
print "ERROR! incorrect version attribute value '" + version_str + "', ", type(version_str)
return version
#-------------------------------------------------------------------------------
def parse_values(node, opt):
value = {}
for n,v in node.attributes.items():
value[str(n)] = str(v)
vartype = str(value['vartype'])
value['type'] = vartype
del value['vartype']
type_parsers[vartype](node, value, opt)
if 'platform' in value:
if value['platform'] == 'all':
del value['platform']
if 'inversion' in value:
value['inversion'] = parse_version_str(value['inversion'])
if 'outversion' in value:
value['outversion'] = parse_version_str(value['outversion'])
return value
#-------------------------------------------------------------------------------
def guess_values(opt):
name = opt['name']
values = opt['values']
if len(values) == 0:
if name[:4] == 'skip':
values.append({'off':'del', 'on':'name', 'type':'boolean'})
#-------------------------------------------------------------------------------
def parse_optype(node, option):
optype = {}
for i in node.attributes.items():
optype[str(i[0])] = str(i[1])
# make cleanup
if optype:
if 'format' in optype:
if optype['format'] == option['name']:
del optype['format']
return optype
#-------------------------------------------------------------------------------
def ver_cmp(v1, v2):
minlen = min(len(v1), len(v2))
return cmp(v1[0:minlen], v2[0:minlen])
#-------------------------------------------------------------------------------
def ver_diff(v1,v2):
return abs(reduce(lambda x,y: x*10 + y, v1) - reduce(lambda x,y: x*10 + y, v2))
#-------------------------------------------------------------------------------
def parse_versions(versions_node, option):
vers = []
removed = []
introduced = []
for node in versions_node.childNodes:
if xml.dom.Node.ELEMENT_NODE == node.nodeType:
if node.tagName == "manual":
version_str = node.getAttribute('version')
version = parse_version_str(version_str)
if version:
if len(version) > 2:
print "Error: manual version is set in x.y.z format", option
quit()
vers.append(version)
elif node.tagName == 'introduced':
version_str = node.getAttribute('version')
version = parse_version_str(version_str)
if version:
introduced.append(version)
elif node.tagName == "removed":
version_str = node.getAttribute('version')
version = parse_version_str(version_str)
if version:
removed.append(version)
vers.sort()
vers.append((0,0))
res = []
skip = False
for i in range(0, len(vers)-1):
if vers[i][0:2] == vers[i+1][0:2]:
res.append(max(vers[i], vers[i+1]))
skip = True
else:
if not skip:
res.append(vers[i])
else:
skip = False
return [tuple(introduced), tuple(res), tuple(removed)]
#-------------------------------------------------------------------------------
def parse_types(node, option):
optype = None
for t in node.childNodes:
if t.nodeType == t.ELEMENT_NODE and t.tagName == 'mycnf':
cur_optype = parse_optype(t, option)
if optype is None and cur_optype is not None:
optype = cur_optype
return optype
#-------------------------------------------------------------------------------
def parse_var_types(node, option):
for t in node.childNodes:
if t.nodeType == t.ELEMENT_NODE and t.hasAttribute('isdynamic'):
if t.getAttribute('isdynamic') not in ('yes','no'):
print "Invalid isdynamic value", t.getAttribute('isdynamic')
return t.getAttribute('isdynamic') == 'yes', t.nodeName
return None, None
#-------------------------------------------------------------------------------
def check_redundant_option(opts, optid):
if '-' in optid and optid.replace('-', '_') in [o['name'] for o in opts]:
print 'Skipped redundant option: %s'%o['name']
return True
elif '_' in optid and optid.replace('_', '-') in [o['name'] for o in opts]:
for o in opts:
if optid.replace('_', '-') == o['name']:
opts.remove(o)
print 'Removed redundant option: %s'%o['name']
return False
#-------------------------------------------------------------------------------
for option in doc.documentElement.getElementsByTagName('mysqloption'):
opt = {}
optid = str(option.getAttribute('id'))
opt['name'] = optid
opt['caption'] = optid
is_mycnf_opt = False
is_variable_dynamic = False
variable_class = None
opt['values'] = []
for t in option.getElementsByTagName('types'):
otype = parse_types(t, opt)
if otype is not None:
is_mycnf_opt = True
if len(otype) > 0:
opt['optype'] = otype
is_variable_dynamic, variable_class = parse_var_types(t, opt)
for t in option.getElementsByTagName('disabledby'):
items = t.attributes.items()
# items usually look like [('xref', 'skip-merge')] for optid 'merge'
if len(items) == 1:
items = items[0]
opt['disabledby'] = str(items[1])
else:
print "Warning: disabledby has more that one value or no values", optid, items
for node in option.childNodes:
if node.nodeType == node.ELEMENT_NODE:
if node.tagName == 'values':
ovalue = parse_values(node, opt)
opt['values'].append(ovalue)
elif node.tagName == 'versions':
opt['versions'] = parse_versions(node, opt)
elif node.tagName == 'shortdescription':
firstChild = node.firstChild
desc = firstChild.data.encode('ascii').replace("\n", "") if firstChild else ""
d1 = desc
d2 = desc.replace(' ', ' ')
while d1 != d2:
d1 = d2
d2 = d2.replace(' ', ' ')
desc = d2
opt['description'] = desc.strip(" ")
#if len(desc) > 80:
# f = open('long_desc.txt','a')
# f.write("option '" + optid + "' has long desc. " + desc + "\n")
# f.close()
elif node.tagName == 'deprecated':
version = node.getAttribute('version')
opt['deprecated'] = parse_version_str(version)
if is_mycnf_opt or optid in mycnf_vars:#or variable_class == "system":
if optid[:5] != 'maria' and optid[:6] != 'falcon' and optid[:3] != 'bdb' and (not optid in skip_list):
if not check_redundant_option(opts, optid):
opts.append(opt)
if 'values' in opt and len(opt['values']) == 0:
guess_values(opt)
elif variable_class == "system":
print "-", optid
if is_variable_dynamic is not None:
if variable_class == "system":
sys_vars.append((opt['name'], opt.get('description', ''), is_variable_dynamic))
else:
stat_vars.append((opt['name'], opt.get('description', ''), is_variable_dynamic))
stat_var_sections.append((opt['name'], option.getAttribute('section').encode('latin1')))
#-------------------------------------------------------------------------------
# Merge from missing_info
for o in opts:
missing_def = missing_info.get_def(o['name'])
if missing_def:
for k,v in missing_def.iteritems():
o[k] = v
print "Merged", missing_def
print " to", o
print "----"
for o in missing_info.non_requested:
missing_def = missing_info.get_def(o)
opts.append(missing_def)
#-------------------------------------------------------------------------------
# make list const
for o in opts:
if 'values' in o and len(o['values']) > 0:
o['values'] = values = list(o['values'])
for o in opts:
if not 'values' in o or len(o['values']) == 0:
print "Warning: option", o['name'], "has no values"
if 'skip-' in o['name']:
for opt in opts:
if o['name'][5:] == opt['name']:
for v in opt['values']:
if 'default' in v:
if v['default'].lower() in ['1', 'on', 'true', 'yes']:
print 'Removed option %s'%(opt['name'])
opts.remove(opt)
else:
print 'Removed option %s'%(o['name'])
opts.remove(o)
break
break
print "Writing to raw_opts.py..."
f = open('raw_opts.py', 'w+')
f.write("ropts = ")
pp = pprint.PrettyPrinter(indent=2, stream=f)
pp.pprint(opts)
f.close()
print "Writing to wb_admin_variable_list.py..."
f = open('raw_vars.py', 'w+')
f.write("system_vars_list =")
pp = pprint.PrettyPrinter(indent=2, stream=f)
pp.pprint(sys_vars)
f.write("\n\n")
f.write("status_vars_list =")
pp.pprint(stat_vars)
f.close()
#f = open("variable_groups.py","w+")
#pp = pprint.PrettyPrinter(indent=2, stream=f)
#pp.pprint(stat_var_sections)
#f.close()
|