Beispiel #1
0
def findExecutable(rule, dirObj):
    """
    Function to search if an executable is available in the machine. Lifted from
    StackOverflow and modified to account for possible executable suffixes
    stored in Windows in the environment variable PATHEXT.
    """

    # Get the program name
    program = properties.getProperty(dirObj.options, rule, 'exec')

    suffixes = ['']
    pext = os.environ.get("PATHEXT")
    if pext:
        suffixes = pext.split(';')

    def is_exe(fpath, suffixes):
        # Return the first executable when concatenating a suffix
        return next((fpath + s for s in suffixes \
                        if os.path.exists(fpath + s) and \
                         os.access(fpath + s, os.X_OK)), None)

    fpath, fname = os.path.split(program)
    if fpath:
        return is_exe(program, suffixes)

    # Return the first executable when traversing the path
    for path in os.environ["PATH"].split(os.pathsep):
        executable = is_exe(os.path.join(path, program), suffixes)
        # If found, return it
        if executable != None:
            properties.setProperty(dirObj.options, rule, 'exec', executable) 
            return executable

    return None
Beispiel #2
0
def AppendOptions(config, sectionName, options, documentation):
    """
    Function that incorporates to the given config a set of options as part of
    the given section. The documentation string is added taking into account the
    current languages.
    """
    
    global variable_help_messages
    # If the section is already present in the config, never mind
    try:
        config.add_section(sectionName)
    except ConfigParser.DuplicateSectionError:
        pass

    # Loop over all the default values and add them to the proper sections
    for (vn, vv, msg) in options:
        properties.setProperty(config, sectionName, vn, vv,
                               createRule = True, createOption = True)
        
        variable_help_messages[sectionName + '.' + vn] = msg
        
    # Add the string for the help
    helpStr = documentation.get(config_defaults['languages'][0].split()[0])
    if helpStr == None:
        helpStr = documentation.get('en')
    properties.setProperty(config, sectionName, 'help', helpStr,
                           createRule = True, createOption = True)
    return
Beispiel #3
0
        #
        # STEP 5: Options given from outside the directory
        #
        for assignment in givenOptions:
            # Chop assignment into its three parts
            (sn, on, ov) = assignment.split()

            sn = properties.expandAlias(sn, self.alias)
            # Check first if the option is legal
            if not self.options.has_option(sn, on):
                optionName = sn + '.' + on
                print i18n.get('incorrect_option').format(optionName)
                sys.exit(3)

            # Insert the new assignment in options of the directory
            properties.setProperty(self.options, sn, on, ov)

        # Compare Adagio versions to see if execution is allowed
        if not self.isCorrectAdagioVersion():
            version = self.options.get(adagio.module_prefix, 'version')
            adagio.logError('Directory', None, \
                             'ERROR: Incorrect Adagio Version (' + version + ')')
            print i18n.get('incorrect_version').format(version)
            sys.exit(3)

        self.current_rule = None

        # Dump a debug message showing the list of rules detected in the
        # config file
        adagio.logDebug('Directory', None,
                     'Rules: ' + ', '.join(self.rule_list))