def processCommand(self, filename, command): standard.writeBlock( self, '[processCommand]: infilename=%s'%filename) infilename = _fileutil.getOSPath( filename) outfilename = _fileutil.getOSPath( filename) mCurDir = '{cur_dir}' mIn = '{in}' mOut = '{out}' i = command.find(mOut[:-1]) if i >= 0: j = command.find('}', i) mExt = command[i+len(mOut[:-1]):j] mOut = command[i:j+1] if len(mExt) > 0: outfilename = outfilename[:outfilename.rfind('.')] + mExt else: outfilename += '.tmp' tmpoutfilename = outfilename + '~' instance_home = standard.getINSTANCE_HOME() package_home = standard.getPACKAGE_HOME() package_home = os.path.normpath(package_home) command = command.replace( '{package_home}', package_home) command = command.replace( '{instance_home}', instance_home) command = command.replace( mCurDir, _fileutil.getFilePath(infilename)) command = command.replace( mIn, infilename) command = command.replace( mOut, tmpoutfilename) # Change directory (deprecated!). if self.getConfProperty('ZMS.filtermanager.processCommand.chdir', 0): path = _fileutil.getFilePath(filename) standard.writeBlock( self, '[processCommand]: path=%s'%path) os.chdir(path) # Execute command. standard.writeBlock( self, '[processCommand]: command=%s'%command) os.system(command) # Check if output file exists. try: os.stat( _fileutil.getOSPath( tmpoutfilename)) standard.writeBlock( self, '[processCommand]: rename %s to %s'%( tmpoutfilename, outfilename)) try: os.remove( outfilename) except OSError: pass os.rename( tmpoutfilename, outfilename) except OSError: outfilename = infilename # Remove input file if it is the result of a transformation of output file. if outfilename != infilename: os.remove( infilename) # Return filename. standard.writeBlock( self, '[processCommand]: outfilename=%s'%( outfilename)) return outfilename
def importFilter(self, filename, id, REQUEST): ob_filter = self.getFilterManager().getFilter(id) folder = _fileutil.getFilePath(filename) # Process filter. filename = processFilter(self, ob_filter, folder, filename, REQUEST) # Return filename. return filename
def processFile(self, processId, filename, trans=None): standard.writeBlock( self, '[processFile]: processId=%s'%processId) folder = _fileutil.getFilePath(filename) processOb = self.getFilterManager().getProcess(processId) command = processOb.get('command') # Save transformation to file. if trans: command = command.replace( '{trans}', getTransFilename(self, folder, trans)) # Execute command. filename = processCommand(self, filename, command) # Return filename. return filename
def processMethod(self, processId, filename, trans, REQUEST): standard.writeLog( self, '[processMethod]: processId=%s'%processId) infilename = filename outfilename = filename REQUEST.set( 'ZMS_FILTER_IN', infilename) REQUEST.set( 'ZMS_FILTER_OUT', outfilename) REQUEST.set( 'ZMS_FILTER_TRANS', trans) REQUEST.set( 'ZMS_FILTER_CUR_DIR', _fileutil.getFilePath(infilename)) try: value = getattr( self, processId)( self, REQUEST) except: value = standard.writeError( self, '[processMethod]: processId=%s'%processId) outfilename = REQUEST.get( 'ZMS_FILTER_OUT') # Return filename. return outfilename
def processMethod(self, processId, filename, trans, REQUEST): standard.writeBlock( self, '[processMethod]: processId=%s'%processId) infilename = filename outfilename = filename REQUEST.set( 'ZMS_FILTER_IN', infilename) REQUEST.set( 'ZMS_FILTER_OUT', outfilename) REQUEST.set( 'ZMS_FILTER_TRANS', trans) REQUEST.set( 'ZMS_FILTER_CUR_DIR', _fileutil.getFilePath(infilename)) try: process = self.getFilterManager().getProcess(processId) ob = process['ob'] value = zopeutil.callObject( ob, self) except: value = standard.writeError( self, '[processMethod]: processId=%s'%processId) outfilename = REQUEST.get( 'ZMS_FILTER_OUT') # Return filename. return outfilename
def importContent(self, file): # Setup. catalog_awareness = self.getConfProperty('ZMS.CatalogAwareness.active', 1) self.setConfProperty('ZMS.CatalogAwareness.active', 0) self.dTagStack = collections.deque() self.dValueStack = collections.deque() self.oParent = self.getParentNode() # Parse XML-file. ob = self.parse(file, self, 1) # Process objects after import recurse_importContent(ob, _fileutil.getFilePath(file.name)) # Cleanup. self.setConfProperty('ZMS.CatalogAwareness.active', catalog_awareness) # Return imported object. return ob
def getParentDir(self, path): return _fileutil.getFilePath( path)