diff --git a/converter.py b/converter.py index 284b7d8..602812a 100644 --- a/converter.py +++ b/converter.py @@ -4,15 +4,17 @@ import argparse import ewpproject import uvprojxproject +# TODO: add Cmake and jinja2 support + def findFile (path,fileext): - file = '' + f = '' for root, dirs, files in os.walk(path): for file in files: if file.endswith(fileext): - file = os.path.join(root, file) + f = os.path.join(root, file) - return file + return f if __name__ == '__main__': @@ -30,7 +32,7 @@ if __name__ == '__main__': file = findFile(args.path,'.ewp') if (len(file)): print ('Found project file: ' + file) - project = ewpproject.EWPProject(file) + project = ewpproject.EWPProject(args.path,file) project.parseProject() project.displaySummary() else: @@ -41,7 +43,7 @@ if __name__ == '__main__': file = findFile(args.path,'.uvprojx') if (len(file)): print ('Found project file: ' + file) - project = uvprojxproject.UVPROJXProject(file) + project = uvprojxproject.UVPROJXProject(args.path,file) project.parseProject() project.displaySummary() else: diff --git a/ewpproject.py b/ewpproject.py index 6b705aa..ac12aee 100644 --- a/ewpproject.py +++ b/ewpproject.py @@ -4,8 +4,9 @@ from lxml import objectify class EWPProject (object): - def __init__(self, xmlFile): + def __init__(self, path, xmlFile): + self.path = path self.xmlFile = xmlFile xmltree = objectify.parse(xmlFile) self.root = xmltree.getroot() @@ -32,23 +33,26 @@ class EWPProject (object): self.chip = e.state elif e.name.text == 'CCDefines': for d in e.getchildren(): - if d.tag == 'state': + if d.tag == 'state' and d.text != None: self.defines.append(d.text) elif e.name.text == 'CCIncludePath2': for d in e.getchildren(): - if d.tag == 'state': + if d.tag == 'state' and d.text != None: self.includes.append(d.text) + + for i in range(0, len(self.includes)): + self.includes[i] = self.includes[i].replace('$PROJ_DIR$', self.path) + def displaySummary(self): - - + print ('Project Name:' + self.projectName) print ('Project chip:' + self.chip) - print ('Project includes: ' + self.includes) - print ('Project defines: ' + self.defines) + print ('Project includes: ' + ' '.join(self.includes)) + print ('Project defines: ' + ' '.join(self.defines)) def searchGroups(self, xml): - + for element in xml.getchildren(): if element.tag == 'group': diff --git a/uvprojxproject.py b/uvprojxproject.py index aea7dfc..2dcb414 100644 --- a/uvprojxproject.py +++ b/uvprojxproject.py @@ -3,7 +3,7 @@ from lxml import objectify class UVPROJXProject (object): - def __init__(self, xmlFile): + def __init__(self, path, xmlFile): self.xmlFile = xmlFile xmltree = objectify.parse(xmlFile) @@ -14,22 +14,26 @@ class UVPROJXProject (object): 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.includes = self.root.Targets.Target.TargetOption.TargetArmAds.Cads.VariousControls.IncludePath.text.split(';') self.memories = self.root.Targets.Target.TargetOption.TargetCommonOption.Cpu + self.defines = self.root.Targets.Target.TargetOption.TargetArmAds.Cads.VariousControls.Define.text.split(',') - + self.sources = [] 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) + if hasattr(element,'Files'): + 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 includes: ' + ' '.join(self.includes)) + print ('Project defines: ' + ' '.join(self.defines)) print ('Project: ' + self.memories)