3 import xml.etree.ElementTree
4 from xml.dom
import minidom
9 root = xml.etree.ElementTree.parse(sys.argv[1]).getroot()
12 for pv
in root.iter(
'physvol'):
14 posname = pv.find(
'positionref').attrib[
'ref']
16 posinfo = re.split(
r'(\d+)in', posname.strip())
17 pvname = posinfo[0] + posinfo[1]
20 pv.attrib[
'name'] = pvname
23 for lv
in root.iter(
'volume'):
24 if not 'Sensor' in lv.attrib[
'name']:
27 element = xml.etree.ElementTree.SubElement(lv,
'auxiliary')
28 element.set(
'auxtype',
'SensDet')
29 element.set(
'auxvalue', lv.attrib[
'name'])
32 rough_string = xml.etree.ElementTree.tostring(root,
'utf-8')
33 reparsed_string = minidom.parseString(rough_string).toprettyxml(indent =
' ', newl =
'\n', encoding =
'utf-8')
36 final_string =
'\n'.
join(line
for line
in reparsed_string.split(
'\n')
if line.strip())
39 fout =
open(sys.argv[2],
'w')
40 fout.write(final_string)