示例#1
0
        else:
            # If there is no rule file, notify
            adagio.logInfo('Directory', None, 'No ' + adagioPropFile + \
                            ' found in ' + self.current_dir)
            print i18n.get('cannot_find_properties').format(adagioPropFile,
                                                            self.current_dir)
            self.rule_list = []

        #
        # 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)
示例#2
0
def clean(rule, dirObj, deepClean = False, pad = None):
    """
    Clean the files produced by this rule
    """

    global module_prefix

    if pad == None:
        pad = ''

    adagio.logInfo(rule, dirObj, 'Cleaning')

    (toProcess, remoteRules,
     optionsToSet, newExportDir) = prepareRule(rule, dirObj)

    # When cleaning, rules should be executed in reversed order
    remoteRules.reverse()

    if deepClean:
        # If the clean is deep, attach .clean suffix to all remote rules
        remoteRules = [x + '.deepclean'
                         for x in remoteRules
                         if not re.match('(.+\.)?help$', x) and \
                             not re.match('(.+\.)?vars$', x)and \
                             not re.match('(.+\.)?clean$', x)]

        # If no rule is obtained, deep clean, means simply execute the clean
        # rule
        if remoteRules == []:
            remoteRules = ['deepclean']
    else:
        # If the clean is not deep, the execution only propagates to those rules
        # of type export and if the newExportDir is this directory (to clean the
        # current directory only). Otherwise, the rule is simply ignored.
        if newExportDir != dirObj.current_dir:
            return

        remoteRules = [x + '.clean'  for x in remoteRules
                         if x.startswith('export')]

    adagio.logInfo(rule, dirObj,
                'Remote Rules = ' + ' '.join(remoteRules))

    # Loop over each directory
    for dirName in toProcess:

        adagio.logInfo(rule, dirObj, 'RECUR: ' + dirName)
        remoteObj = directory.getDirectoryObject(dirName, optionsToSet)

        # If the clean is not deep and there is no given remote rules, we need
        # to select those that start with 'export'
        if (not deepClean) and (remoteRules == []):
            remoteRules = [x + '.clean' for x in remoteObj.rule_list
                             if re.match('^export(\..+)?$',
                                         properties.expandAlias(x,
                                                                remoteObj.alias))]

        # If remoteRules empty, there is nothing to process in the remote
        # directory.
        if remoteRules == []:
            continue

        # Execute the remote rules
        remoteObj.Execute(remoteRules, pad + '  ')

    return
示例#3
0
def Execute(rule, dirObj, pad = None):
    """
    Given a rule and a directory, it checks which rule needs to be invoked and
   performs the invokation.
    """

    global modules

    # Keep a copy of the rule before applying aliases
    originalRule = rule

    # Apply the alias expansion
    try:
        rule = properties.expandAlias(rule, dirObj.alias)
    except SyntaxError:
        print i18n.get('error_alias_expression')
        sys.exit(1)

    # Detect help, vars or clean rule
    specialRule = re.match('.+\.help$', rule) or \
        re.match('.+\.vars$', rule) or \
        re.match('.+\.clean$', rule) or \
        re.match('.+\.deepclean$', rule)

    # Make sure the rule is legal.
    if not specialRule and not dirObj.options.has_section(rule):
        print i18n.get('illegal_rule_name').format(t = originalRule,
                                                     dl = dirObj.current_dir)
        sys.exit(2)

    # Get the module prefix (everything up to the first dot) and the rule prefix
    # (dropping any special rule suffix)
    ruleParts = rule.split('.')
    modulePrefix = ruleParts[0]
    if specialRule:
        rulePrefix = '.'.join(ruleParts[:-1])
    else:
        rulePrefix = rule

    if pad == None:
	pad = ''

    # Traverse the modules and execute the "Execute" function
    executed = False
    for moduleName in modules:

        # If the rule does not belong to this module, keep iterating
        if modulePrefix != eval(moduleName + '.module_prefix'):
            continue

        logInfo(originalRule, dirObj, 'Enter ' + dirObj.current_dir)

        # Print msg when beginning to execute a rule in dir
        print pad + 'BB', originalRule

        # Detect and execute "help" rule
        if helpRule(rule, dirObj, moduleName, pad):
            print pad + 'EE', originalRule
            logInfo(originalRule, dirObj, 'Exit ' + dirObj.current_dir)
            return

        # Detect and execute "vars" rule
        if varsRule(rule, dirObj, moduleName, pad):
            print pad + 'EE', originalRule
            logInfo(originalRule, dirObj, 'Exit ' + dirObj.current_dir)
            return

        # Check the condition
        if not rules.evaluateCondition(rulePrefix, dirObj.options):
            return

        # Detect and execute "clean" rules
        if cleanRules(rule, dirObj, moduleName, pad):
            print pad + 'EE', originalRule
            logInfo(originalRule, dirObj, 'Exit ' + dirObj.current_dir)
            return

        # Execute.
        if moduleName == 'gotodir':
            # gotodir must take into account padding
            eval(moduleName + '.Execute(rule, dirObj, pad)')
        else:
            eval(moduleName + '.Execute(rule, dirObj)')

        # Detect if no module executed the rule
        executed = True

        print pad + 'EE', originalRule

        logInfo(originalRule, dirObj, 'Exit ' + dirObj.current_dir)

        # Once the rule executed, no need to keep checking for the rest of modules
        break

    # Special case of targets of the "default" module.
    if modulePrefix == 'adagio':
        print pad + 'BB', originalRule

        # Detect and execute "help" rule
        if helpRule(rule, dirObj, 'adagio', pad):
            print pad + 'EE', originalRule
            logInfo(originalRule, dirObj, 'Exit ' + dirObj.current_dir)
            return

        # Detect and execute "vars" rule
        if varsRule(rule, dirObj, 'adagio', pad):
            print pad + 'EE', originalRule
            logInfo(originalRule, dirObj, 'Exit ' + dirObj.current_dir)
            return

    if not executed:
        print i18n.get('unknown_rule').format(originalRule)
        sys.exit(1)