Message: Shifted some stuff around
Commit: f811f6988d54d4b6ad26eff01ede5144ea20d2ef
Date: Tue Apr 26 13:20:54 2011 -0400
Author: Erik Zawadzki <
e...@cs.cmu.edu>
|
1 |
import xml.dom.minidom as xml |
|
2 |
|
|
3 |
def findNode(dom,path_list): |
|
4 |
current = dom |
|
5 |
for n in path_list: |
|
6 |
current = current.getElementsByTagName(n).item(0) |
|
7 |
return current |
|
8 |
|
|
9 |
def getNodeText(node): |
|
10 |
if node.firstChild.nodeType == node.TEXT_NODE: |
|
11 |
return str(node.firstChild.data) |
|
12 |
return '' |
|
13 |
|
|
14 |
def getText(dom, path): |
|
15 |
node = findNode(dom,path) |
|
16 |
return getNodeText(node) |
|
17 |
|
|
18 |
def getNumber(dom, path): |
|
19 |
node = findNode(dom,path) |
|
20 |
return int(getNodeText(node)) |
|
21 |
|
|
22 |
def getNumberList(dom, path): |
|
23 |
node = findNode(dom,path) |
|
24 |
list_text = getNodeText(node) |
|
25 |
return map(float, list_text.split(',')) |
|
26 |
|
|
27 |
def getChildren(dom, path): |
|
28 |
curr = findNode(dom,path) |
|
29 |
return curr.childNodes |
|
30 |
|
|
31 |
def getAttrList(dom, path): |
|
32 |
curr = findNode(dom,path) |
|
33 |
Attr={} |
|
34 |
for c in curr.childNodes: |
|
35 |
if c.hasChildNodes(): |
|
36 |
Attr[c.nodeName] = getText(dom, path + [c.nodeName]) |
|
37 |
return Attr |
|
38 |
|
|
39 |
def getFunction(dom,path): |
|
40 |
node = findNode(dom,path) |
|
41 |
(module_name, sep, function_name) = getNodeText(node).rpartition('.') |
|
42 |
module = __import__(module_name) |
|
43 |
func = getattr(module, function_name) |
|
44 |
return func |
| 1 |
1 |
import xml.dom.minidom as xml |
| 2 |
|
from xmlz import * |
|
2 |
from XMLWrap import * |
| 3 |
3 |
import sys |
| 4 |
4 |
import MicroTemplate as mt |
| 5 |
5 |
|
| 8 |
8 |
print 'Usage: python generator.py <XML config file>' |
| 9 |
9 |
quit() |
| 10 |
10 |
|
|
11 |
# Parse the XML file |
| 11 |
12 |
dom = xml.parse(sys.argv[1]) |
| 12 |
13 |
|
|
14 |
# Generate the PAO file |
| 13 |
15 |
pao_h_template = getText(dom, ['pao_h']) |
| 14 |
16 |
pao_cpp_template = getText(dom, ['pao_cpp']) |
| 15 |
17 |
pao_sub = getAttrList(dom, ['pao_args']) |
| 17 |
19 |
mt.rewrite(pao_sub, pao_h_template, 'gen_pao.h') |
| 18 |
20 |
mt.rewrite(pao_sub, pao_cpp_template, 'gen_pao.cpp') |
| 19 |
21 |
|
|
22 |
# Generate the Mapper file |
| 20 |
23 |
mapper_h_template = getText(dom, ['mapper_h']) |
| 21 |
24 |
mapper_cpp_template = getText(dom, ['mapper_cpp']) |
| 22 |
25 |
mapper_sub = getAttrList(dom, ['mapper_args']) |
| 1 |
|
import xml.dom.minidom as xml |
| 2 |
|
|
| 3 |
|
def findNode(dom,path_list): |
| 4 |
|
current = dom |
| 5 |
|
for n in path_list: |
| 6 |
|
current = current.getElementsByTagName(n).item(0) |
| 7 |
|
return current |
| 8 |
|
|
| 9 |
|
def getNodeText(node): |
| 10 |
|
if node.firstChild.nodeType == node.TEXT_NODE: |
| 11 |
|
return str(node.firstChild.data) |
| 12 |
|
return '' |
| 13 |
|
|
| 14 |
|
def getText(dom, path): |
| 15 |
|
node = findNode(dom,path) |
| 16 |
|
return getNodeText(node) |
| 17 |
|
|
| 18 |
|
def getNumber(dom, path): |
| 19 |
|
node = findNode(dom,path) |
| 20 |
|
return int(getNodeText(node)) |
| 21 |
|
|
| 22 |
|
def getNumberList(dom, path): |
| 23 |
|
node = findNode(dom,path) |
| 24 |
|
list_text = getNodeText(node) |
| 25 |
|
return map(float, list_text.split(',')) |
| 26 |
|
|
| 27 |
|
def getChildren(dom, path): |
| 28 |
|
curr = findNode(dom,path) |
| 29 |
|
return curr.childNodes |
| 30 |
|
|
| 31 |
|
def getAttrList(dom, path): |
| 32 |
|
curr = findNode(dom,path) |
| 33 |
|
Attr={} |
| 34 |
|
for c in curr.childNodes: |
| 35 |
|
if c.hasChildNodes(): |
| 36 |
|
Attr[c.nodeName] = getText(dom, path + [c.nodeName]) |
| 37 |
|
return Attr |
| 38 |
|
|
| 39 |
|
def getFunction(dom,path): |
| 40 |
|
node = findNode(dom,path) |
| 41 |
|
(module_name, sep, function_name) = getNodeText(node).rpartition('.') |
| 42 |
|
module = __import__(module_name) |
| 43 |
|
func = getattr(module, function_name) |
| 44 |
|
return func |