diff --git a/converter.py b/converter.py index f0f9ae5..27e89b5 100644 --- a/converter.py +++ b/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__': pass \ No newline at end of file diff --git a/ewpproject.py b/ewpproject.py index 9ec7761..6a6744e 100644 --- a/ewpproject.py +++ b/ewpproject.py @@ -1,7 +1,59 @@ # -*- coding: utf-8 -*- - +import xmltree +from lxml import objectify + 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 \ No newline at end of file + 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) + \ No newline at end of file diff --git a/uvprojxproject.py b/uvprojxproject.py index f180bda..03fc617 100644 --- a/uvprojxproject.py +++ b/uvprojxproject.py @@ -1,7 +1,36 @@ # -*- coding: utf-8 -*- - +import xmltree +from lxml import objectify + class UVPROJXProject (object): - def __init__(self): + def __init__(self, xmlFile): - pass \ No newline at end of file + 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) +