Loading test/genDevice.py +35 −34 Original line number Original line Diff line number Diff line Loading @@ -13,7 +13,7 @@ from GenDevice.acsUtils import * import pandas as pd import pandas as pd import glob import glob outdir="/tmp/" OUTDIR="/tmp/" gendir=os.environ["PYGEN"] gendir=os.environ["PYGEN"] if gendir=="": if gendir=="": Loading @@ -22,39 +22,36 @@ if gendir=="": if not checkACS(): if not checkACS(): print ("ACS Enviroment is not set") print ("ACS Enviroment is not set") exit() exit() def generateComponent(config,install=False): def generateComponent(config): pwd=os.getcwd() pwd=os.getcwd() wb=excelIcd(config['icdfile']) wb=excelIcd(config['icdfile']) smain= wb.book.parse("Main") devs= wb.MainSheet['Device Name'] devs= smain['Device Name'] #comp=smain['Component Name'] assembly=smain['Assembly'] #outfile=[] if len(devs)>1 : if len(devs)>1 : print ("the Assembly:"+assembly[0]+" includes more than one device\n",devs) print ("The Assembly:"+wb.MainSheet['Assembly'][0]+" includes more than one device\n",devs) for dev in devs: genMulti(wb,config) 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() else: else: print ("the Assembly:"+assembly[0]+" includes one device\n",devs) print ("The Assembly:"+wb.MainSheet['Assembly'][0]+" includes one device\n",devs) #outf=manageICDFiles(devs[0],outdir,wb) genSingle(wb,config) mygen=genFromTemplates(wb,config['icdfile'],config['prefix'],config['module'],config['basedir']) mygen.generateFileInDir() checkCDB(mygen) if install : build(mygen) checkCDB(mygen) os.chdir(pwd) 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): def manageICDFiles(dev,outdir,wb): query="`Device Name` =="+ "'"+dev+"'" query="`Device Name` =="+ "'"+dev+"'" main=(wb.book.parse("Main")).query(query) main=(wb.book.parse("Main")).query(query) Loading Loading @@ -103,17 +100,15 @@ def checkCDB(mygen): def removetmpfiles(): def removetmpfiles(): filelist = glob.glob(outdir+'*.xlsx') filelist = glob.glob(OUTDIR+'*.xlsx') for fil in filelist: for fil in filelist: try: try: os.remove(fil) os.remove(fil) except OSError as e: except OSError as e: print ("Error: %s - %s." % (e.filename, e.strerror)) print ("Error: %s - %s." % (e.filename, e.strerror)) if __name__ =="__main__": def getInput(): parser = OptionParser() parser = OptionParser() today = date.today() pwd=os.getcwd() parser.add_option("-f", "--file", dest="bookfile", parser.add_option("-f", "--file", dest="bookfile", help="ICD Exel File ", metavar="FILE") help="ICD Exel File ", metavar="FILE") parser.add_option("-d", "--dir", dest="basedir", default="./tmp", parser.add_option("-d", "--dir", dest="basedir", default="./tmp", Loading @@ -125,13 +120,19 @@ if __name__ =="__main__": parser.add_option("-i", "--install", dest="install", default=False, parser.add_option("-i", "--install", dest="install", default=False, help="execute the Makefile in src dir ", metavar="INSTALL") help="execute the Makefile in src dir ", metavar="INSTALL") (options, args) = parser.parse_args() (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={} config['icdfile']=options.bookfile config['icdfile']=options.bookfile config['prefix']=options.prefix config['prefix']=options.prefix config['module']=options.module config['module']=options.module config['basedir']=options.basedir 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") print ("ALL Done") os.chdir(pwd) os.chdir(pwd) Loading Loading
test/genDevice.py +35 −34 Original line number Original line Diff line number Diff line Loading @@ -13,7 +13,7 @@ from GenDevice.acsUtils import * import pandas as pd import pandas as pd import glob import glob outdir="/tmp/" OUTDIR="/tmp/" gendir=os.environ["PYGEN"] gendir=os.environ["PYGEN"] if gendir=="": if gendir=="": Loading @@ -22,39 +22,36 @@ if gendir=="": if not checkACS(): if not checkACS(): print ("ACS Enviroment is not set") print ("ACS Enviroment is not set") exit() exit() def generateComponent(config,install=False): def generateComponent(config): pwd=os.getcwd() pwd=os.getcwd() wb=excelIcd(config['icdfile']) wb=excelIcd(config['icdfile']) smain= wb.book.parse("Main") devs= wb.MainSheet['Device Name'] devs= smain['Device Name'] #comp=smain['Component Name'] assembly=smain['Assembly'] #outfile=[] if len(devs)>1 : if len(devs)>1 : print ("the Assembly:"+assembly[0]+" includes more than one device\n",devs) print ("The Assembly:"+wb.MainSheet['Assembly'][0]+" includes more than one device\n",devs) for dev in devs: genMulti(wb,config) 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() else: else: print ("the Assembly:"+assembly[0]+" includes one device\n",devs) print ("The Assembly:"+wb.MainSheet['Assembly'][0]+" includes one device\n",devs) #outf=manageICDFiles(devs[0],outdir,wb) genSingle(wb,config) mygen=genFromTemplates(wb,config['icdfile'],config['prefix'],config['module'],config['basedir']) mygen.generateFileInDir() checkCDB(mygen) if install : build(mygen) checkCDB(mygen) os.chdir(pwd) 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): def manageICDFiles(dev,outdir,wb): query="`Device Name` =="+ "'"+dev+"'" query="`Device Name` =="+ "'"+dev+"'" main=(wb.book.parse("Main")).query(query) main=(wb.book.parse("Main")).query(query) Loading Loading @@ -103,17 +100,15 @@ def checkCDB(mygen): def removetmpfiles(): def removetmpfiles(): filelist = glob.glob(outdir+'*.xlsx') filelist = glob.glob(OUTDIR+'*.xlsx') for fil in filelist: for fil in filelist: try: try: os.remove(fil) os.remove(fil) except OSError as e: except OSError as e: print ("Error: %s - %s." % (e.filename, e.strerror)) print ("Error: %s - %s." % (e.filename, e.strerror)) if __name__ =="__main__": def getInput(): parser = OptionParser() parser = OptionParser() today = date.today() pwd=os.getcwd() parser.add_option("-f", "--file", dest="bookfile", parser.add_option("-f", "--file", dest="bookfile", help="ICD Exel File ", metavar="FILE") help="ICD Exel File ", metavar="FILE") parser.add_option("-d", "--dir", dest="basedir", default="./tmp", parser.add_option("-d", "--dir", dest="basedir", default="./tmp", Loading @@ -125,13 +120,19 @@ if __name__ =="__main__": parser.add_option("-i", "--install", dest="install", default=False, parser.add_option("-i", "--install", dest="install", default=False, help="execute the Makefile in src dir ", metavar="INSTALL") help="execute the Makefile in src dir ", metavar="INSTALL") (options, args) = parser.parse_args() (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={} config['icdfile']=options.bookfile config['icdfile']=options.bookfile config['prefix']=options.prefix config['prefix']=options.prefix config['module']=options.module config['module']=options.module config['basedir']=options.basedir 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") print ("ALL Done") os.chdir(pwd) os.chdir(pwd) Loading