axis_examplecompt_changesinfo-opsversion-1.30version-2.00version-3.01version-3.02
Last change
on this file since 01073f7 was
7c3008e,
checked in by Ted Faber <faber@…>, 16 years ago
|
checkpoint
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | #!/usr/bin/python -u |
---|
2 | import libxml2 |
---|
3 | |
---|
4 | class federated_visualization: |
---|
5 | class callback: |
---|
6 | def __init__(self): |
---|
7 | self.result = { }; |
---|
8 | self.row = { }; |
---|
9 | self.node_fields = set(["name", "x", "y", "type"]); |
---|
10 | self.float_fields = set(["x", "y"]); |
---|
11 | self.last_chars = ""; |
---|
12 | pass |
---|
13 | |
---|
14 | def startDocument(self): |
---|
15 | pass |
---|
16 | |
---|
17 | def endDocument(self): |
---|
18 | pass |
---|
19 | |
---|
20 | def startElement(self, tag, attrs): |
---|
21 | if tag == "node": |
---|
22 | self.row = {} |
---|
23 | pass |
---|
24 | |
---|
25 | def endElement(self, tag): |
---|
26 | if tag == "node": |
---|
27 | self.result[self.row["name"]] = self.row; |
---|
28 | elif tag in self.node_fields: |
---|
29 | if tag in self.float_fields: |
---|
30 | self.row[tag] = float(self.last_chars); |
---|
31 | else: |
---|
32 | self.row[tag] = self.last_chars; |
---|
33 | pass |
---|
34 | pass |
---|
35 | |
---|
36 | def characters(self, data): |
---|
37 | self.last_chars = data; |
---|
38 | pass |
---|
39 | |
---|
40 | def warning(self, msg): |
---|
41 | print "Warning: %s!" % msg |
---|
42 | pass |
---|
43 | |
---|
44 | def error(self, msg): |
---|
45 | print "Error: %s!" % msg |
---|
46 | pass |
---|
47 | |
---|
48 | def fatalError(self, msg): |
---|
49 | global log |
---|
50 | print "fatalError: %s:" % (msg) |
---|
51 | |
---|
52 | def __init__(self, file): |
---|
53 | self.handler = self.callback() |
---|
54 | self.result = { }; |
---|
55 | libxml2.SAXParseFile(self.handler, file, 0); |
---|
56 | self.result = self.handler.result; |
---|
57 | libxml2.cleanupParser() |
---|
58 | pass |
---|
59 | pass |
---|
60 | |
---|
61 | if __name__ == "__main__": |
---|
62 | import sys; |
---|
63 | parse = federated_visualization(sys.argv[1]); |
---|
64 | print parse.result |
---|
65 | pass |
---|
Note: See
TracBrowser
for help on using the repository browser.