示例#1
0
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)
示例#2
0
def checkProjectExist(project_dir,
                      no_version_directory,
                      force_erase,
                      answer_yes=False):
    """
    Look for any version directory in the project directory e.g 1.0,1.2 etc...
    """
    if os.path.exists(project_dir) and not force_erase:
        logger.warning('<%s> Project ALREADY exists!!!', project_dir)
        version_dir_list = lookForDirectories(project_dir)
        # Warn user about directory under the project
        if no_version_directory and version_dir_list:
            logger.warning(
                'Found the following version(s) directory(ies) : %s',
                version_dir_list)
        if not answer_yes:
            response_key = input(
                'Do you want to overwrite the existing project (y/n, default: n)?'
            )
        if answer_yes or response_key.lower() == "yes" or response_key == "y":
            logger.info('# Overwriting the existing project: <%s>',
                        project_dir)
        else:
            raise Exception()
    elif force_erase:
        ProjectCommonRoutines.eraseDirectory(project_dir)
示例#3
0
def createDirectories(module_dir):
    """
    Create directories needed for a python program
    """
    # Create the scripts directory
    scripts_path = os.path.join(module_dir, 'scripts')
    ProjectCommonRoutines.makeDirectory(scripts_path)
示例#4
0
def addConfFile(module_dir, program_name):
    """
    Create the configuration file by default
    """
    conf_file = os.path.join(module_dir, 'conf', program_name + '.conf')
    # check file does not exist
    if not os.path.exists(conf_file):
        f = open(conf_file, 'w')
        f.write(
            '###############################################################################\n'
        )
        f.write('#\n')
        f.write('# Configuration file for the <' + program_name +
                '> executable \n')
        f.write('#\n')
        f.write(
            '###############################################################################\n'
        )
        f.close()
        ProjectCommonRoutines.addItemToCreationList(conf_file)
    else:
        logger.warning(
            'The < %s > conf file has been kept as it already exists!',
            conf_file)
        logger.warning('The < %s > conf file already exists!', conf_file)
示例#5
0
def checkDependencyListValid(str_list):
    """
    Check if the dependency name(s) is(are) valid
    """
    if str_list:
        for elt in str_list:
            ProjectCommonRoutines.checkNameAndVersionValid(elt, '1.0')
示例#6
0
def checkDependencyProjectValid(str_list):
    """
    Check if the dependency project name and version list is valid
    """
    for i in range(len(str_list)):
        ProjectCommonRoutines.checkNameAndVersionValid(str_list[i][0],
                                                       str_list[i][1])
示例#7
0
def createModule(project_dir,
                 module_name,
                 dependency_list,
                 standalone=False,
                 answer_yes=False):
    """
    Create a module, copy auxiliary files and substitute variables in the
    CMakefile.txt file
    """
    # Create module directory
    mod_path = os.path.join(project_dir, module_name)
    logger.info('# Creating the module: <%s> ', mod_path)
    if os.path.exists(mod_path):
        # Ask user
        logger.warning('<%s> module ALREADY exists on disk!!!', module_name)
        if not answer_yes:
            response_key = input(
                'Do you want to replace the existing module (y/n), default: n)?'
            )
        if answer_yes or response_key.lower() == "y":
            logger.info('# Replacing the existing module: <%s>', module_name)
            ProjectCommonRoutines.eraseDirectory(mod_path)
        else:
            raise Exception()

    createModuleDirectories(project_dir, module_name)
    createCmakeListFile(project_dir, module_name, dependency_list, standalone)
示例#8
0
def updateCmakeListsFile(module_dir):
    """
    Update the CMakeList.txt file
    """
    logger.info('Updating the <%s> file', CMAKE_LISTS_FILE)
    cmake_filename = os.path.join(module_dir, CMAKE_LISTS_FILE)
    ProjectCommonRoutines.addItemToCreationList(cmake_filename)

    # Backup the file
    ProjectCommonRoutines.makeACopy(cmake_filename)

    # Cmake file already exist
    if os.path.isfile(cmake_filename):
        f = open(cmake_filename)
        data = f.read()
        f.close()
        cmake_object = ParseCmakeLists.CMakeLists(data)

        # Add elements_install_conf_files if any
        cmake_object.elements_install_python_modules = 'elements_install_python_modules()'

    # Write new data
    f = open(cmake_filename, 'w')
    f.write(str(cmake_object))
    f.close()
示例#9
0
def updateCmakeListsFile(module_dir, program_name):
    """
    Update the <CMakeList.txt> file
    """
    logger.info('Updating the <%s> file', CMAKE_LISTS_FILE)
    cmake_filename = os.path.join(module_dir, CMAKE_LISTS_FILE)
    ProjectCommonRoutines.addItemToCreationList(cmake_filename)

    # Backup the file
    ProjectCommonRoutines.makeACopy(cmake_filename)

    # Cmake file already exist
    if os.path.isfile(cmake_filename):
        f = open(cmake_filename)
        data = f.read()
        f.close()
        cmake_object = ParseCmakeLists.CMakeLists(data)
        module_name = cmake_object.elements_subdir_list[
            0].name + '.' + program_name

        # Add elements_install_conf_files if any
        cmake_object.elements_install_python_modules = 'elements_install_python_modules()'
        cmake_object.elements_install_conf_files = 'elements_install_conf_files()'

        program_object = ParseCmakeListsMacros.ElementsAddPythonExecutable(
            program_name, module_name)
        cmake_object.elements_add_python_executable_list.append(program_object)

    # Write new data
    f = open(cmake_filename, 'w')
    f.write(str(cmake_object))
    f.close()
示例#10
0
def mainMethod(args):
    """
    Main
    """

    logger.info('#')
    logger.info(
        '#  Logging from the mainMethod() of the RemoveCppProgram script ')
    logger.info('#')

    exit_code = Exit.Code["OK"]

    program_name = args.program_name

    # Default is the current directory
    module_dir = os.getcwd()

    logger.info('Current directory : %s', module_dir)
    logger.info('')

    try:
        # We absolutely need a Elements cmake file
        module_name = ProjectCommonRoutines.getElementsModuleName(module_dir)

        # Default is the current directory
        file_to_be_deleted = getAllFiles(program_name, module_dir, module_name)
        if file_to_be_deleted:
            logger.info('File to be deleted:')
            for elt_file in file_to_be_deleted:
                logger.info(' --> %s', elt_file)
            response_key = input('Do you want to continue?(y/n, default: n)')
            if response_key.lower() == 'Y' or response_key.lower() == 'y':
                ProjectCommonRoutines.removeFilesOnDisk(file_to_be_deleted)
                cmakefile = os.path.join(module_dir, 'CMakeLists.txt')
                updateCmakeListsFile(module_dir, program_name)
                logger.info('')
                logger.warning('# !!!!!!!!!!!!!!!!!!')
                logger.warning('# If your < %s > program has some Element and/or external dependencies,', \
                                program_name)
                logger.warning(
                    '# you maybe need to remove them. Check the <find_package,'
                )
                logger.warning(
                    '# elements_depends_on_subdirs> macros in the file :')
                logger.warning('# < %s >', cmakefile)
                logger.warning('# !!!!!!!!!!!!!!!!!!')
        else:
            logger.info('No file found for deletion!')
            logger.info('')

    except Exception as msg:
        if str(msg):
            logger.error(msg)
        logger.error('# Script aborted.')
        exit_code = Exit.Code["NOT_OK"]
    else:
        logger.info('# Script over.')

    return exit_code
示例#11
0
def makeChecks(project_dir, module_name, dependency_list):
    """
    Make some checks
    """
    # We absolutely need an Elements cmake file
    checkCmakelistFileExist(project_dir)
    ProjectCommonRoutines.checkNameAndVersionValid(module_name, '1.0')
    checkDependencyListValid(dependency_list)
示例#12
0
def createModuleDirectories(project_dir, module_name):
    """
    Create the directory structure for the module
    """
    # Create standalone directories
    standalone_directories = [module_name, "doc", "conf", "tests/src"]
    for d in standalone_directories:
        target_dir = os.path.join(project_dir, module_name, d)
        os.makedirs(target_dir)
        ProjectCommonRoutines.addItemToCreationList(target_dir)
示例#13
0
def mainMethod(args):
    """
    Main
    """

    exit_code = Exit.Code["OK"]

    logger = log.getLogger('CreateElementsProject')

    logger.info('#')
    logger.info(
        '#  Logging from the mainMethod() of the CreateElementsProject script')
    logger.info('#')

    proj_name = args.project_name
    proj_version = args.project_version
    dependant_projects = args.dependency
    destination_path = Project.setPath()
    dependency = args.dependency
    no_version_directory = args.no_version_directory
    standalone = args.standalone
    force_erase = args.erase
    answer_yes = args.yes

    logger.info('# Installation directory : %s', destination_path)

    try:
        # Set the project directory
        project_dir = Project.getProjectDirectory(no_version_directory,
                                                  destination_path, proj_name,
                                                  proj_version)
        Project.makeChecks(proj_name, proj_version, dependency,
                           dependant_projects)

        Project.checkProjectExist(project_dir, no_version_directory,
                                  force_erase, answer_yes)

        # Create the project
        Project.createProject(project_dir, proj_name, proj_version,
                              dependant_projects, standalone)

        # Print all files created
        ProjectCommonRoutines.printCreationList()

        logger.info('# <%s> project successfully created.', project_dir)

    except Exception as msg:
        if str(msg):
            logger.error(msg)
        logger.error('# Script aborted.')
        exit_code = Exit.Code["NOT_OK"]
    else:
        logger.info('# Script over.')

    return exit_code
示例#14
0
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()
示例#15
0
def mainMethod(args):
    """
    Main
    """

    logger.info('#')
    logger.info(
        '#  Logging from the mainMethod() of the AddPythonProgram script')
    logger.info('#')

    exit_code = Exit.Code["OK"]

    program_name = args.program_name

    try:
        # Default is the current directory
        current_dir = os.getcwd()

        logger.info('# Current directory : %s', current_dir)
        logger.info('')

        # We absolutely need a Elements cmake file
        module_name = ProjectCommonRoutines.getElementsModuleName(current_dir)

        program_file_path = os.path.join(current_dir, 'python', module_name,
                                         program_name + '.py')
        # Make checks
        makeChecks(program_file_path, program_name)

        # Create program
        createPythonProgram(current_dir, module_name, program_name)

        logger.info('< %s > program successfully created in < %s >.',
                    program_name, program_file_path)
        # Remove backup file
        ProjectCommonRoutines.deleteFile(
            os.path.join(current_dir, CMAKE_LISTS_FILE) + '~')

        # Print all files created
        ProjectCommonRoutines.printCreationList()

    except Exception as msg:
        if str(msg):
            logger.error(msg)
        logger.error('# Script aborted.')
        exit_code = Exit.Code["NOT_OK"]
    else:
        logger.info('# Script over.')

    return exit_code
示例#16
0
def mainMethod(args):
    """
    Main
    """

    logger.info('#')
    logger.info('#  Logging from the mainMethod() of the RemovePythonModule \
    script ')
    logger.info('#')

    exit_code = Exit.Code["OK"]

    pymodule_name = args.pymodule_name

    # Default is the current directory
    module_dir = os.getcwd()

    logger.info('Current directory : %s', module_dir)
    logger.info('')

    try:
        # We absolutely need a Elements cmake file
        module_name = ProjectCommonRoutines.getElementsModuleName(module_dir)

        # Default is the current directory
        file_to_be_deleted = getAllFiles(pymodule_name, module_dir,
                                         module_name)
        if file_to_be_deleted:
            logger.info('File to be deleted:')
            for elt_file in file_to_be_deleted:
                logger.info(' --> %s', elt_file)
            response_key = input('Do you want to continue?(y/n, default: n)')
            if response_key == 'Y' or response_key == 'y':
                ProjectCommonRoutines.removeFilesOnDisk(file_to_be_deleted)
                updateCmakeListsFile(module_dir)
        else:
            logger.info('')
            logger.info('No file found for deletion!')
            logger.info('')

    except Exception as msg:
        if str(msg):
            logger.error(msg)
        logger.error('# Script aborted.')
        exit_code = Exit.Code["NOT_OK"]
    else:
        logger.info('# Script over.')

    return exit_code
示例#17
0
def mainMethod(args):
    """
    Main
    """

    logger.info('#')
    logger.info('#  Logging from the mainMethod() of the AddCppProgram script')
    logger.info('#')

    exit_code = Exit.Code["OK"]

    program_name = args.program_name
    module_list = args.module_dependency
    library_list = args.library_dependency

    try:
        # Default is the current directory
        current_dir = os.getcwd()

        logger.info('Current directory : %s', current_dir)
        logger.info('')
        # We absolutely need a Elements cmake file
        module_name = ProjectCommonRoutines.getElementsModuleName(current_dir)
        # make some checks
        makeChecks(current_dir, program_name)
        # Create CPP program
        createCppProgram(current_dir, module_name, program_name, module_list,
                         library_list)

        location = os.path.join(current_dir, 'src', 'program')
        logger.info('< %s > program successfully created in < %s >.',
                    program_name, location)

        # Remove backup file
        ProjectCommonRoutines.deleteFile(
            os.path.join(current_dir, CMAKE_LISTS_FILE) + '~')

        # Print all files created
        ProjectCommonRoutines.printCreationList()

    except Exception as msg:
        if str(msg):
            logger.error(msg)
        logger.error('# Script aborted.')
        exit_code = Exit.Code["NOT_OK"]
    else:
        logger.info('# Script over.')

    return exit_code
示例#18
0
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))
示例#19
0
def mainMethod(args):
    """
    Main
    """

    logger.info('#')
    logger.info('#  Logging from the mainMethod() of the AddScript script')
    logger.info('#')

    exit_code = Exit.Code["OK"]

    program_name = args.program_name

    # Default is the current directory
    current_dir = os.getcwd()

    logger.info('# Current directory : %s', current_dir)
    logger.info('')

    try:
        # Check name in the Element Naming Database
        program_file_path = os.path.join(current_dir, 'scripts', program_name)
        # Make checks
        makeChecks(program_file_path, program_name)

        createScript(current_dir, program_name)
        logger.info('< %s > program successfully created in < %s >.',
                    program_name, program_file_path)

        # Remove backup file
        ProjectCommonRoutines.deleteFile(
            os.path.join(current_dir, CMAKE_LISTS_FILE) + '~')

        # Print all files created
        ProjectCommonRoutines.printCreationList()

    except Exception as msg:
        if str(msg):
            logger.error(msg)
        logger.error('# Script aborted.')
        exit_code = Exit.Code["NOT_OK"]
    else:
        logger.info('# Script over.')

    return exit_code
示例#20
0
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))
示例#21
0
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))
示例#22
0
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)
示例#23
0
def updateCmakeListsFile(module_dir):
    """
    Update the <CMakeLists.txt> file
    """
    logger.info('Updating the <%s> file', CMAKE_LISTS_FILE)
    cmake_filename = os.path.join(module_dir, CMAKE_LISTS_FILE)

    # Cmake file already exist
    if os.path.isfile(cmake_filename):
        # Backup the file
        ProjectCommonRoutines.makeACopy(cmake_filename)
        f = open(cmake_filename)
        data = f.read()
        f.close()
        # Add the program to be removed
        cmake_object = ParseCmakeLists.CMakeLists(data)
        cmake_object.elements_remove_python_module = 'elements_install_python_modules()'

    # Write new data
    f = open(cmake_filename, 'w')
    f.write(str(cmake_object))
    f.close()
示例#24
0
def makeChecks(program_file_path, program_name):
    """
    Make some checks
    """
    # Module as no version number, '1.0' is just for using the routine
    ProjectCommonRoutines.checkNameAndVersionValid(program_name, '1.0')
    ProjectCommonRoutines.checkFileNotExist(program_file_path, program_name)
    ProjectCommonRoutines.checkAuxFileExist(PROGRAM_TEMPLATE_FILE_IN)
示例#25
0
def mainMethod(args):
    """
    Main
    """

    exit_code = Exit.Code["OK"]

    logger.info('#')
    logger.info('#  Logging from the mainMethod() of the AddModule script ')
    logger.info('#')

    module_name = args.module_name
    dependency_list = args.module_dependency
    standalone = args.standalone
    answer_yes = args.yes

    # Default is the current directory
    project_dir = os.getcwd()
    logger.info('# Current directory : %s', project_dir)

    try:
        makeChecks(project_dir, module_name, dependency_list)
        createModule(project_dir, module_name, dependency_list, standalone,
                     answer_yes)
        logger.info('# <%s> module successfully created in <%s>.', module_name,
                    project_dir)
        # Print all files created
        ProjectCommonRoutines.printCreationList()

    except Exception as msg:
        if str(msg):
            logger.error(msg)
        logger.error('# Script aborted.')
        exit_code = Exit.Code["NOT_OK"]
    else:
        logger.info('# Script over.')

    return exit_code
示例#26
0
def makeChecks(module_file_path, python_module_name):
    """
    Make some checks
    """
    # Module as no version number? but '1.0' is just for using the routine
    ProjectCommonRoutines.checkNameAndVersionValid(python_module_name, '1.0')
    ProjectCommonRoutines.checkFileNotExist(module_file_path,
                                            python_module_name)
    ProjectCommonRoutines.checkAuxFileExist(PYTEST_TEMPLATE_FILE_IN)
示例#27
0
def makeChecks(current_dir, program_name):
    """
    Make some checks
    """
    # Check if file exits
    program_file_path = os.path.join(current_dir, 'src', 'program',
                                     program_name + '.cpp')
    ProjectCommonRoutines.checkFileNotExist(program_file_path, program_name)
    ProjectCommonRoutines.checkNameAndVersionValid(program_name, '1.0')
    ProjectCommonRoutines.checkAuxFileExist(PROGRAM_TEMPLATE_FILE_IN)
示例#28
0
def makeChecks(proj_name, proj_version, dependency, dependant_projects):
    """
    Make some checks
    """
    # Check project name and version
    ProjectCommonRoutines.checkNameAndVersionValid(proj_name, proj_version)
    if not dependency is None:
        checkDependencyProjectValid(dependant_projects)
    # Check for duplicate dependencies
    if not dependency is None:
        duplicate_elements(dependant_projects)
    # Check AUX files exist
    ProjectCommonRoutines.checkAuxFileExist(AUX_CMAKE_LIST_IN)
    ProjectCommonRoutines.checkAuxFileExist(AUX_MAKE_FILE_IN)
示例#29
0
def createFiles(module_dir, module_name, program_name):
    """
    Create files needed for a python program
    """
    init_file = os.path.join(module_dir, 'python', module_name, '__init__.py')
    ProjectCommonRoutines.createPythonInitFile(init_file)
    ProjectCommonRoutines.addItemToCreationList(init_file)

    conf_file = os.path.join(module_dir, 'conf', module_name,
                             program_name + '.conf')
    ProjectCommonRoutines.addItemToCreationList(conf_file)
    if not os.path.exists(conf_file):
        f = open(conf_file, 'w')
        f.write('# Write your program options here. e.g. : option = string')
        f.close()
示例#30
0
def updateCmakeListsFile(module_dir, module_name, program_name,
                         module_dep_list, library_dep_list):
    """
    Update CMakeLists.txt file
    """
    logger.info('Updating the <%s> file', CMAKE_LISTS_FILE)
    cmake_filename = os.path.join(module_dir, CMAKE_LISTS_FILE)
    ProjectCommonRoutines.addItemToCreationList(cmake_filename)

    # Cmake file already exist
    if os.path.isfile(cmake_filename):
        cmake_object, module_name = ProjectCommonRoutines.updateCmakeCommonPart(
            cmake_filename, library_dep_list)

        # 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)

        # Add elements_install_conf_files if any
        cmake_object.elements_install_conf_files = 'elements_install_conf_files()'

        # Update elements_add_executable macro
        source = os.path.join('src', 'program', program_name + '.cpp')
        existing_exe = [
            x for x in cmake_object.elements_add_executable_list
            if x.name == program_name
        ]
        existing_add_lib = [
            x for x in cmake_object.elements_add_library_list
            if x.name == module_name
        ]
        link_libs = ['ElementsKernel']
        include_dirs = ['ElementsKernel']
        if module_dep_list:
            link_libs = link_libs + module_dep_list
            include_dirs = include_dirs + module_dep_list
        if existing_add_lib:
            link_libs += [module_name]
            include_dirs += [module_name]
        if library_dep_list:
            link_libs = link_libs + library_dep_list
            include_dirs = include_dirs + library_dep_list
        if existing_exe:
            for lib in link_libs:
                if not lib in existing_exe[0].link_libraries_list:
                    existing_exe[0].link_libraries_list.append(lib)
            for incd in include_dirs:
                if not incd in existing_exe[0].include_dirs_list:
                    existing_exe[0].include_dirs_list.append(incd)
        else:
            exe_object = ParseCmakeListsMacros.ElementsAddExecutable(
                program_name, source, link_libs, include_dirs)
            cmake_object.elements_add_executable_list.append(exe_object)

    # Write new data
    f = open(cmake_filename, 'w')
    f.write(str(cmake_object))
    f.close()