예제 #1
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)
예제 #2
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)
예제 #3
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))
예제 #4
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)
예제 #5
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)