def _CheckClassNameAvailable( self, name, context="Application", searchSimilar=False ): appRep = False appSim = False repFiles = {} simFiles = {} # Search in the application context [appRep, appSim, repFiles, simFiles] = self._CheckClassNameInDir( GetApplicationsDirectory()+self.nameCamel+"Application", self.nameCamel.lower(), appRep, appSim, repFiles, simFiles ) if context == "Application": if searchSimilar: return appRep, appSim, repFiles, simFiles else: return appRep, repFiles # Search also in the kratos context: [appRep, appSim, repFiles, simFiles] = self._CheckClassNameInDir( GetKratosDirectory(), self.nameCamel.lower(), appRep, appSim, repFiles, simFiles ) if context == "Kratos": if searchSimilar: return appRep, appSim, repFiles, simFiles else: return appRep, repFiles # Search in other apps... "Everywhere": for root, dirs, files in os.walk(GetApplicationsDirectory()): for subapp in dirs: [appRep, appSim, repFiles, simFiles] = self._CheckClassNameInDir( GetApplicationsDirectory() + subapp, self.nameCamel.lower(), appRep, appSim, repFiles, simFiles ) if searchSimilar: return appRep, appSim, repFiles, simFiles else: return appRep, repFiles
def __init__(self, name): self._appDir = GetApplicationsDirectory() self._nameCamel = name self._nameUpper = ToUpperFromCamel(self._nameCamel) self._nameLower = ToLowerFromCamel(self._nameCamel) self._elements = [] self._conditions = [] self._processes = [] self._strategies = [] self._variables = [] self.__isDerived = False # What templates files need to be used for every class self._classTemplateFiles = { 'Elements': ['element_template.cpp', 'element_template.h'], 'Conditions': ['condition_template.h'], 'Processes': ['process_template.h'] } # Where they should be placed self._classTemplatePath = { 'Elements': ['classes', 'custom_elements'], 'Conditions': ['classes', 'custom_conditions'], 'Processes': ['classes', 'custom_process'] }
def __init__(self, name): self._appDir = GetApplicationsDirectory() self._nameCamel = name self._nameUpper = ToUpperFromCamel(self._nameCamel) self._nameLower = ToLowerFromCamel(self._nameCamel) self._elements = [] self._conditions = [] self._processes = [] self._strategies = [] self._variables = [] self.isDerived = False # Define the application tree rules ( directory names, files, etc...) self.rules += [{ 'token': '@{APP_NAME_CAMEL}', 'value': self._nameCamel }, { 'token': '@{APP_NAME_CAPS}', 'value': self._nameUpper }, { 'token': '@{APP_NAME_LOW}', 'value': self._nameLower }, { 'token': '@{APP_DEPEND_LIST}', 'value': '' }, { 'token': '@{APP_SOURCE_LIST}', 'value': '' }] # Define the templates files needed for every class self._classTemplateFiles = { 'Elements': ['element_template.cpp', 'element_template.h'], 'Conditions': ['condition_template.h'], 'Processes': ['process_template.h'], 'Variables': [ self._nameLower + '_application.h', self._nameLower + '_application.cpp', 'custom_python/' + self._nameLower + '_python_application.cpp', ] } # Define where the generated classes should be placed self._classTemplatePath = { 'Elements': ['classes', 'custom_elements'], 'Conditions': ['classes', 'custom_conditions'], 'Processes': ['classes', 'custom_process'] }
def __init__(self, name): super(ApplicationGenerator, self).__init__() appStrPos = name.lower().find('application') maxi = 5 while appStrPos != -1 and maxi > 0: oldname = name name = name[0:appStrPos] + name[appStrPos+len('application'):len(name)] msg = Formatc([ {'color': bcolors.WARNING, 'msg': '[WARNING]'}, {'color': bcolors.CYAN, 'msg': ' {}'.format(oldname)}, {'color': None, 'msg': ' already contains the substring "'}, {'color': bcolors.CYAN, 'msg': '{}'.format('Application')}, {'color': None, 'msg': '". Removing... : '+name}, ], sys.stderr) print(msg, file=sys.stderr) appStrPos = name.lower().find('application') maxi = maxi -1 if difflib.SequenceMatcher(None, name.lower(), 'application').ratio() > 0.65: msg = Formatc([ {'color': bcolors.WARNING, 'msg': '[WARNING]'}, {'color': None, 'msg': ' Your application name contains something wrong after automatic fix, please select another name.'}, ], sys.stderr) print(msg, file=sys.stderr) exit() self._appDir = GetApplicationsDirectory() self._nameCamel = name self._nameUpper = ToUpperFromCamel(self._nameCamel) self._nameLower = ToLowerFromCamel(self._nameCamel) self._elements = [] self._conditions = [] self._processes = [] self._strategies = [] self._variables = [] self.isDerived = False # Define the application tree rules ( directory names, files, etc...) self.rules += [ {'token': '@{APP_NAME_CAMEL}', 'value': self._nameCamel}, {'token': '@{APP_NAME_CAPS}', 'value': self._nameUpper}, {'token': '@{APP_NAME_LOW}', 'value': self._nameLower}, {'token': '@{APP_DEPEND_LIST}', 'value': ''}, {'token': '@{APP_SOURCE_LIST}', 'value': ''} ] # Define the templates files needed for every class self._classTemplateFiles = { 'Elements': ['element_template.cpp', 'element_template.h'], 'Conditions': ['condition_template.cpp', 'condition_template.h'], 'Processes': ['process_template.cpp', 'process_template.h'], 'Variables': [ self._nameLower+'_application.h', self._nameLower+'_application.cpp', self._nameLower+'_application_variables.h', self._nameLower+'_application_variables.cpp', 'custom_python/' + self._nameLower+'_python_application.cpp', ] } # Define where the generated classes should be placed self._classTemplatePath = { 'Elements': ['classes', 'custom_elements'], 'Conditions': ['classes', 'custom_conditions'], 'Processes': ['classes', 'custom_processes'] }
# Check if default section is valid json try: prcDataJson = json.loads(prcData) except Exception as e: print("Unable to parse json {} {}:\n {}".format(appName, f, prcData)) else: if appName in appRep: appRep[appName][f] = prcDataJson else: appRep[appName] = {f:prcDataJson} return appRep appRep = {} for root, dirs, files in os.walk(GetApplicationsDirectory()): for subapp in dirs: appRep = CheckClassNameInDir( GetApplicationsDirectory() + subapp, 'process', appRep ) with open('process.json', 'w') as json_file: json.dump(appRep, json_file) # for app in appRep: # print("*", app) # for process in appRep[app]: # print(process) # for processMame, processInfo in process.items():