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)
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, if empty, terminate toProcess = rules.getFilesToProcess(rule, dirObj) if toProcess == []: adagio.logDebug(rule, dirObj, i18n.get('no_file_to_process')) return # Loop over all source files to process executable = dirObj.getProperty(rule, 'exec') extraArgs = dirObj.getProperty(rule, 'extra_arguments') # The command is soffice --nologo --invisible --headless # --convert-to pdf *.doc command = [executable, '--nologo', '--invisible', '--headless', '--convert-to', 'pdf'] command.extend(extraArgs.split()) 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 dstFileName = os.path.splitext(os.path.basename(datafile))[0] + \ '.pdf' dstFile = os.path.abspath(os.path.join(dstDir, dstFileName)) # Perform the execution command.append(datafile) # command.append('macro:///Tools.MSToPDF.ConvertMSToPDF(' + datafile + ')') rules.doExecution(rule, dirObj, command, datafile, dstFile, stdout = adagio.userLog) command.pop(-1) # End of loop over all src files return
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 directories to synchronize, check if work is needed srcDir = dirObj.getProperty(rule, 'src_dir') dstDir = dirObj.getProperty(rule, 'dst_dir') if srcDir == '' or dstDir == '' or srcDir == dstDir: return # If source directory does not exist, terminate if not os.path.isdir(srcDir): print i18n.get('not_a_directory').format(srcDir) sys.exit(1) # Prepare the command to execute executable = dirObj.getProperty(rule, 'exec') extraArgs = dirObj.getProperty(rule, 'extra_arguments') command = [executable, '-avz'] command.append(srcDir) command.append(dstDir) adagio.logDebug(rule, dirObj, ' EXEC ' + srcDir + ' ' + dstDir) # Perform the execution rules.doExecution(rule, dirObj, command, srcDir, None, adagio.userLog, adagio.userLog) return
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, if empty, terminate toProcess = rules.getFilesToProcess(rule, dirObj) if toProcess == []: return executable = dirObj.getProperty(rule, 'exec') outputFormat = dirObj.getProperty(rule, 'output_format') if not outputFormat in set(['dvi', 'pdf', 'dvipdf']): print i18n.get('program_incorrect_format').format(executable, outputFormat) sys.exit(1) # Prepare the command to execute dstDir = dirObj.getProperty(rule, 'dst_dir') commandPrefix = [executable, '-output-directory=' + dstDir, '-interaction=nonstopmode'] if outputFormat != 'dvipdf': commandPrefix.append('-output-format=' + outputFormat) commandPrefix.extend(dirObj.getProperty(rule, 'extra_arguments').split()) # Loop over all source files to process 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 baseName = os.path.splitext(os.path.basename(datafile))[0] if outputFormat != 'dvipdf': dstFile = baseName + '.' + outputFormat else: dstFile = baseName + '.dvi' pdfFile = baseName + '.pdf' dstFile = os.path.abspath(os.path.join(dstDir, dstFile)) # Add the input file to the command command = commandPrefix + [datafile] # Perform the execution rules.doExecution(rule, dirObj, command, datafile, dstFile, adagio.userLog) if outputFormat == 'dvipdf': rules.doExecution(rule, dirObj, ['dvipdf', dstFile], datafile, pdfFile, adagio.userLog) return
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, if empty, terminate toProcess = rules.getFilesToProcess(rule, dirObj) if toProcess == []: adagio.logDebug(rule, dirObj, i18n.get('no_file_to_process')) return # Get geometry geometries = dirObj.getProperty(rule, 'geometry').split() if geometries == []: print i18n.get('no_var_value').format('geometry') return # Loop over all source files to process executable = dirObj.getProperty(rule, 'exec') extraArgs = dirObj.getProperty(rule, 'extra_arguments') convertCrop = dirObj.getProperty(rule, 'crop_option') dstDir = dirObj.getProperty(rule, 'dst_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) # 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)) # Creat the command to execute (slightly non-optimal, because the # following function might NOT execute the process due to # dependencies command = [executable, '-scale', geometry] command.extend(convertCrop.split()) command.extend(extraArgs.split()) command.append(datafile) command.append(dstFile) # Perform the execution rules.doExecution(rule, dirObj, command, datafile, dstFile, adagio.userLog) return