예제 #1
0
def clean(rule, dirObj):
    """
    Clean the files produced by this rule
    """

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

    # Get the files to process
    toProcess = rules.getFilesToProcess(rule, dirObj)
    if toProcess == []:
        return

    # Loop over all source files to process
    dstDir = dirObj.getProperty(rule, 'dst_dir')
    nupOption = dirObj.getProperty(rule, 'nup')
    for datafile in toProcess:

        # 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] + \
            '-' + nupOption + os.path.splitext(os.path.basename(datafile))[1]
        dstFile = os.path.abspath(os.path.join(dstDir, dstFile))

        if not os.path.exists(dstFile):
            continue

        rules.remove(dstFile)

    return
예제 #2
0
def clean(rule, dirObj):
    """
    Clean the files produced by this rule
    """
    
    adagio.logInfo(rule, dirObj, 'Cleaning')

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

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

        # 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))

        if not os.path.exists(dstFile):
            continue

        rules.remove(dstFile)

    return
예제 #3
0
def doClean(rule, dirObj, toProcess, srcDir, dstDir):
    """
    Function to execute the core of the clean operation. It is in its own
    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

    for datafile in toProcess:

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

        # If file 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(srcDir, '', 1)
        # If the result has a slash, remove it
        if dstFile[0] == '/':
            dstFile = dstFile[1:]
        # Derive the destination file name
        dstFile = os.path.abspath(os.path.join(dstDir, dstFile))

        # If file is not there, bypass
        if not os.path.exists(dstFile):
            continue

        # Proceed with the cleaning (dump the file name being deleted)
        rules.remove(dstFile)
예제 #4
0
def doClean(rule, dirObj, toProcess, suffixes=None):
    """
    Function to perform the cleanin step
    """

    if suffixes == None:
        suffixes = [""]

        # Split the languages and remember if the execution is multilingual
    languages = dirObj.getProperty(rule, "languages").split()
    language_as = dirObj.getProperty(rule, "language_as").split()

    # If languages is empty, insert an empty string to force one execution
    if languages == []:
        languages = [""]
    multilingual = len(languages) > 1

    # Obtain the file extension to use
    outputFormat = processOuputFormat(rule, dirObj)

    # Loop over all source files to process
    dstDir = dirObj.getProperty(rule, "dst_dir")
    for datafile in toProcess:

        # Loop over the different suffixes
        for psuffix in suffixes:

            # Loop over languages
            for language in languages:
                # If processing multilingual, create the appropriate suffix
                lang_name = ""
                if multilingual:
                    if language_as == "suffix":
                        lang_name = language + "_"
                    else:
                        lang_name = "_" + language

                # Derive the destination file name
                if language_as == "suffix":
                    dstFile = lang_name + os.path.splitext(os.path.basename(datafile))[0] + psuffix + outputFormat
                else:
                    dstFile = os.path.splitext(os.path.basename(datafile))[0] + lang_name + psuffix + outputFormat
                dstFile = os.path.abspath(os.path.join(dstDir, dstFile))

                if not os.path.exists(dstFile):
                    continue

                rules.remove(dstFile)
예제 #5
0
def clean(rule, dirObj):
    """
    Clean the files produced by this rule
    """

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

    # Get the files to process
    toProcess = rules.getFilesToProcess(rule, dirObj)
    if toProcess == []:
        return

    # Loop over all source files to process
    dstDir = dirObj.getProperty(rule, 'dst_dir')
    outputFormat = dirObj.getProperty(rule, 'output_format')
    for datafile in toProcess:

        # 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
        dstPrefix = os.path.splitext(os.path.basename(datafile))[0]
        dstPrefix = os.path.join(dstDir, dstPrefix)

        extensionsToClean = ['out', 'aux', 'log', 'bbl', 'blg', 'idx',
                             'ilg', 'ind', 'lof', 'lot', 'toc']
        if outputFormat != 'dvipdf':
            extensionsToClean.append(outputFormat)
        else:
            extensionsToClean.append('dvi')
            extensionsToClean.append('pdf')

        for fmt in extensionsToClean:
            dstFile = dstPrefix + '.' + fmt

            if not os.path.exists(dstFile):
                continue

            rules.remove(dstFile)

    return
예제 #6
0
def clean(rule, dirObj):
    """
    Clean the files produced by this rule
    """

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

    # Get the files to process
    toProcess = rules.getFilesToProcess(rule, dirObj)
    if toProcess == []:
        return

    # Get geometry
    geometries = dirObj.getProperty(rule, 'geometry').split()
    if geometries == []:
        print i18n.get('no_var_value').format('geometry')
        return

    # Loop over all the source files
    dstDir = dirObj.getProperty(rule, 'dst_dir')
    for datafile in toProcess:

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

        # Loop over formats
        for geometry in geometries:
            # Derive the destination file name
            (fn, ext) = os.path.splitext(os.path.basename(datafile))
            dstFile = fn + '_' + geometry + ext
            dstFile = os.path.abspath(os.path.join(dstDir, dstFile))

            if not os.path.exists(dstFile):
                continue

            rules.remove(dstFile)

    return
예제 #7
0
def clean(rule, dirObj):
    """
    Clean the files produced by this rule
    """

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

    # Get the files to process
    toProcess = rules.getFilesToProcess(rule, dirObj)
    if toProcess == []:
        return

    # Get the dstDir
    dstDir = dirObj.getProperty(rule, 'dst_dir')

    # If dist dir not found, terminate
    if not os.path.isdir(dstDir):
        print i18n.get('file_not_found').format(dstDir)
        sys.exit(1)

    # Delete the dst directory
    rules.remove(dstDir)

    return
예제 #8
0
def clean(rule, dirObj):
    """
    Clean the files produced by this rule
    """

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

    # Get the files to process
    toProcess = rules.getFilesToProcess(rule, dirObj)
    if toProcess == []:
        return

    rawFiles = []
    for fname in toProcess:
        # Get the result files
        resultFiles = doGetShuffledFiles(fname)

        # Accumulate the list
        rawFiles.extend(resultFiles)

    suffixes = []
    produceValues = set(dirObj.getProperty(rule, 'produce').split())
    if 'regular' in produceValues:
        # Delete the regular version
        suffixes.append('')
    if 'solution' in produceValues:
        # Delete the solution
        suffixes.append('_solution')
    if 'pguide' in produceValues:
        # Delete the professor guide
        suffixes.append('_pguide')

    xsltproc.doClean(rule, dirObj, rawFiles, suffixes)

    # Clean also the produced files
    map(lambda x: rules.remove(x), rawFiles)

    return