Added command line support with dedicated executables

This commit is contained in:
2024-02-27 17:25:05 +01:00
parent 13cea1421c
commit e34f8d3d75
5 changed files with 45 additions and 99 deletions

2
HLExtract Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
python HeiligeListe.py EXTRACT "$@"

3
HLGenerate Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
python HeiligeListe.py GENERATE "$@"

2
HLInit Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
python HeiligeListe.py INIT "$@"

2
HLRelease Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
python HeiligeListe.py RELEASE "$@"

View File

@@ -5,6 +5,7 @@ import sys
import shutil
import json
import datetime
import argparse
sys.path.insert(0,os.path.join(os.path.dirname(__file__), 'Python_Code'))
@@ -46,7 +47,7 @@ class HeiligeListe:
return True
def HLClone(self,dirname,phase='All'):
def HLClone(self, dirname = "Work", phase='All'):
"""
Routine to take all reference input files and to generate a working directory to copy all relevant files
to the working directory so that it can be build. Existing working directory are deleted
@@ -108,7 +109,7 @@ class HeiligeListe:
return False
return True
def HLRelease(self, dirname, phase='All'):
def HLRelease(self, dirname='Work', phase='All'):
"""
Copies excel files and sub_assembly files into the current directory, add them to git and push it to the git repository
:param dirname: name of working directory
@@ -238,7 +239,7 @@ class HeiligeListe:
return True
def HLGenerate(self,dirname, phase = 'All'):
def HLGenerate(self, dirname = 'Work', phase = 'All', filter = None):
"""
Generate an Excel File with the tabs for 3DExperience, Holy List and Proto List within the defined working
directory. If the directory is not found the command HLClone is performed first.
@@ -253,68 +254,7 @@ class HeiligeListe:
# step 1 - check if working folder exists. Otherwise try to creat it
folder = os.path.join(os.path.dirname(__file__), dirname)
if not os.path.exists(folder):
status = self.HLClone(dirname, phase)
if not status:
return False
# step 2 - read in lattice version and phase
version = {'Version': None, 'Current': False,'Planned': False, 'Final': False}
with open(os.path.join(folder,'Version.json'), 'r') as fin:
version = json.load(fin)
if version['Version'] is None:
print('Cannot find version file in working directory')
return False
vers=['Current','Planned','Final']
for nphase, ver in enumerate(vers):
if (phase == 'All' or phase == ver) and version[ver]:
vercomp = self.PLs[nphase].SF.Version
if not vercomp == version['Version']:
print('Lattice mismatch of Cloned Lattice and current Online Model')
print('Please clone working directory with current model again')
return False
# step 3 - calculate layout for Proto list
print('\n------------------------------\nGenerating Proto List:\n')
self.PLs[nphase].generateLayout()
#excelfile = os.path.join(folder, 'HolyList-Lat%s-Phase-%s' % (version['Version'], ver))
#self.export.export(excelfile, self.PLs[nphase], None)
#return True
# step 4 - parse assembly and component lists
print('\n------------------------------\nParsing Assembly and Component Lists:\n')
assemblyfile = os.path.join(folder,'Phase %s' % ver)
print('Parsing Assembly Lists in Directory:',assemblyfile)
self.assembly.readFiles(assemblyfile,folder,nphase)
# step 5 - calculate Holy List
print('\n------------------------------\nGenerating Holy List:\n')
DL = self.assembly.generateLayout(self.PLs[nphase])
# step 6 - write out Excel File
excelfile=os.path.join(folder,'HolyList-Lat%s-Phase-%s' % (version['Version'],ver))
print('\n------------------------------\nWriting Excel File: %s\n' % excelfile)
self.export.export(excelfile, self.PLs[nphase], DL, Filter = None)
return True
def HLExtract(self,dirname, filter, phase = 'All'):
"""
Generate an Excel File with only the tab for 3DExperience within the defined working
directory. If the directory is not found the command HLClone is performed first.
:param dirname: name of working directory
:param filter: regular expression for the filter
:param phase: either 'Current', 'Planned', 'Future', or 'All'. Tag is case-sensitive
:return: True or False depending if working directory existed and phase is valid
"""
if len(dirname) < 1:
return False
# step 1 - check if working folder exists. Otherwise try to creat it
folder = os.path.join(os.path.dirname(__file__), dirname)
if not os.path.exists(folder):
status = self.HLClone(dirname, phase)
status = self.HLClone(dirname = dirname, phase = phase)
if not status:
return False
@@ -359,56 +299,53 @@ class HeiligeListe:
return True
def parse(args):
HL = HeiligeListe()
if len(args) < 2:
print('Command Arguments are missing (e.g. init, generate)')
cmd=args[1].upper()
print('Action:', cmd)
if cmd == 'INIT':
if len(args) < 3:
print('Needs arguments for working directory')
return
elif len(args) < 4:
HL.HLClone(args[2]) # all phases
else:
HL.HLClone(args[2], args[3]) # specific phase
parser = argparse.ArgumentParser(prog='HLInit', description='Initialize a working directory')
parser.add_argument('-d','--dir', default='Work', help='Name of working directory')
parser.add_argument('-p','--phase', default='Current',
help = 'Phase: Current, Planned, Final, or All',
choices=['Current','Planned','Final','All'])
pargs = parser.parse_args(args[2:])
HL.HLClone(dirname=pargs.dir,phase=pargs.phase)
elif cmd == 'UPDATE':
HL.HLUpdateLattice()
elif cmd == 'GENERATE':
if len(args) < 3:
print('Needs argument for working directory')
return
elif len(args) < 4:
HL.HLGenerate(args[2])
else:
HL.HLGenerate(args[2],args[3])
parser = argparse.ArgumentParser(prog='HLGenerate', description='Generate the holy list in the working directory')
parser.add_argument('-d', '--dir', default='Work', help='Name of working directory')
parser.add_argument('-p', '--phase', default='Current',
help='Phase: Current, Planned, Final, or All',
choices=['Current', 'Planned', 'Final', 'All'])
pargs = parser.parse_args(args[2:])
HL.HLGenerate(dirname=pargs.dir, phase=pargs.phase)
elif cmd == 'EXTRACT':
if len(args) < 4:
print('Needs argument for working directory and filter')
return
elif len(args) < 4:
HL.HLExtract(args[2],args[3])
else:
HL.HLExtract(args[2], args[3],args[4])
parser = argparse.ArgumentParser(prog='HLExtract', description='Extract a subset of the holy list')
parser.add_argument('-d', '--dir', default='Work', help='Name of working directory')
parser.add_argument('-f', '--filter', default='.*', help='Regular Expression Filter')
parser.add_argument('-p', '--phase', default='Current',
help='Phase: Current, Planned, Final, or All',
choices=['Current', 'Planned', 'Final', 'All'])
pargs = parser.parse_args(args[2:])
HL.HLGenerate(dirname=pargs.dir, phase=pargs.phase,filter=pargs.filter)
elif cmd == 'COMPARE':
if len(args) < 4:
print('Needs argument for the two files to be compared')
return
compareLists(args[2:])
elif cmd == 'RELEASE':
if len(args) < 3:
print('Needs argument for working directory')
return
elif len(args) < 4:
HL.HLRelease(args[2])
else:
HL.HLRelease(args[2],args[3])
# compareWithOldHL('work/HolyList-Lat10.5.1-Phase-Current.xlsx', 'Debug/sf-hl-current.xlsx')
parser = argparse.ArgumentParser(prog='HLRelease',
description='Release the holy list as a new version on gitlab')
parser.add_argument('-d', '--dir', default='Work', help='Name of working directory')
parser.add_argument('-p', '--phase', default='Current',
help='Phase: Current, Planned, Final, or All',
choices=['Current', 'Planned', 'Final', 'All'])
pargs = parser.parse_args(args[2:])
HL.HLRelease(dirname=pargs.dir, phase=pargs.phase)
# Main Routine
if __name__ == '__main__':