1 from __future__
import print_function
2 import xml.dom.minidom
as dom
3 import sys, os, optparse
7 OptionParser is main class to parse options. 10 optparse.OptionParser.__init__(self, usage=
"%prog --help or %prog [options] file", version=
"%prog 0.0.1", conflict_handler=
"resolve")
11 self.add_option(
"--src", action=
"store", type=
"string", dest=
"src", help=
"specify source XML file")
12 self.add_option(
"--min", action=
"store", type=
"int", dest=
"min", help=
"Minimum length to measure")
13 self.add_option(
"--max", action=
"store", type=
"int", dest=
"max", help=
"Maximum length to measure")
14 self.add_option(
"--cid", action=
"store", type=
"int", dest=
"cid", help=
"Apply combination ID")
15 self.add_option(
"--xsd", action=
"store_true", dest=
"xsd", help=
"Create XML Schema fragment")
18 print(
"Reading histogram file")
20 histos = srcdoc.getElementsByTagName(
"Histogram")
23 for key
in histo.childNodes:
24 if key.nodeType == key.ELEMENT_NODE:
26 value = key.childNodes[0].nodeValue
29 if name
not in elements:
30 elements[name] = {
'type':
'',
'count': 0}
31 elements[name][
'count'] = elements[name][
'count'] + 1
35 if elements[name][
'type'] ==
'':
36 elements[name][
'type'] =
'xs:integer' 40 if elements[name][
'type']
in (
'',
'xs:integer'):
41 elements[name][
'type'] =
'xs:double' 43 elements[name][
'type'] =
'xs:string' 46 if keys[k][
'name'] == name
and keys[k][
'value'] == value:
47 keys[k][
'count'] = keys[k][
'count'] + 1
52 keys[n] = {
'name': name,
'value': value,
'count': 1}
60 name = keys[k][
'name']
62 root = resdoc.createElement(
"xs:complexType")
63 root.setAttribute(
"name",
"HistogramType")
64 resdoc.appendChild(root)
65 seq = resdoc.createElement(
"xs:all")
67 for e
in sorted(elements.keys()):
68 el = resdoc.createElement(
"xs:element")
69 el.setAttribute(
"name", e)
70 el.setAttribute(
"type", elements[e][
'type'])
71 if elements[e][
'count'] < len(histograms):
72 el.setAttribute(
"minOccurs",
'0')
73 el.setAttribute(
"maxOccurs",
'1')
78 print(
"Declaration to apply:", co)
80 print(keys[k][
'name'],
'=', keys[k][
'value'])
99 for i
in range(vfrom, vto):
100 for j
in range(i, vto):
102 if len(queue) >= min
and len(queue) <= max:
107 print(
"Computing permutations")
120 for ci
in comb.keys():
129 if __name__ ==
"__main__":
132 (opts, args) = optManager.parse_args()
135 if opts[
'src']
in (
'',
None):
136 print(
"You must specify a valid source xml file")
139 resdoc = dom.Document()
140 srcdoc = dom.parse(opts[
'src'])
153 if opts[
'xsd'] !=
None:
156 print(resdoc.toprettyxml())
161 if len(h) > len_max: len_max = len(h)
162 if len(h) < len_min: len_min = len(h)
163 print(
"Computed len: min = ", len_min,
", max = ", len_max)
166 if opts[
'min']
not in (0,
None): min = opts[
'min']
168 if opts[
'max']
not in (0,
None): max = opts[
'max']
169 print(
"Computing lens from", min,
" to ", max)
174 for pi
in sorted(prior.keys()):
175 print(pi,
"=", prior[pi])
177 if opts[
'cid'] !=
None:
def kpermutation(vfrom, vto, min, max)
S & print(S &os, JobReport::InputFile const &f)
def create_declaration(cid)