-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsohsubs.py
191 lines (158 loc) · 5.86 KB
/
dsohsubs.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
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
#!/usr/bin/env python
#
# Generated Thu Oct 12 01:57:52 2017 by generateDS.py version 2.28b.
# Python 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2]
#
# Command line options:
# ('--silence', '')
# ('--external-encoding', 'utf-8')
# ('-o', '../dsr-xml-validation/dsoh.py')
# ('-s', '../dsr-xml-validation/dsohsubs.py')
#
# Command line arguments:
# ../dsr-xml-validation/Dealer Stock On Hand.xsd
#
# Command line:
# generateDS.py --silence --external-encoding="utf-8" -o "../dsr-xml-validation/dsoh.py" -s "../dsr-xml-validation/dsohsubs.py" ../dsr-xml-validation/Dealer Stock On Hand.xsd
#
# Current working directory (os.getcwd()):
# generateDS
#
import sys
from lxml import etree as etree_
import ??? as supermod
def parsexml_(infile, parser=None, **kwargs):
if parser is None:
# Use the lxml ElementTree compatible parser so that, e.g.,
# we ignore comments.
parser = etree_.ETCompatXMLParser()
doc = etree_.parse(infile, parser=parser, **kwargs)
return doc
#
# Globals
#
ExternalEncoding = 'utf-8'
#
# Data representation classes
#
class PART_STOCKSub(supermod.PART_STOCK):
def __init__(self, PART_STOCK_HEADER=None, PART_STOCK_DETAIL=None, PART_STOCK_CONTROL=None):
super(PART_STOCKSub, self).__init__(PART_STOCK_HEADER, PART_STOCK_DETAIL, PART_STOCK_CONTROL, )
supermod.PART_STOCK.subclass = PART_STOCKSub
# end class PART_STOCKSub
class PART_STOCK_DETAILSub(supermod.PART_STOCK_DETAIL):
def __init__(self, SUPP_CODE=None, DEALER_BRANCH_ID=None, PART_NO=None, QTY=None, UNIT_RRP=None, UNIT_AVG_COSTS=None):
super(PART_STOCK_DETAILSub, self).__init__(SUPP_CODE, DEALER_BRANCH_ID, PART_NO, QTY, UNIT_RRP, UNIT_AVG_COSTS, )
supermod.PART_STOCK_DETAIL.subclass = PART_STOCK_DETAILSub
# end class PART_STOCK_DETAILSub
class PART_STOCK_HEADERSub(supermod.PART_STOCK_HEADER):
def __init__(self, SESSION_ID=None, DEALER_ID=None, DATA_DATE=None, DEALER_SYSTEM=None, EXTRACTION_DATE=None):
super(PART_STOCK_HEADERSub, self).__init__(SESSION_ID, DEALER_ID, DATA_DATE, DEALER_SYSTEM, EXTRACTION_DATE, )
supermod.PART_STOCK_HEADER.subclass = PART_STOCK_HEADERSub
# end class PART_STOCK_HEADERSub
class PART_STOCK_CONTROLSub(supermod.PART_STOCK_CONTROL):
def __init__(self, TOTAL_RECORDS=None, TOTAL_QTY=None, TOTAL_SOH_VALUE=None):
super(PART_STOCK_CONTROLSub, self).__init__(TOTAL_RECORDS, TOTAL_QTY, TOTAL_SOH_VALUE, )
supermod.PART_STOCK_CONTROL.subclass = PART_STOCK_CONTROLSub
# end class PART_STOCK_CONTROLSub
def get_root_tag(node):
tag = supermod.Tag_pattern_.match(node.tag).groups()[-1]
rootClass = None
rootClass = supermod.GDSClassesMapping.get(tag)
if rootClass is None and hasattr(supermod, tag):
rootClass = getattr(supermod, tag)
return tag, rootClass
def parse(inFilename, silence=False):
parser = None
doc = parsexml_(inFilename, parser)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'xsd_double'
rootClass = supermod.xsd_double
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
## if not silence:
## sys.stdout.write('<?xml version="1.0" ?>\n')
## rootObj.export(
## sys.stdout, 0, name_=rootTag,
## namespacedef_='',
## pretty_print=True)
return rootObj
def parseEtree(inFilename, silence=False):
parser = None
doc = parsexml_(inFilename, parser)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'xsd_double'
rootClass = supermod.xsd_double
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
mapping = {}
rootElement = rootObj.to_etree(None, name_=rootTag, mapping_=mapping)
reverse_mapping = rootObj.gds_reverse_node_mapping(mapping)
## if not silence:
## content = etree_.tostring(
## rootElement, pretty_print=True,
## xml_declaration=True, encoding="utf-8")
## sys.stdout.write(content)
## sys.stdout.write('\n')
return rootObj, rootElement, mapping, reverse_mapping
def parseString(inString, silence=False):
from StringIO import StringIO
parser = None
doc = parsexml_(StringIO(inString), parser)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'xsd_double'
rootClass = supermod.xsd_double
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
## if not silence:
## sys.stdout.write('<?xml version="1.0" ?>\n')
## rootObj.export(
## sys.stdout, 0, name_=rootTag,
## namespacedef_='')
return rootObj
def parseLiteral(inFilename, silence=False):
parser = None
doc = parsexml_(inFilename, parser)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'xsd_double'
rootClass = supermod.xsd_double
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
## if not silence:
## sys.stdout.write('#from ??? import *\n\n')
## sys.stdout.write('import ??? as model_\n\n')
## sys.stdout.write('rootObj = model_.rootClass(\n')
## rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
## sys.stdout.write(')\n')
return rootObj
USAGE_TEXT = """
Usage: python ???.py <infilename>
"""
def usage():
print(USAGE_TEXT)
sys.exit(1)
def main():
args = sys.argv[1:]
if len(args) != 1:
usage()
infilename = args[0]
parse(infilename)
if __name__ == '__main__':
#import pdb; pdb.set_trace()
main()