Beispiel #1
0
 def initExportFilter(self, id, REQUEST):
   # Set environment variables.
   instance_home = standard.getINSTANCE_HOME()
   package_home = standard.getPACKAGE_HOME()
   package_home = os.path.normpath(package_home)
   REQUEST.set( 'ZMS_FILTER', True)
   REQUEST.set( 'ZMS_FILTER_INSTANCE_HOME', instance_home)
   REQUEST.set( 'ZMS_FILTER_PACKAGE_HOME', package_home)
   # Set local variables.
   ob_filter = self.getFilterManager().getFilter(id)
   ob_filter_format = ob_filter.get('format', '')
   # Create temporary folder.
   tempfolder = tempfile.mktemp()
   ressources = self.exportRessources( tempfolder, REQUEST, from_zms=ob_filter_format=='XHTML', from_home=ob_filter_format=='XHTML')
   # Export data to file.
   if ob_filter_format == 'export':
     outfilename = _fileutil.getOSPath('%s/INDEX0'%tempfolder)
   elif ob_filter_format in ['XML', 'XML_incl_embedded']:
     # Set XML.
     data = self.toXml( REQUEST)
     outfilename = _fileutil.getOSPath('%s/export.xml'%tempfolder)
     _fileutil.exportObj( data, outfilename)
   elif ob_filter_format == 'XHTML':
     # Set XHTML.
     data = self.toXhtml( REQUEST)
     outfilename = _fileutil.getOSPath('%s/export.html'%tempfolder)
     _fileutil.exportObj( data, outfilename)
   elif ob_filter_format == 'myXML':
     # Set myXML.
     data = self.getXmlHeader() + getattr( self, 'getObjToXml_DocElmnt')(context=self)
     outfilename = _fileutil.getOSPath('%s/export.xml'%tempfolder)
     _fileutil.exportObj( data, outfilename)
   else:
     raise zExceptions.InternalError("Unknown format '%s'"%ob_filter.get('format', ''))
   return tempfolder, outfilename
Beispiel #2
0
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
Beispiel #3
0
 def getPACKAGE_HOME(self):
     warn(self, 'getPACKAGE_HOME', 'Products.zms.standard.getPACKAGE_HOME')
     return standard.getPACKAGE_HOME()
Beispiel #4
0
 def getPath(self, REQUEST): 
   path = standard.getPACKAGE_HOME()
   if 'path' in REQUEST:
     path = REQUEST['path']
   path = path.strip()
   return path
Beispiel #5
0
    def manage_export(self, export_format, lang, REQUEST, RESPONSE):
        """ Exportable.manage_export """

        title = self.getHome().id + '_' + self.id_quote(
            self.getTitlealt(REQUEST))

        # Get export format.
        try:
            export_format = int(export_format)
        except:
            pass

        get_data = REQUEST.get('download', 1) == 1

        # ZEXP.
        if export_format == 0:
            filename = '%s.zexp' % self.id
            export = self.aq_parent.manage_exportObject(id=self.id, download=1)
            content_type = 'application/data'

        # HTML.
        elif export_format == 1:
            filename = '%s_html.zip' % title
            export = self.toZippedHtml(REQUEST, get_data)
            content_type = 'application/zip'

        # XML.
        elif export_format == 2:
            filename = '%s_xml.zip' % title
            export = self.toZippedXml(REQUEST, get_data)
            content_type = 'application/zip'

        # myXML.
        elif export_format == 3:
            instance_home = standard.getINSTANCE_HOME()
            package_home = standard.getPACKAGE_HOME()
            package_home = os.path.normpath(package_home)
            REQUEST.set('ZMS_FILTER_INSTANCE_HOME', instance_home)
            REQUEST.set('ZMS_FILTER_PACKAGE_HOME', package_home)
            filename = '%s.xml' % title
            export = self.getXmlHeader() + getattr(
                self, 'getObjToXml_DocElmnt')(context=self)
            content_type = 'text/xml'

        # Export Filter.
        elif export_format in self.getFilterManager().getFilterIds():
            if REQUEST.get('debug'):
                url = self.url_append_params('manage_importexportDebugFilter',
                                             {
                                                 'lang': lang,
                                                 'filterId': export_format,
                                                 'debug': 1
                                             })
                return RESPONSE.redirect(url)
            else:
                filename, export, content_type = _filtermanager.exportFilter(
                    self, export_format, REQUEST)

        # return export for download to browser
        if get_data:
            RESPONSE.setHeader('Content-Type', content_type)
            RESPONSE.setHeader('Content-Disposition',
                               'inline;filename="%s"' % filename)
            return export
        else:
            message = 'Exported to %s (%s)' % (export, content_type)
            url = '%s/manage_importexport' % self.absolute_url()
            url = self.url_append_params(url, {
                'lang': lang,
                'manage_tabs_message': message
            })
            RESPONSE.redirect(url)