def substituteAuxFiles(module_dir, program_name): """ Copy AUX file(s) and substitutes keyworks """ configuration = { "FILE": os.path.join('scripts', program_name), "DATE": time.strftime("%x"), "AUTHOR": ProjectCommonRoutines.getAuthor(), } # Put AUX files to their target and substitute tgt = os.path.join('scripts', program_name) Auxiliary.configure(os.path.join("ElementsKernel", "templates", PROGRAM_TEMPLATE_FILE_IN), module_dir, tgt, configuration=configuration, create_missing_dir=True) full_tgt = os.path.join(module_dir, tgt) # Add the execution flag tgt_stat = os.stat(full_tgt) os.chmod(full_tgt, tgt_stat.st_mode | stat.S_IEXEC) ProjectCommonRoutines.addItemToCreationList(full_tgt)
def checkAuxFileExist(aux_file_name): """ Make sure the <aux_file> auxiliary file exists. Return an exception in case of an error. <aux_file_name> is just the name without the path. """ auxpath = os.path.join('ElementsKernel', 'templates', aux_file_name) aux.getAuxiliaryPath(auxpath)
def createCmakeListFile(project_dir, module_name, module_dep_list, standalone=False): """ Create the <CMakeList.txt> file and add dependencies to it """ for src in target_locations: file_name = os.path.join("ElementsKernel", "templates", src) tgt = target_locations[src] module_dir = os.path.join(project_dir, module_name) Auxiliary.configure(file_name, module_dir, tgt, configuration="", create_missing_dir=True) ProjectCommonRoutines.addItemToCreationList( os.path.join(module_dir, tgt)) # Read the template file cmake_list_file = os.path.join(module_dir, CMAKE_LISTS_FILE) fo = open(cmake_list_file) template_data = fo.read() fo.close() cmake_object = ParseCmakeLists.CMakeLists(template_data) # Add elements_subdir macro subdir_obj = ParseCmakeListsMacros.ElementsSubdir(module_name) cmake_object.elements_subdir_list.append(subdir_obj) # Set <ElementsKernel> as a default if not standalone: default_dependency = 'ElementsKernel' if module_dep_list: if not default_dependency in module_dep_list: module_dep_list.insert(0, default_dependency) else: module_dep_list = [default_dependency] # Update ElementsDependsOnSubdirs macro if module_dep_list: for mod_dep in module_dep_list: dep_object = ParseCmakeListsMacros.ElementsDependsOnSubdirs( [mod_dep]) cmake_object.elements_depends_on_subdirs_list.append(dep_object) # Write new data f = open(cmake_list_file, 'w') f.write(str(cmake_object)) f.close()
def createProject(project_dir, proj_name, proj_version, dep_projects, standalone=False): """ Create the project structure """ logger.info('# Creating the project') configuration = getSubstituteConfiguration(proj_name, proj_version, dep_projects, standalone) for src in target_locations: file_name = os.path.join("ElementsKernel", "templates", src) tgt = target_locations[src] Auxiliary.configure(file_name, project_dir, tgt, configuration=configuration, create_missing_dir=True) ProjectCommonRoutines.addItemToCreationList(os.path.join(project_dir, tgt))
def copyAuxFile(destination, aux_file_name): """ Copy the <aux_file_name> file to the <destination> directory. <aux_file_name> is just the name without path """ aux_path_file = aux.getAuxiliaryPath( os.path.join('ElementsKernel', 'templates', aux_file_name)) shutil.copy(aux_path_file, os.path.join(destination, aux_file_name))
def substituteAuxFiles(module_dir, program_name, module_name): """ Copy AUX file(s) and substitutes keyworks """ filename = program_name + ".py" configuration = { "FILE": os.path.join('python', module_name, filename), "DATE": time.strftime("%x"), "AUTHOR": ProjectCommonRoutines.getAuthor(), "PROGRAMNAME": program_name } # Put AUX files to their target and substitut tgt = os.path.join('python', module_name, program_name + '.py') Auxiliary.configure(os.path.join("ElementsKernel", "templates", PROGRAM_TEMPLATE_FILE_IN), module_dir, tgt, configuration=configuration, create_missing_dir=True) ProjectCommonRoutines.addItemToCreationList(os.path.join(module_dir, tgt))
def substituteAuxFiles(module_dir, program_name): """ Copy AUX file(s) and substitutes keyworks """ target_location = os.path.join('src', 'program', program_name + '.cpp') configuration = { "FILE": target_location, "DATE": time.strftime("%x"), "AUTHOR": ProjectCommonRoutines.getAuthor(), "PROGRAMNAME": program_name } Auxiliary.configure(os.path.join("ElementsKernel", "templates", PROGRAM_TEMPLATE_FILE_IN), module_dir, target_location, configuration=configuration, create_missing_dir=True) ProjectCommonRoutines.addItemToCreationList( os.path.join(module_dir, target_location))
def createPythonModule(module_dir, module_name, python_module_name): """ Create the python module """ print('module_dir ', module_dir, 'module_name ', module_name, 'python_module_name ', python_module_name) createDirectories(module_dir, module_name) ProjectCommonRoutines.createPythonInitFile( os.path.join(module_dir, 'python', module_name, '__init__.py')) full_pymodule_name = os.path.join('python', module_name, python_module_name + '.py') pytest_name = os.path.join('tests', 'python', python_module_name + '_test.py') target_locations = { PYMODULE_TEMPLATE_FILE_IN: full_pymodule_name, PYTEST_TEMPLATE_FILE_IN: pytest_name } configuration = { "FILE": full_pymodule_name, "FILETEST": pytest_name, "DATE": time.strftime("%x"), "AUTHOR": ProjectCommonRoutines.getAuthor(), "MODULENAME": module_name, "PYTHONMODULE": python_module_name } # Put AUX files to their target and substitut for src in target_locations: file_name = os.path.join("ElementsKernel", "templates", src) tgt = target_locations[src] Auxiliary.configure(file_name, module_dir, tgt, configuration=configuration, create_missing_dir=True) ProjectCommonRoutines.addItemToCreationList( os.path.join(module_dir, tgt)) updateCmakeListsFile(module_dir)