From: Peter C. <pc...@us...> - 2010-02-03 00:21:37
|
Update of /cvsroot/ipbench/ipbench2/src In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv10643 Modified Files: ipbench.py Log Message: Changed from python-xml to elementtree, in a way that (seems to) work for python 2.5 and 2.6. Index: ipbench.py =================================================================== RCS file: /cvsroot/ipbench/ipbench2/src/ipbench.py,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** ipbench.py 13 Sep 2005 04:01:55 -0000 1.34 --- ipbench.py 3 Feb 2010 00:21:03 -0000 1.35 *************** *** 9,14 **** import select from optparse import OptionParser ! from xml import xpath ! from xml.dom.ext.reader import Sax2 options = None --- 9,13 ---- import select from optparse import OptionParser ! from xml.etree.ElementTree import parse options = None *************** *** 273,280 **** if (options.config): dbprint("Reading config from " + options.config) ! reader = Sax2.Reader() ! doc = reader.fromStream(open(options.config)) ! tests = xpath.Evaluate( "/ipbench/test", doc) if (len(tests) > 1): print "Error in config: please only have one <test> section" --- 272,279 ---- if (options.config): dbprint("Reading config from " + options.config) ! doc = parse(options.config).getroot() ! ! tests = doc.findAll('/ipbench/test') if (len(tests) > 1): print "Error in config: please only have one <test> section" *************** *** 283,302 **** # go through attributes for <test> for test in tests: ! for args in test.attributes: ! if (args.name == "name"): ! dbprint("[main] setting test from config file to " + args.value) ! options.test = str(args.value) ! if (args.name == "args"): ! dbprint("[main] setting default test args from config file to " + args.value) ! options.test_args = str(args.value) ! if (args.name == "port"): ! dbprint("[main] setting default test port from config file to " + args.value) ! options.test_port = int(args.value) ! if (args.name == "target"): ! dbprint("[main] setting default test target from config file to " + args.value) ! options.test_target = str(args.value) ! if (args.name == "controller_args"): ! dbprint("[main] setting default controller test args from config file to " + args.value) ! options.controller_args = str(args.value) # the test should be known by now --- 282,290 ---- # go through attributes for <test> for test in tests: ! options.test = str(test.get("name", None)) ! options.test_args = str(test.get('args', '')) ! options.test_port = int(test.get('port', '0')) ! options.test_target = str(test.get('target', '')) ! options.controller_args = str(test.get('controller_args', '')) # the test should be known by now *************** *** 307,311 **** # go through each <client>, override default values from attributes and add it to the # clients[] list ! data = xpath.Evaluate("client",test) for cclients in data: newclient = { --- 295,299 ---- # go through each <client>, override default values from attributes and add it to the # clients[] list ! data = doc.findAll('/ipbench/test/client') for cclients in data: newclient = { *************** *** 316,335 **** "test_target":str(options.test_target) } ! for arg in cclients.attributes: ! if (arg.name == "hostname"): ! newclient["hostname"] = arg.value ! continue ! if (arg.name == "port"): ! newclient["port"] = int(arg.value) ! continue ! if (arg.name == "test_port"): ! newclient["test_port"] = int(arg.value) ! continue ! if (arg.name == "test_args"): ! newclient["test_args"] = arg.value ! continue ! if (arg.name == "test_target"): ! newclient["test_target"] = arg.value ! continue if (newclient["hostname"] == None): print "Please specifiy a hostname for the client!" --- 304,313 ---- "test_target":str(options.test_target) } ! newclient["hostname"] = cclients.get('hostname', None) ! newclient["port"] = int(cclients.get('port', options.port)) ! newclient["test_port"] = int(cclients.get('test_port', options.test_port)) ! newclient["test_args"] = cclients.get('test_args', str(options.test_args)) ! newclient["test_target"] = cclients.get('test_target', str(options.test_target)) ! if (newclient["hostname"] == None): print "Please specifiy a hostname for the client!" *************** *** 338,358 **** #now look for the <target_test> section, add to the targets list ! target_tests = xpath.Evaluate( "/ipbench/target_test", doc) for target_test in target_tests: ! for args in target_test.attributes: ! if (args.name == "name"): ! dbprint("[main] setting target test from config file to " + args.value) ! target_test_name = args.value ! if (args.name == "args"): ! dbprintf("[main] setting target args from config file to " + args.value) ! options.target_test_args = args.value ! if (args.name == "controller_args"): ! dbprintf("[main] setting target controller args from config file to " + args.value) ! options.target_controller_args = str(args.value) ! # it is possible that there will be multiple <target_test> sections, each ! # with multiple <targets> in them. so make sure we only select those ! # targets for the target test we are currently looking at. ! tclients = xpath.Evaluate("/ipbench/target_test[@name=\'"+target_test_name+"\']/target",doc) if (not (len(tclients) > 0)): print "Please specifiy some targets in the <target_test> section!" --- 316,330 ---- #now look for the <target_test> section, add to the targets list ! target_tests = doc.FindAll("/ipbench/target_test") for target_test in target_tests: ! target_test_name = test.get('name') ! options.target_test_args = test.get('args') ! options.target_controller_args = str(test.get('controller_args')) ! # it is possible that there will be multiple <target_test> ! # sections, each with multiple <targets> in them. so ! # make sure we only select those targets for the target ! # test we are currently looking at. ! tclients = doc.findAll("/ipbench/target_test[@name=\'"+target_test_name+"\']/target") if (not (len(tclients) > 0)): print "Please specifiy some targets in the <target_test> section!" *************** *** 365,378 **** "test": str(target_test_name) #comes encoded in utf-16 } ! for arg in tclient.attributes: ! if (arg.name == "hostname"): ! newtarget["hostname"] = arg.value ! continue ! if (arg.name == "port"): ! newtarget["port"] = int(arg.value) ! continue ! if (arg.name == "test_args"): ! newtarget["test_args"] = arg.value ! continue if (newtarget["hostname"] == None): --- 337,345 ---- "test": str(target_test_name) #comes encoded in utf-16 } ! for arg in tclient.keys(): ! newtarget["hostname"] = tclient.get('hostname', ! options.target_test_hostname) ! newtarget["port"] = int(tclient.get(port, options.target_test_port)) ! newtarget["test_args"] = str(tclient.get('test_args', options.target_test_args)) if (newtarget["hostname"] == None): |