1
2
3
4
5
6
7
8
9
10
11
12
13 """
14 Locate the correct xml map file given:
15 - Interchange Control Version Number (ISA12)
16 - Functional Identifier Code (GS01)
17 - Version / Release / Industry Identifier Code (GS08)
18 - Transaction Set Purpose Code (BHT02) (For 278 only)
19 """
20
21 import libxml2
22 import errors
23
24 NodeType = {'element_start': 1, 'element_end': 15, 'attrib': 2, 'text': 3, 'CData': 4, 'entity_ref': 5, 'entity_decl':6, 'pi': 7, 'comment': 8, 'doc': 9, 'dtd': 10, 'doc_frag': 11, 'notation': 12}
25
27 """
28 Interface to the maps.xml file
29 """
31 """
32 @param map_index_file: Absolute path of maps.xml
33 @type map_index_file: string
34 """
35 self.maps = []
36 tspc = None
37 try:
38 reader = libxml2.newTextReaderFilename(map_index_file)
39 except:
40 raise errors.EngineError, 'Map file not found: %s' % (map_index_file)
41
42 while reader.Read():
43
44 if reader.NodeType() == NodeType['element_start'] and reader.Name() == 'version':
45 while reader.MoveToNextAttribute():
46 if reader.Name() == 'icvn':
47 icvn = reader.Value()
48
49 if reader.NodeType() == NodeType['element_end'] and reader.Name() == 'version':
50 icvn = None
51
52 if reader.NodeType() == NodeType['element_start'] and reader.Name() == 'map':
53 file_name = ''
54 while reader.MoveToNextAttribute():
55 if reader.Name() == 'vriic':
56 vriic = reader.Value()
57 elif reader.Name() == 'fic':
58 fic = reader.Value()
59 elif reader.Name() == 'tspc':
60 tspc = reader.Value()
61
62 if reader.NodeType() == NodeType['element_end'] and reader.Name() == 'map':
63 self.maps.append((icvn, vriic, fic, tspc, file_name))
64 vriic = None
65 fic = None
66 tspc = None
67 file_name = None
68
69 if reader.NodeType() == NodeType['text']:
70 file_name = reader.Value()
71
72
73 - def add_map(self, icvn, vriic, fic, tspc, map_file):
74 self.maps.append((icvn, vriic, fic, tspc, map_file))
75
77 """
78 @rtype: string
79 """
80 for a in self.maps:
81 if a[0] == icvn and a[1] == vriic and a[2] == fic \
82 and (tspc is None or a[3] == tspc):
83 return a[4]
84 return None
85
87 for a in self.maps:
88 print a[0], a[1], a[2], a[3], a[4]
89