Added code to find the project file in the directory.

This commit is contained in:
cylon 2016-08-31 20:42:28 +02:00
parent 7b24babefb
commit 71f1ae6347
3 changed files with 50 additions and 5 deletions

View File

@ -1,6 +1,52 @@
# -*- coding: utf-8 -*-
import os
import argparse
import ewpproject import ewpproject
import uvprojxproject 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__': if __name__ == '__main__':
pass 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')

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import xmltree
from lxml import objectify from lxml import objectify
class EWPProject (object): class EWPProject (object):
@ -7,7 +7,7 @@ class EWPProject (object):
def __init__(self, xmlFile): def __init__(self, xmlFile):
self.xmlFile = xmlFile self.xmlFile = xmlFile
self.xmltree = objectify.parse(xmlFile) xmltree = objectify.parse(xmlFile)
self.root = xmltree.getroot() self.root = xmltree.getroot()
def parseProject(self): def parseProject(self):

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import xmltree
from lxml import objectify from lxml import objectify
class UVPROJXProject (object): class UVPROJXProject (object):
@ -7,7 +6,7 @@ class UVPROJXProject (object):
def __init__(self, xmlFile): def __init__(self, xmlFile):
self.xmlFile = xmlFile self.xmlFile = xmlFile
self.xmltree = objectify.parse(xmlFile) xmltree = objectify.parse(xmlFile)
self.root = xmltree.getroot() self.root = xmltree.getroot()
def parseProject (self): def parseProject (self):