Ejemplo n.º 1
0
def Execute(rule, dirObj):
    """
    Execute the rule in the given directory
    """

    global has_executable

    if has_executable == '':
        has_executable = adagio.findExecutable(rule, dirObj)

    # If the executable is not present, notify and terminate
    if not has_executable:
        print i18n.get('no_executable').format(dirObj.options.get(rule, 'exec'))
        if dirObj.options.get(rule, 'partial') == '0':
            sys.exit(1)
        return

    # Get the files to process (all *.xcf in the current directory)
    toProcess = glob.glob(os.path.join(dirObj.current_dir, '*.xcf'))
    if toProcess == []:
        adagio.logDebug(rule, dirObj, i18n.get('no_file_to_process'))
        return

    scriptFileName = dirObj.getProperty(rule, 'script')
    if not os.path.isfile(scriptFileName):
        print i18n.get('file_not_found').format(scriptFileName)
        sys.exit(1)

    # Loop over the source files to see if an execution is needed
    dstFiles = []
    dstDir = dirObj.getProperty(rule, 'src_dir')
    for datafile in toProcess:
        adagio.logDebug(rule, dirObj, ' EXEC ' + datafile)

        # If file not found, terminate
        if not os.path.isfile(datafile):
            print i18n.get('file_not_found').format(datafile)
            sys.exit(1)

        # Derive the destination file name
        dstFile = os.path.splitext(os.path.basename(datafile))[0] + '.png'
        dstFile = os.path.abspath(os.path.join(dstDir, dstFile))

        # Check for dependencies!
        try:
            sources = set([datafile])
            sources.update(dirObj.option_files)
            dependency.update(dstFile, sources)
        except etree.XMLSyntaxError, e:
            print i18n.get('severe_parse_error').format(fName)
            print str(e)
            sys.exit(1)

        # If the destination file is up to date, skip the execution
        if dependency.isUpToDate(dstFile):
            print i18n.get('file_uptodate').format(os.path.basename(dstFile))
            continue

        # Remember the files to produce
        dstFiles.append(dstFile)
Ejemplo n.º 2
0
def doExecution(rule, dirObj, command, datafile, dstFile,
                stdout = None, stderr = None, stdin = None):
    """
    Function to execute a program using the subprocess.Popen method. The three
    channels (std{in, out, err}) are passed directly to the call.
    """

    # Check for dependencies if dstFile is given
    if dstFile != None:
        srcDeps = set(dirObj.option_files)
        if datafile != None:
            srcDeps.add(datafile)

        try:
            dependency.update(dstFile, srcDeps)
        except etree.XMLSyntaxError, e:
            print i18n.get('severe_parse_error').format(fName)
            print str(e)
            sys.exit(1)

        # If the destination file is up to date, skip the execution
        if dependency.isUpToDate(dstFile):
            print i18n.get('file_uptodate').format(os.path.basename(dstFile))
            return
        # Notify the production
        print i18n.get('producing').format(os.path.basename(dstFile))
Ejemplo n.º 3
0
def singleStyleApplication(datafile, styles, styleTransform, styleParams, dstFile, rule, dirObj, dataTree=None):
    """
    Apply a transformation to a file with a dictionary
    """

    # Check for dependencies!
    sources = set(styles + [datafile])
    sources.update(dirObj.option_files)
    dependency.update(dstFile, sources)

    # If the destination file is up to date, skip the execution
    if dependency.isUpToDate(dstFile):
        print i18n.get("file_uptodate").format(os.path.basename(dstFile))
        return dataTree

    # Proceed with the execution of xslt
    print i18n.get("producing").format(os.path.basename(dstFile))

    # Parse the data file if needed
    if dataTree == None:
        adagio.logInfo(rule, dirObj, "Parsing " + datafile)
        dataTree = treecache.findOrAddTree(datafile, True)

    # Apply the transformation
    xsltprocEquivalent(rule, dirObj, styleParams, datafile, dstFile)
    try:
        result = styleTransform(dataTree, **styleParams)
    except etree.XSLTApplyError, e:
        print
        print i18n.get("error_applying_xslt").format("\n".join(styles), datafile, rule)
        print "Error:", str(e)
        sys.exit(1)
Ejemplo n.º 4
0
def doShuffle(toProcess, dirObj):
    # Every source file given is processed to know how many permutations will be
    # produced.
    rawFiles = []
    for fname in toProcess:
        # Get the result files
        resultFiles = doGetShuffledFiles(fname)

        # Accumulate the list
        rawFiles.extend(resultFiles)

        # Update the dependencies (apply update to all elements in resultFiles)
        try:
            sources = set([fname])
            sources.update(dirObj.option_files)
            map(lambda x: dependency.update(x, sources), resultFiles)
        except etree.XMLSyntaxError, e:
            print i18n.get('severe_parse_error').format(fName)
            print e
            sys.exit(1)

        # If all the permutation files are up to date, no need to process
        if reduce(lambda x, y: x and y,
                  [dependency.isUpToDate(x) for x in resultFiles]):
            print i18n.get('testexam_no_shuffle_required').format(fname)
            continue

        print i18n.get('testexam_shuffling').format(fname)
        permutations = testshuffle.main(fname, adagio.userLog)

        if permutations == 0:
            print i18n.get('testexam_no_permutations').format(fname)
            sys.exit(1)
Ejemplo n.º 5
0
        command = [executable, '--no-data', '--no-fonts', '--no-interface', 
                   '-b', '-']

        scriptFile = open(scriptFileName, 'r')
        rules.doExecution(rule, dirObj, command, None, None,
                            stdout = adagio.userLog, stdin = scriptFile)
        scriptFile.close()

        # If dstFile does not exist, something went wrong
        if next((x for x in dstFiles if not os.path.exists(x)), None):
            print i18n.get('severe_exec_error').format(executable)
            sys.exit(1)

        # Update the dependencies of the newly created files
        try:
            map(lambda x: dependency.update(x), dstFiles)
        except etree.XMLSyntaxError, e:
            print i18n.get('severe_parse_error').format(fName)
            print str(e)
            sys.exit(1)

    return

def clean(rule, dirObj):
    """
    Clean the files produced by this rule
    """
    
    adagio.logInfo(rule, dirObj, 'Cleaning')

    # Get the files to process
Ejemplo n.º 6
0
def doCopy(rule, dirObj, toProcess, srcDir, dstDir):
    """
    Effectively perform the copy. The functionality is in this function because
    it is used also by the export rule.
    """

    # Identical source and destination, useless operation
    if os.path.abspath(srcDir) == os.path.abspath(dstDir):
        return

    # Loop over all source files to process
    for datafile in toProcess:
        # Normalize to avoid surprises
        datafile = os.path.normpath(datafile)

        # Remember if the source is a directory
        isDirectory = os.path.isdir(datafile)

        adagio.logDebug(rule, dirObj, ' EXEC ' + datafile)

        # If source is not found, terminate
        if not os.path.exists(datafile):
            print i18n.get('file_not_found').format(datafile)
            sys.exit(1)

        # Remove the srcDir prefix
        dstFile = datafile.replace(os.path.normpath(srcDir), '', 1)
        # If the result has a slash (could be a directory to copy or a file with
        # a directory path), remove it
        if dstFile[0] == os.sep:
            dstFile = dstFile[1:]

        # Derive the destination file name
        dstFile = os.path.abspath(os.path.join(dstDir, dstFile))

        # Check for dependencies!
        try:
            sources = set([datafile])
            sources.update(dirObj.option_files)
            dependency.update(dstFile, sources)
        except etree.XMLSyntaxError, e:
            print i18n.get('severe_parse_error').format(fName)
            print str(e)
            sys.exit(1)

        # Copying the file/dir
        adagio.logDebug(rule, dirObj, 'Copy? ' + datafile + ' ' +
                     dstFile)

        # If the destination file is up to date, skip the execution
        if (not isDirectory) and dependency.isUpToDate(dstFile):
            print i18n.get('file_uptodate').format(os.path.basename(dstFile))
            continue

        # Proceed with the execution of copy
        print i18n.get('copying').format(os.path.basename(dstFile))

        # Copying the file/dir
        adagio.logDebug(rule, dirObj, 'Copy ' + datafile + ' ' +
                     dstFile)

        if os.path.isdir(datafile):
            # Copy source tree to dst tree
            distutils.dir_util.copy_tree(datafile, dstFile)
        else:
            # It is a regular file, make sure the dirs leading to it are created
            dirPrefix = os.path.dirname(dstFile)
            if not os.path.exists(dirPrefix):
                os.makedirs(dirPrefix)

            # Proceed wih the copy
            shutil.copyfile(datafile, dstFile)

        # Update the dependencies of the newly created file
        if not isDirectory:
            try:
                dependency.update(dstFile)
            except etree.XMLSyntaxError, e:
                print i18n.get('severe_parse_error').format(fName)
                print str(e)
                sys.exit(1)
Ejemplo n.º 7
0
    except Exception, e:
        print i18n.get('severe_exec_error').format(command[0])
        print i18n.get('exec_line').format(' '.join(command))
        print e
        sys.exit(1)

    # If dstFile is given, update dependencies
    if dstFile != None:
        # If dstFile does not exist, something went wrong
        if not os.path.exists(dstFile):
            print i18n.get('severe_exec_error').format(command[0])
            sys.exit(1)

        # Update the dependencies of the newly created file
        try:
            dependency.update(dstFile)
        except etree.XMLSyntaxError, e:
            print i18n.get('severe_parse_error').format(fName)
            print str(e)
            sys.exit(1)

    return

def evaluateCondition(rule, options):
    """
    Evaluates the following condition with the given options (conjunction)

    1) option "enable_open" is '1'
    2) option "enable_begin" is empty or is a datetime before now
    3) option "enable_end" is empty or is a datetime past now
    4) If "adagio.enabled_profiles" is empty or contains the value of option