Commit b06e557a authored by Gino Tosti's avatar Gino Tosti
Browse files

code cleaning

parent 1d8ad749
......@@ -13,7 +13,7 @@ from GenDevice.acsUtils import *
import pandas as pd
import glob
outdir="/tmp/"
OUTDIR="/tmp/"
gendir=os.environ["PYGEN"]
if gendir=="":
......@@ -22,39 +22,36 @@ if gendir=="":
if not checkACS():
print ("ACS Enviroment is not set")
exit()
def generateComponent(config,install=False):
def generateComponent(config):
pwd=os.getcwd()
wb=excelIcd(config['icdfile'])
smain= wb.book.parse("Main")
devs= smain['Device Name']
#comp=smain['Component Name']
assembly=smain['Assembly']
#outfile=[]
devs= wb.MainSheet['Device Name']
if len(devs)>1 :
print ("the Assembly:"+assembly[0]+" includes more than one device\n",devs)
for dev in devs:
print("working On device:", dev)
outf=manageICDFiles(dev,outdir,wb)
#outfile.append(outf)
print("Working on files:",dev)
wb1=excelIcd(outf)
mygen=genFromTemplates(wb1,outf,config['prefix'],config['module'],config['basedir'])
mygen.generateFileInDir()
if install :
build(mygen)
removetmpfiles()
print ("The Assembly:"+wb.MainSheet['Assembly'][0]+" includes more than one device\n",devs)
genMulti(wb,config)
else:
print ("the Assembly:"+assembly[0]+" includes one device\n",devs)
#outf=manageICDFiles(devs[0],outdir,wb)
mygen=genFromTemplates(wb,config['icdfile'],config['prefix'],config['module'],config['basedir'])
mygen.generateFileInDir()
checkCDB(mygen)
if install :
build(mygen)
checkCDB(mygen)
print ("The Assembly:"+wb.MainSheet['Assembly'][0]+" includes one device\n",devs)
genSingle(wb,config)
os.chdir(pwd)
def genMulti(wb,config):
for dev in wb.MainSheet['Device Name']:
print("working On device:", dev)
outf=manageICDFiles(dev,OUTDIR,wb)
print("Working on files:",outf)
wb1=excelIcd(outf)
config['icdfile']=outf
genSingle(wb1,config)
removetmpfiles()
def genSingle(wb,config):
mygen=genFromTemplates(wb,config['icdfile'],config['prefix'],config['module'],config['basedir'])
mygen.generateFileInDir()
if config['install'] :
build(mygen)
checkCDB(mygen)
def manageICDFiles(dev,outdir,wb):
query="`Device Name` =="+ "'"+dev+"'"
main=(wb.book.parse("Main")).query(query)
......@@ -103,17 +100,15 @@ def checkCDB(mygen):
def removetmpfiles():
filelist = glob.glob(outdir+'*.xlsx')
filelist = glob.glob(OUTDIR+'*.xlsx')
for fil in filelist:
try:
os.remove(fil)
except OSError as e:
print ("Error: %s - %s." % (e.filename, e.strerror))
if __name__ =="__main__":
def getInput():
parser = OptionParser()
today = date.today()
pwd=os.getcwd()
parser.add_option("-f", "--file", dest="bookfile",
help="ICD Exel File ", metavar="FILE")
parser.add_option("-d", "--dir", dest="basedir", default="./tmp",
......@@ -125,13 +120,19 @@ if __name__ =="__main__":
parser.add_option("-i", "--install", dest="install", default=False,
help="execute the Makefile in src dir ", metavar="INSTALL")
(options, args) = parser.parse_args()
print("running genDevice with the following options:\n", options)
#print("running genDevice with the following options:\n", options)
config={}
config['icdfile']=options.bookfile
config['prefix']=options.prefix
config['module']=options.module
config['basedir']=options.basedir
generateComponent(config,install=options.install)
config['install']=options.install
return config
if __name__ =="__main__":
pwd=os.getcwd()
config=getInput()
generateComponent(config)
print ("ALL Done")
os.chdir(pwd)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment