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 files to process, if empty, terminate toProcess = rules.getFilesToProcess(rule, dirObj) if toProcess == []: return # Prepare the command to execute executable = dirObj.getProperty(rule, 'exec') dstDir = dirObj.getProperty(rule, 'dst_dir') outputFormat = dirObj.getProperty(rule, 'output_format') if outputFormat == '': print i18n.get('empty_output_format').format(rule) sys.exit(1) # 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 dstFile = os.path.splitext(os.path.basename(datafile))[0] + \ '.' + outputFormat dstFile = os.path.abspath(os.path.join(dstDir, dstFile)) # Add the input file to the command command = [executable, '-L', outputFormat] command.extend(dirObj.getProperty(rule, 'extra_arguments').split()) command.extend([datafile, dstFile]) # Perform the execution rules.doExecution(rule, dirObj, command, datafile, dstFile, 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 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
dstFiles.append(dstFile) # If the execution is needed if dstFiles != []: executable = dirObj.getProperty(rule, 'exec') extraArgs = dirObj.getProperty(rule, 'extra_arguments') # Proceed with the execution fnames = ' '.join([os.path.basename(x) for x in dstFiles]) print i18n.get('producing').format(os.path.basename(fnames)) 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)
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
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(['tex', 'dvi', 'ps', 'pdf']): print i18n.get('program_incorrect_format').format(executable, outputFormat) sys.exit(1) # Prepare the command to execute dstDir = dirObj.getProperty(rule, 'dst_dir') if dirObj.getProperty(rule, 'compliant_mode') == '1': compliantOptions = \ '-P doc.collab.show=0 -P latex.output.revhistory=0'.split() else: compliantOptions = [] extraArgs = dirObj.getProperty(rule, 'extra_arguments') extraXsltArgs = dirObj.getProperty(rule, 'extra_xslt_arguments').split() extraXsltArgs = reduce(lambda x, y: x + ['-x', y], extraXsltArgs, []) commandPrefix = [executable, '-t', outputFormat] commandPrefix.extend(compliantOptions) commandPrefix.extend(extraXsltArgs) commandPrefix.extend(extraArgs.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 dstFile = os.path.splitext(os.path.basename(datafile))[0] + \ '.' + outputFormat dstFile = os.path.abspath(os.path.join(dstDir, dstFile)) # Add the output and input files to the command command = commandPrefix + ['-o', dstFile] + [datafile] # Perform the execution rules.doExecution(rule, dirObj, command, datafile, dstFile, adagio.userLog, adagio.userLog) return