mirror of
https://github.com/phodina/ProjectConverter.git
synced 2026-07-30 16:26:15 +08:00
Parsing methods are rewritten for each project into class.
This commit is contained in:
parent
3998e6a570
commit
7b24babefb
77
converter.py
77
converter.py
@ -1,79 +1,6 @@
|
|||||||
from lxml import objectify
|
import ewpproject
|
||||||
|
import uvprojxproject
|
||||||
|
|
||||||
|
|
||||||
def searchGroups(xml):
|
|
||||||
|
|
||||||
for element in xml.getchildren():
|
|
||||||
|
|
||||||
if element.tag == 'group':
|
|
||||||
searchGroups(element)
|
|
||||||
|
|
||||||
elif element.tag == 'file':
|
|
||||||
print (element.name)
|
|
||||||
|
|
||||||
def parseEWP():
|
|
||||||
|
|
||||||
xmlFile = "Test.ewp"
|
|
||||||
xmltree = objectify.parse(xmlFile)
|
|
||||||
root = xmltree.getroot()
|
|
||||||
|
|
||||||
projectName = root.configuration.name
|
|
||||||
print ('Project Name:' + projectName)
|
|
||||||
|
|
||||||
chip = ''
|
|
||||||
|
|
||||||
#TODO: parse into tree structure
|
|
||||||
searchGroups(root)
|
|
||||||
|
|
||||||
defines = []
|
|
||||||
includes = []
|
|
||||||
|
|
||||||
for element in root.configuration.getchildren():
|
|
||||||
|
|
||||||
if element.tag == 'settings':
|
|
||||||
for e in element.data.getchildren():
|
|
||||||
|
|
||||||
if e.tag == 'option':
|
|
||||||
if e.name.text == 'OGChipSelectEditMenu':
|
|
||||||
chip = e.state
|
|
||||||
elif e.name.text == 'CCDefines':
|
|
||||||
for d in e.getchildren():
|
|
||||||
if d.tag == 'state':
|
|
||||||
defines.append(d.text)
|
|
||||||
elif e.name.text == 'CCIncludePath2':
|
|
||||||
for d in e.getchildren():
|
|
||||||
if d.tag == 'state':
|
|
||||||
includes.append(d.text)
|
|
||||||
|
|
||||||
print (includes)
|
|
||||||
print (defines)
|
|
||||||
print (chip)
|
|
||||||
|
|
||||||
def parseUVPROJX():
|
|
||||||
|
|
||||||
xmlFile = 'Test.uvprojx'
|
|
||||||
xmltree = objectify.parse(xmlFile)
|
|
||||||
root = xmltree.getroot()
|
|
||||||
|
|
||||||
projectName = root.Targets.Target.TargetName
|
|
||||||
|
|
||||||
chip = root.Targets.Target.TargetOption.TargetCommonOption.Device
|
|
||||||
svd = root.Targets.Target.TargetOption.TargetCommonOption.SFDFile
|
|
||||||
includes = root.Targets.Target.TargetOption.TargetArmAds.Cads.VariousControls.IncludePath.text
|
|
||||||
memories = root.Targets.Target.TargetOption.TargetCommonOption.Cpu
|
|
||||||
print ('Project Name:' + projectName)
|
|
||||||
print ('Project chip:' + chip)
|
|
||||||
print ('Project svd:' + svd)
|
|
||||||
print ('Project includes: ' + includes)
|
|
||||||
print ('Project: ' + memories)
|
|
||||||
|
|
||||||
for element in root.Targets.Target.Groups.getchildren():
|
|
||||||
|
|
||||||
print ('GroupName: ' + element.GroupName.text)
|
|
||||||
for file in element.Files.getchildren():
|
|
||||||
print ('FileName: ' + file.FileName.text)
|
|
||||||
print ('FilePath: ' + file.FilePath.text)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
pass
|
pass
|
||||||
@ -1,7 +1,59 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import xmltree
|
||||||
|
from lxml import objectify
|
||||||
|
|
||||||
class EWPProject (object):
|
class EWPProject (object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, xmlFile):
|
||||||
|
|
||||||
|
self.xmlFile = xmlFile
|
||||||
|
self.xmltree = objectify.parse(xmlFile)
|
||||||
|
self.root = xmltree.getroot()
|
||||||
|
|
||||||
|
def parseProject(self):
|
||||||
|
|
||||||
pass
|
self.projectName = self.root.configuration.name
|
||||||
|
|
||||||
|
self.chip = ''
|
||||||
|
|
||||||
|
#TODO: parse into tree structure
|
||||||
|
self.searchGroups(self.root)
|
||||||
|
|
||||||
|
self.defines = []
|
||||||
|
self.includes = []
|
||||||
|
|
||||||
|
for element in self.root.configuration.getchildren():
|
||||||
|
|
||||||
|
if element.tag == 'settings':
|
||||||
|
for e in element.data.getchildren():
|
||||||
|
|
||||||
|
if e.tag == 'option':
|
||||||
|
if e.name.text == 'OGChipSelectEditMenu':
|
||||||
|
self.chip = e.state
|
||||||
|
elif e.name.text == 'CCDefines':
|
||||||
|
for d in e.getchildren():
|
||||||
|
if d.tag == 'state':
|
||||||
|
self.defines.append(d.text)
|
||||||
|
elif e.name.text == 'CCIncludePath2':
|
||||||
|
for d in e.getchildren():
|
||||||
|
if d.tag == 'state':
|
||||||
|
self.includes.append(d.text)
|
||||||
|
|
||||||
|
def displaySummary(self):
|
||||||
|
|
||||||
|
|
||||||
|
print ('Project Name:' + self.projectName)
|
||||||
|
print ('Project chip:' + self.chip)
|
||||||
|
print ('Project includes: ' + self.includes)
|
||||||
|
print ('Project defines: ' + self.defines)
|
||||||
|
|
||||||
|
def searchGroups(self, xml):
|
||||||
|
|
||||||
|
for element in xml.getchildren():
|
||||||
|
|
||||||
|
if element.tag == 'group':
|
||||||
|
self.searchGroups(element)
|
||||||
|
|
||||||
|
elif element.tag == 'file':
|
||||||
|
print (element.name)
|
||||||
|
|
||||||
@ -1,7 +1,36 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import xmltree
|
||||||
|
from lxml import objectify
|
||||||
|
|
||||||
class UVPROJXProject (object):
|
class UVPROJXProject (object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, xmlFile):
|
||||||
|
|
||||||
pass
|
self.xmlFile = xmlFile
|
||||||
|
self.xmltree = objectify.parse(xmlFile)
|
||||||
|
self.root = xmltree.getroot()
|
||||||
|
|
||||||
|
def parseProject (self):
|
||||||
|
|
||||||
|
self.projectName = self.root.Targets.Target.TargetName
|
||||||
|
self.chip = self.root.Targets.Target.TargetOption.TargetCommonOption.Device
|
||||||
|
self.svd = self.root.Targets.Target.TargetOption.TargetCommonOption.SFDFile
|
||||||
|
self.includes = self.root.Targets.Target.TargetOption.TargetArmAds.Cads.VariousControls.IncludePath.text
|
||||||
|
self.memories = self.root.Targets.Target.TargetOption.TargetCommonOption.Cpu
|
||||||
|
|
||||||
|
|
||||||
|
for element in self.root.Targets.Target.Groups.getchildren():
|
||||||
|
|
||||||
|
print ('GroupName: ' + element.GroupName.text)
|
||||||
|
for file in element.Files.getchildren():
|
||||||
|
print ('FileName: ' + file.FileName.text)
|
||||||
|
print ('FilePath: ' + file.FilePath.text)
|
||||||
|
|
||||||
|
def displaySummary(self):
|
||||||
|
|
||||||
|
print ('Project Name:' + self.projectName)
|
||||||
|
print ('Project chip:' + self.chip)
|
||||||
|
print ('Project svd:' + self.svd)
|
||||||
|
print ('Project includes: ' + self.includes)
|
||||||
|
print ('Project: ' + self.memories)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user