本文整理汇总了Python中xml.etree.ElementTree.SubElement.clear方法的典型用法代码示例。如果您正苦于以下问题:Python SubElement.clear方法的具体用法?Python SubElement.clear怎么用?Python SubElement.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.etree.ElementTree.SubElement
的用法示例。
在下文中一共展示了SubElement.clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mergePopulationData
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import clear [as 别名]
def mergePopulationData(populationFile, regionFile, mergedFile):
csvReader = csv.reader(open(populationFile), delimiter=',', quotechar='"')
inhabDict = {}
for entry in csvReader:
if csvReader.line_num <= 3:
continue
while(len(entry[0]) < 2):
entry[0] = '0' + entry[0]
while(len(entry[2]) < 2):
entry[2] = '0' + entry[2]
while(len(entry[3]) < 4):
entry[3] = '0' + entry[3]
while(len(entry[4]) < 3):
entry[4] = '0' + entry[4]
inhabDict["".join(entry[:5])] = str(entry[6]).replace(' ', '')
root = ET.ElementTree(file=regionFile).getroot()
for parents in root.findall("./*"):
for elem in parents.findall("param[7]"):
RSValue = str(elem.attrib)[11:23]
inhabitants = SubElement(parents, 'param')
if RSValue in inhabDict:
inhabitants.clear()
inhabitants.attrib = {
'key': "INHABITANTS", 'value': inhabDict[RSValue]}
outstr = minidom.parseString(ET.tostring(root)).toprettyxml(indent=" ")
with open(mergedFile, 'w') as out:
out.write(outstr.encode('utf-8'))
示例2: gen_project
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import clear [as 别名]
def gen_project(tree, target, script):
project_path = os.path.dirname(os.path.abspath(target))
root = tree.getroot()
out = file(target, 'wb')
out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n')
#change target name
TargetName = tree.find('Targets/Target/TargetName')
TargetName.text = buildstring
OutputName = tree.find('Targets/Target/TargetOption/TargetCommonOption/OutputName')
OutputName.text = buildstring
# add group
groups = tree.find('Targets/Target/Groups')
if groups is None:
groups = SubElement(tree.find('Targets/Target'), 'Groups')
groups.clear() # clean old groups
for group in script:
# don't add an empty group
if len(group['src']) != 0:
group_tree = add_group(groups, group['name'], group['src'], project_path)
# add GroupOption
GroupOption = SubElement(group_tree, 'GroupOption')
GroupArmAds = SubElement(GroupOption, 'GroupArmAds')
Cads = SubElement(GroupArmAds, 'Cads')
VariousControls = SubElement(Cads, 'VariousControls')
MiscControls = SubElement(VariousControls, 'MiscControls')
MiscControls.text = '--via '+opt_dir+group['name']+'.c_opts'
Aads = SubElement(GroupArmAds, 'Aads')
VariousControls = SubElement(Aads, 'VariousControls')
MiscControls = SubElement(VariousControls, 'MiscControls')
MiscControls.text = '--via '+opt_dir+group['name']+'.as_opts'
# set <OutputName>B-L475E-IOT01</OutputName>
gen_indent(root)
changeItemForMcu(tree)
projString = ModifyProjString( etree.tostring(root, encoding='utf-8') )
out.write(projString)
out.close()
示例3: MDK4Project
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import clear [as 别名]
def MDK4Project(target, script):
project_path = os.path.dirname(os.path.abspath(target))
project_uvopt = os.path.abspath(target).replace('uvproj', 'uvopt')
if os.path.isfile(project_uvopt):
os.unlink(project_uvopt)
tree = etree.parse('template.uvproj')
root = tree.getroot()
out = file(target, 'wb')
out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n')
CPPPATH = []
CPPDEFINES = []
LINKFLAGS = ''
CCFLAGS = ''
ProjectFiles = []
# add group
groups = tree.find('Targets/Target/Groups')
if groups is None:
groups = SubElement(tree.find('Targets/Target'), 'Groups')
groups.clear() # clean old groups
for group in script:
group_xml = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path)
# get each include path
if group.has_key('CPPPATH') and group['CPPPATH']:
if CPPPATH:
CPPPATH += group['CPPPATH']
else:
CPPPATH += group['CPPPATH']
# get each group's definitions
if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
if CPPDEFINES:
CPPDEFINES += group['CPPDEFINES']
else:
CPPDEFINES += group['CPPDEFINES']
# get each group's link flags
if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
if LINKFLAGS:
LINKFLAGS += ' ' + group['LINKFLAGS']
else:
LINKFLAGS += group['LINKFLAGS']
if group.has_key('LIBS') and group['LIBS']:
for item in group['LIBS']:
lib_path = ''
for path_item in group['LIBPATH']:
full_path = os.path.join(path_item, item + '.lib')
if os.path.isfile(full_path): # has this library
lib_path = full_path
if lib_path != '':
MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path)
# write include path, definitions and link flags
IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath')
IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in CPPPATH])
Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define')
Define.text = ', '.join(set(CPPDEFINES))
Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc')
Misc.text = LINKFLAGS
xml_indent(root)
out.write(etree.tostring(root, encoding='utf-8'))
out.close()
# copy uvopt file
if os.path.exists('template.uvopt'):
import shutil
shutil.copy2('template.uvopt', 'project.uvopt')
示例4: fileGeneration
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import clear [as 别名]
filename = "out"
#counts the generated files
filecont = 1
tasksArray = tasks.values()
#generating the first xml file that is the first configuration
#(all the tasks has been initialized with the first configuration
# when they are created [Task()])
filecont = fileGeneration(filecont, filename, dirname, tasksArray, xmlEdges, outputRoot, outputEdges)
#getting the task list head
result = tasksArray[0]
while result!=None:
result = tasksArray[0] #needed due to looping problems
#take the next task that can change his configuration
result = result.getNextAvailable()
if result!=None:
#change his configuration
result.setNextConfiguration()
#generating a new file by passing tasksArray and the other stuffs.
filecont = fileGeneration(filecont, filename, dirname, tasksArray, xmlEdges, outputRoot, outputEdges)
#clearing edges for the next file
outputEdges.clear()
print "[fileGenerator] Generated #", (filecont-1), "configurations in directory ", dirname
else:
print "input file does not exists"
示例5: MDK45Project
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import clear [as 别名]
def MDK45Project(tree, target, script):
project_path = os.path.dirname(os.path.abspath(target))
root = tree.getroot()
out = file(target, 'wb')
out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n')
CPPPATH = []
CPPDEFINES = []
LINKFLAGS = ''
CCFLAGS = ''
ProjectFiles = []
# add group
groups = tree.find('Targets/Target/Groups')
if groups is None:
groups = SubElement(tree.find('Targets/Target'), 'Groups')
groups.clear() # clean old groups
for group in script:
group_tree = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path)
# for local CPPPATH/CPPDEFINES
if (group_tree != None) and (group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CCFLAGS')):
GroupOption = SubElement(group_tree, 'GroupOption')
GroupArmAds = SubElement(GroupOption, 'GroupArmAds')
Cads = SubElement(GroupArmAds, 'Cads')
VariousControls = SubElement(Cads, 'VariousControls')
MiscControls = SubElement(VariousControls, 'MiscControls')
if group.has_key('LOCAL_CCFLAGS'):
MiscControls.text = group['LOCAL_CCFLAGS']
else:
MiscControls.text = ' '
Define = SubElement(VariousControls, 'Define')
if group.has_key('LOCAL_CPPDEFINES'):
Define.text = ', '.join(set(group['LOCAL_CPPDEFINES']))
else:
Define.text = ' '
Undefine = SubElement(VariousControls, 'Undefine')
Undefine.text = ' '
IncludePath = SubElement(VariousControls, 'IncludePath')
if group.has_key('LOCAL_CPPPATH'):
IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in group['LOCAL_CPPPATH']])
else:
IncludePath.text = ' '
# get each include path
if group.has_key('CPPPATH') and group['CPPPATH']:
if CPPPATH:
CPPPATH += group['CPPPATH']
else:
CPPPATH += group['CPPPATH']
# get each group's definitions
if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
if CPPDEFINES:
CPPDEFINES += group['CPPDEFINES']
else:
CPPDEFINES += group['CPPDEFINES']
# get each group's link flags
if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
if LINKFLAGS:
LINKFLAGS += ' ' + group['LINKFLAGS']
else:
LINKFLAGS += group['LINKFLAGS']
if group.has_key('LIBS') and group['LIBS']:
for item in group['LIBS']:
lib_path = ''
for path_item in group['LIBPATH']:
full_path = os.path.join(path_item, item + '.lib')
if os.path.isfile(full_path): # has this library
lib_path = full_path
if lib_path != '':
if (group_tree != None):
MDK4AddLibToGroup(ProjectFiles, group_tree, group['name'], lib_path, project_path)
else:
MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path)
# write include path, definitions and link flags
IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath')
IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in CPPPATH])
Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define')
Define.text = ', '.join(set(CPPDEFINES))
Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc')
Misc.text = LINKFLAGS
xml_indent(root)
out.write(etree.tostring(root, encoding='utf-8'))
out.close()