コード例 #1
0
ファイル: _filtermanager.py プロジェクト: zms-publishing/ZMS2
def processCommand(self, filename, command):
  _globals.writeLog( self, '[processCommand]: infilename=%s'%filename)
  infilename = _fileutil.getOSPath( filename)
  outfilename = _fileutil.getOSPath( filename)
  mZmsHome = '{zms_home}'
  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 = INSTANCE_HOME
  software_home = os.path.join(SOFTWARE_HOME, '..%s..' % os.sep)
  software_home = os.path.normpath(software_home)  
  command = command.replace( '{software_home}', software_home)
  command = command.replace( '{instance_home}', instance_home)
  command = command.replace( mZmsHome,_fileutil.getOSPath(package_home(globals())))
  command = command.replace( mCurDir,_fileutil.getFilePath(infilename))
  command = command.replace( mIn,infilename)
  command = command.replace( mOut,tmpoutfilename)
  path = _fileutil.getFilePath(filename)
  _globals.writeLog( self, '[processCommand]: path=%s'%path)
  os.chdir(path)
  _globals.writeLog( self, '[processCommand]: command=%s'%command)
  os.system(command)
  # Check if output file exists.
  try: 
    os.stat( _fileutil.getOSPath( tmpoutfilename)) 
    _globals.writeLog( 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.
  _globals.writeLog( self, '[processCommand]: outfilename=%s'%( outfilename))
  return outfilename
コード例 #2
0
ファイル: _filtermanager.py プロジェクト: zms-publishing/ZMS2
def importFilter(self, filename, id, REQUEST):
  ob_filter = self.getFilter(id)
  folder = _fileutil.getFilePath(filename)
  # Process filter.
  filename = processFilter(self, ob_filter, folder, filename, REQUEST)
  # Return filename.
  return filename
コード例 #3
0
ファイル: _filtermanager.py プロジェクト: zms-publishing/ZMS2
def processFile(self, processId, filename, trans=None):
  _globals.writeLog( self, '[processFile]: processId=%s'%processId)
  folder = _fileutil.getFilePath(filename)
  processOb = self.getProcess(processId)
  command = processOb.get('command')
  # Save transformation to file.
  if trans is not None and trans != '':
    transfilename = '%s/%s'%( folder, trans.getFilename())
    command = command.replace( '{trans}', transfilename)
  # Execute command.
  filename = processCommand(self, filename, command)
  # Return filename.
  return filename
コード例 #4
0
ファイル: _filtermanager.py プロジェクト: zms-publishing/ZMS2
def processMethod(self, processId, filename, trans, REQUEST):
  _globals.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 = _globals.writeError( self, '[processMethod]: processId=%s'%processId)
  outfilename = REQUEST.get( 'ZMS_FILTER_OUT')
  # Return filename.
  return outfilename
コード例 #5
0
def importContent(self, file):
  message = ''
  
  # Setup.
  catalog_awareness = self.getConfProperty('ZMS.CatalogAwareness.active',1)
  self.setConfProperty('ZMS.CatalogAwareness.active',0)
  self.dTagStack = _globals.MyStack()
  self.dValueStack = _globals.MyStack()
  self.oParent = self.getParentNode()
  
  # Parse XML-file.
  ob = self.parse(StringIO(file.read()),self,1)
  
  # Process objects after import
  message += recurse_importContent(ob,_fileutil.getFilePath(file.name))
  
  # Cleanup.
  self.setConfProperty('ZMS.CatalogAwareness.active',catalog_awareness)
  
  # Return with message.
  return message
コード例 #6
0
ファイル: _mediadb.py プロジェクト: zms-publishing/ZMS2
 def getParentDir(self, path):
     return _fileutil.getFilePath(path)