diff --git a/converter.py b/converter.py index 27e89b5..284b7d8 100644 --- a/converter.py +++ b/converter.py @@ -1,6 +1,52 @@ +# -*- coding: utf-8 -*- +import os +import argparse import ewpproject import uvprojxproject +def findFile (path,fileext): + + file = '' + for root, dirs, files in os.walk(path): + for file in files: + if file.endswith(fileext): + file = os.path.join(root, file) + + return file + if __name__ == '__main__': - pass \ No newline at end of file + parser = argparse.ArgumentParser() + parser.add_argument("path", type=str, help="Root directory of project") + parser.add_argument("--ewp",help="Search for *.EWP file in project structure",action='store_true') + parser.add_argument("--uvprojx",help="Search for *.UPROJX file in project structure",action='store_true') + + args = parser.parse_args() + + if (os.path.isdir (args.path)): + + if args.ewp: + print ('Looking for *.ewp file in ' + args.path) + file = findFile(args.path,'.ewp') + if (len(file)): + print ('Found project file: ' + file) + project = ewpproject.EWPProject(file) + project.parseProject() + project.displaySummary() + else: + print ('No project *.ewp file found') + + elif args.uvprojx: + print ('Looking for *.uvprojx file in ' + args.path) + file = findFile(args.path,'.uvprojx') + if (len(file)): + print ('Found project file: ' + file) + project = uvprojxproject.UVPROJXProject(file) + project.parseProject() + project.displaySummary() + else: + print ('No project *.uvprojx file found') + else: + + print ('Not a valid file path') + diff --git a/ewpproject.py b/ewpproject.py index 6a6744e..6b705aa 100644 --- a/ewpproject.py +++ b/ewpproject.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import xmltree + from lxml import objectify class EWPProject (object): @@ -7,7 +7,7 @@ class EWPProject (object): def __init__(self, xmlFile): self.xmlFile = xmlFile - self.xmltree = objectify.parse(xmlFile) + xmltree = objectify.parse(xmlFile) self.root = xmltree.getroot() def parseProject(self): diff --git a/uvprojxproject.py b/uvprojxproject.py index 03fc617..aea7dfc 100644 --- a/uvprojxproject.py +++ b/uvprojxproject.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -import xmltree from lxml import objectify class UVPROJXProject (object): @@ -7,7 +6,7 @@ class UVPROJXProject (object): def __init__(self, xmlFile): self.xmlFile = xmlFile - self.xmltree = objectify.parse(xmlFile) + xmltree = objectify.parse(xmlFile) self.root = xmltree.getroot() def parseProject (self):