예제 #1
0
def import_configuration(file_name=None, verbose=True):
    """
    Load in the configuration file

    Using the file PROJECTSRC, load it in and parse it as an INI
    file using the configparser python class.

    Args:
        file_name: File to load for configuration
        verbose: If True, print the loaded file''s name.

    Returns:
        An empty parser object or filled with a successfully loaded file
    """

    if file_name is None:
        file_name = DEFAULT_BUILD_RULES

    build_rules = None
    if file_name and os.path.exists(file_name):
        build_rules = import_py_script(file_name)
        if verbose:
            if build_rules:
                print('Using configuration file {}'.format(file_name))
            else:
                print('build_rules.py was corrupt.')
    else:
        if verbose:
            print('No configuration file found, using defaults')
        build_rules = import_py_script(
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         BUILD_RULES_PY))
    return build_rules
예제 #2
0
def do_prebuild(working_directory):
    """ Create the super header for extracting documentation.

    :Args:
        working_dir: Directory where the headers to copy are located

    Returns:
        Zero on no error, non-zero on error

    """

    # Update the changelist header
    root_folder = os.path.dirname(working_directory)
    script = import_py_script(os.path.join(root_folder, 'build_rules.py'))
    if not script:
        return 10

    error = script.do_prebuild(root_folder)
    return error
예제 #3
0
def clean(working_directory):
    """
    Delete temporary files.

    This function is called by ``cleanme`` to remove temporary files.

    On exit, return 0 for no error, or a non zero error code if there was an
    error to report.

    Args:
        working_directory
            Directory this script resides in.

    Returns:
        None if not implemented, otherwise an integer error code.
    """

    # The function exists in setup.py.
    # It can be manually invoked with "setup.py clean"
    setup = import_py_script(os.path.join(working_directory, 'setup.py'))
    setup.clean(working_directory)
    return 0
예제 #4
0
def add_build_rules(build_rules_list, file_name, args):
    """
    Load in the file build_rules.py

    Load the build_rules.py file. If the parameter ``root`` was found in the
    parameter list of the function project_rules, check if the default argument
    is ``True`` to abort after execution.

    Args:
        build_rules_list: List to append a valid build_rules file instance.
        file_name: Full path name of the build_rules.py to load.
        args: Args for determining verbosity for output.
    Returns:
        Zero on no error, non zero integer on error
    """

    # Test if there is a specific build rule
    file_name = os.path.abspath(file_name)
    build_rules = burger.import_py_script(file_name)
    if not build_rules:
        return False

    if args.verbose:
        print('Using configuration file {}'.format(file_name))

    # Find the entry point
    rules = getattr(build_rules, 'rules', None)
    if rules:

        # Get the function signature
        sig = signature(rules)

        parm_root = sig.parameters.get('root')
        if parm_root:
            if parm_root.default is True:
                args.version = True
    build_rules_list.append(rules)
    return True
예제 #5
0
def dispatch(file_name, working_directory, args):
    """
    Dispatch to ``rules('clean')``.

    Dispatch to the build_rules.py file to the cleanme
    function of ``rules('clean')`` and return the error code
    if found. If the parameter ``root`` was found in the
    parameter list, check if the default argument is ``True`` to
    abort after execution.

    Args:
        file_name: full path of the build_rules.py file
        working_directory: directory to pass to the ``rules('clean')`` function
        args: Args for determining verbosity for output

    Returns:
        Zero on no error, non zero integer on error

    """
    # Too many branches
    # pylint: disable=R0912

    build_rules = import_py_script(file_name)
    found_root = False
    error = 0
    while build_rules:
        if args.verbose:
            print('Using configuration file {}'.format(file_name))

        # Perform the clean on this folder, if there's a clean function
        rules = getattr(build_rules, 'rules', None)
        if rules:

            # Get the function signature
            sig = signature(rules)

            parm_root = sig.parameters.get('root')
            if parm_root:
                if parm_root.default is True:
                    found_root = True

            # Test for working directory
            parm_working_directory = sig.parameters.get('working_directory')
            if not parm_working_directory:
                if args.verbose:
                    print('function rules() doesn\'t have a parameter for '
                          'working_directory ')
                error = 10
                break

            if parm_working_directory.default is Parameter.empty:
                temp_dir = os.path.dirname(file_name)
            else:
                temp_dir = parm_working_directory.default
            if temp_dir:
                if working_directory != temp_dir:
                    if args.verbose:
                        print(
                            'function rules() not called '
                            'due to directory mismatch. '
                            'Expected {}, found {}'.format(
                                temp_dir, working_directory))
                    break

            # rules is not callable (Actually it is)
            # pylint: disable=E1102
            error = rules(command='clean', working_directory=working_directory)
        break
    return error, found_root