Diff for /OSAS/OSA_system/OSAS_add.py between versions 1.40 and 1.53

version 1.40, 2005/01/20 13:38:02 version 1.53, 2010/02/15 19:09:00
Line 1 Line 1
 #Neue Version Begin 5.4.2004  #Neue Version Begin 5.4.2004
   
   
 """Methoden zum hinzufügen von Dokumenten ins Archiv"""  """Methoden zum hinzufuegen von Dokumenten ins Archiv"""
 from OSAS_helpers import readArchimedesXML   from OSAS_helpers import readArchimedesXML 
 try:  try:
     import archive      import archive
Line 9  except: Line 9  except:
     print "archive not imported"      print "archive not imported"
           
 import os  import os
   import os.path
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile  from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from Products.PageTemplates.PageTemplate import PageTemplate  from Products.PageTemplates.PageTemplate import PageTemplate
 import string  import string
 import urllib  import urllib
   import logging
   
   #ersetzt logging
   def logger(txt,method,txt2):
       """logging"""
       logging.info(txt+ txt2)
   
   
 import xml.dom.minidom  import xml.dom.minidom
 from time import localtime,strftime  from time import localtime,strftime
 from Globals import package_home  from Globals import package_home
   from types import *
   
 import re  import re
 def showHelp(helptext):  def showHelp(helptext):
Line 33  def add(self, no_upload=0): Line 42  def add(self, no_upload=0):
         #self.referencetypes=self.ZopeFind(self,obj_metatypes=['OSAS_MetadataMapping'])          #self.referencetypes=self.ZopeFind(self,obj_metatypes=['OSAS_MetadataMapping'])
     self.referencetypes=self.ZopeFind(self)      self.referencetypes=self.ZopeFind(self)
           
     newtemplate=PageTemplateFile('Products/OSA_system/zpt/OSAS_add_new').__of__(self)          newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_add_new')).__of__(self)
         self.REQUEST.SESSION['path']=self.REQUEST['path']          self.REQUEST.SESSION['path']=self.REQUEST['path']
     if no_upload==0:      if no_upload==0:
         self.REQUEST.SESSION['no_upload']='yes'          self.REQUEST.SESSION['no_upload']='yes'
Line 81  def add2(self): Line 90  def add2(self):
         #sorted=listed.sort()          #sorted=listed.sort()
     #print sorted      #print sorted
           
     newtemplate=PageTemplateFile('Products/OSA_system/zpt/OSAS_add_bibdata').__of__(self)          newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_add_bibdata')).__of__(self)
     return newtemplate()      return newtemplate()
     #return self.fields      #return self.fields
   
Line 116  def add3(self): Line 125  def add3(self):
     metadata=parse_query_string(self.REQUEST['QUERY_STRING'])      metadata=parse_query_string(self.REQUEST['QUERY_STRING'])
     self.REQUEST.SESSION['metadata']=metadata      self.REQUEST.SESSION['metadata']=metadata
     vorschlag=[]      vorschlag=[]
   
     if metadata.has_key('author'):      if metadata.has_key('author'):
         vorschlag.append(metadata['author'][:5])          vorschlag.append(metadata['author'][:5])
     if metadata.has_key('title'):      if metadata.has_key('title'):
Line 132  def add3(self): Line 142  def add3(self):
         self.REQUEST.SESSION['folder_name']=self.REQUEST.SESSION['path']          self.REQUEST.SESSION['folder_name']=self.REQUEST.SESSION['path']
         return add5(self)          return add5(self)
     else:      else:
         newtemplate=PageTemplateFile('Products/OSA_system/zpt/OSAS_add_naming').__of__(self)                  newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_add_naming')).__of__(self)
         return newtemplate()          return newtemplate()
           
   
Line 159  def add4(self): Line 169  def add4(self):
                   
   
         self.image_folder_name="pageimg"          self.image_folder_name="pageimg"
         newtemplate=PageTemplateFile('Products/OSA_system/zpt/OSAS_upload').__of__(self)                  newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_upload')).__of__(self)
                   
         return newtemplate()          return newtemplate()
           
Line 178  def add5(self): Line 188  def add5(self):
     except:      except:
         pass          pass
   
     newtemplate=PageTemplateFile('Products/OSA_system/zpt/OSAS_add_metadata').__of__(self)          newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_add_metadata')).__of__(self)
     return newtemplate()      return newtemplate()
   
 def add6(self):  def add6(self):
Line 196  def add6(self): Line 206  def add6(self):
         if tag!="":          if tag!="":
             self.metadataprint=self.metadataprint+"<"+tag+">"+self.metadata[tag]+"</"+tag+">\n"              self.metadataprint=self.metadataprint+"<"+tag+">"+self.metadata[tag]+"</"+tag+">\n"
   
     newtemplate=PageTemplateFile('Products/OSA_system/zpt/index_meta').__of__(self)          newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','index_meta')).__of__(self)
     newtemplate.content_type="text/plain"      newtemplate.content_type="text/plain"
     renderxml = newtemplate(encode='utf-8')      renderxml = newtemplate(encode='utf-8')
           
                   
     if self.REQUEST.SESSION.has_key('no_upload'):      if self.REQUEST.SESSION.has_key('no_upload'):
         metapath=self.REQUEST.SESSION['path']+"/index.meta"          metapath=self.REQUEST.SESSION['path']+"/index.meta"
     else:      else:
         metapath=self.add_metadata['archive-path']+"/"+self.add_metadata['folder_name']+"/index.meta"          metapath=self.add_metadata['archive-path']+"/"+self.add_metadata['folder_name']+"/index.meta"
           
     f=open(metapath,'w')      f=open(metapath,'w')
           try:
     f.write(renderxml.encode('utf-8'))      f.write(renderxml.encode('utf-8'))
           except:
                   f.write(unicode(renderxml,'latin-1').encode('utf-8'))
                   #f.write(renderxml)
   
     f.close()      f.close()
     os.chmod(metapath,0664)      os.chmod(metapath,0664)
     os.popen('chmod -R 0775 %s'%self.add_metadata['archive-path']+"/"+self.add_metadata['folder_name'])       os.popen('chmod -R 0775 %s'%self.add_metadata['archive-path']+"/"+self.add_metadata['folder_name']) 
Line 221  def add6(self): Line 238  def add6(self):
             """text upload"""              """text upload"""
             return 1              return 1
     else:         else:   
             newtemplate2=PageTemplateFile('Products/OSA_system/zpt/OSAS_saved').__of__(self)                          newtemplate2=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_saved')).__of__(self)
             newtemplate2.content_type="text/html"              newtemplate2.content_type="text/html"
             self.REQUEST.response.setHeader('Content-Type','text/html')              self.REQUEST.response.setHeader('Content-Type','text/html')
             return newtemplate2()              return newtemplate2()
Line 269  def addPresentation(self,path): Line 286  def addPresentation(self,path):
         self.REQUEST.SESSION['presentationname']="%02d-presentation"%i          self.REQUEST.SESSION['presentationname']="%02d-presentation"%i
     self.REQUEST.SESSION['path']=path      self.REQUEST.SESSION['path']=path
   
     tmpTxt="""<?xml version="1.0" encoding="UTF-8"?>          tmpTxt=u"""<?xml version="1.0" encoding="UTF-8"?>
     <info>      <info>
     <author>%s</author>      <author>%s</author>
     <title>%s</title>      <title>%s</title>
Line 279  def addPresentation(self,path): Line 296  def addPresentation(self,path):
           
     self.REQUEST.SESSION['xmlvorschlag']=tmpTxt.encode('utf-8')      self.REQUEST.SESSION['xmlvorschlag']=tmpTxt.encode('utf-8')
           
     newtemplate=PageTemplateFile('Products/OSA_system/zpt/addPresentation').__of__(self)          newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addPresentation')).__of__(self)
     return newtemplate()      return newtemplate()
   
 def addPresentation2(self):  def addPresentation2(self):
Line 306  def addPresentation2(self): Line 323  def addPresentation2(self):
         """nothing"""          """nothing"""
     #print "NAME:",file_name      #print "NAME:",file_name
     f=open(path+"/"+folder_name+"/"+file_name,"w")      f=open(path+"/"+folder_name+"/"+file_name,"w")
     f.write(xmlinfo)          f.write(xmlinfo.encode('utf-8'))
     f.close()      f.close()
     try:      try:
         os.chmod(path+"/"+folder_name,0775)          os.chmod(path+"/"+folder_name,0775)
Line 323  def addPdf(self,path,folder=None): Line 340  def addPdf(self,path,folder=None):
     """add fulltext to the path"""      """add fulltext to the path"""
     self.REQUEST.SESSION['existing_names']=['pageimg'] # to be done generate list of existing text files      self.REQUEST.SESSION['existing_names']=['pageimg'] # to be done generate list of existing text files
     self.REQUEST.SESSION['pathnew']=path      self.REQUEST.SESSION['pathnew']=path
     newtemplate=PageTemplateFile('Products/OSA_system/zpt/addPdf').__of__(self)          newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addPdf')).__of__(self)
     return newtemplate()      return newtemplate()
   
 def addPdf2(self):  def addPdf2(self):
Line 357  def addText(self,path,folder=None): Line 374  def addText(self,path,folder=None):
     """add fulltext to the path"""      """add fulltext to the path"""
     self.REQUEST.SESSION['existing_names']=['pageimg'] # to be done generate list of existing text files      self.REQUEST.SESSION['existing_names']=['pageimg'] # to be done generate list of existing text files
     self.REQUEST.SESSION['pathnew']=path      self.REQUEST.SESSION['pathnew']=path
     newtemplate=PageTemplateFile('Products/OSA_system/zpt/addText').__of__(self)          newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addText')).__of__(self)
     return newtemplate()      return newtemplate()
   
 def addText2(self):  def addText2(self):
Line 379  def addText2(self): Line 396  def addText2(self):
     return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?path='+path)      return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?path='+path)
   
 def addTextExternal(self,path,texturl,version):  def addTextExternal(self,path,texturl,version):
     """hinzufügen eines externen textes"""          """hinzufuegen eines externen textes"""
     try: #neue text version einlesen      try: #neue text version einlesen
         texttemp=urllib.urlopen(texturl).readlines()          texttemp=urllib.urlopen(texturl).readlines()
         text=""          text=""
Line 389  def addTextExternal(self,path,texturl,ve Line 406  def addTextExternal(self,path,texturl,ve
         return "ERROR: cannot read: %s"%texturl          return "ERROR: cannot read: %s"%texturl
     if TextExternalError(text): #kein xml header      if TextExternalError(text): #kein xml header
         return "ERROR: cannot read: %s"%texturl, "received:",text           return "ERROR: cannot read: %s"%texturl, "received:",text 
     textpath=getNewTextPath(path) #erzeuge neuen Ornder für den Text          textpath=getNewTextPath(path) #erzeuge neuen Ornder fuer den Text
     splitted=string.split(texturl,"/")      splitted=string.split(texturl,"/")
     name=splitted[len(splitted)-1] #Name des XML-files      name=splitted[len(splitted)-1] #Name des XML-files
     try:      try:
Line 440  def addTextExternal(self,path,texturl,ve Line 457  def addTextExternal(self,path,texturl,ve
     try:      try:
         texttoolnodelist=subnode.getElementsByTagName('text')          texttoolnodelist=subnode.getElementsByTagName('text')
           
         if not len(texttoolnodelist)==0: #texttool tag existiert schon, dann löschen                  if not len(texttoolnodelist)==0: #texttool tag existiert schon, dann loeschen
             subsubnode=subnode.removeChild(texttoolnodelist[0])              subsubnode=subnode.removeChild(texttoolnodelist[0])
             subsubnode.unlink()              subsubnode.unlink()
     except:      except:
Line 482  def addImages(self,path): Line 499  def addImages(self,path):
     """Imagesfolder to the path"""      """Imagesfolder to the path"""
     self.REQUEST.SESSION['existing_names']=['pageimg'] # to be done generate list of existing pageimages files      self.REQUEST.SESSION['existing_names']=['pageimg'] # to be done generate list of existing pageimages files
     self.REQUEST.SESSION['path']=path      self.REQUEST.SESSION['path']=path
     newtemplate=PageTemplateFile('Products/OSA_system/zpt/OSAS_addImages').__of__(self)          newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_addImages')).__of__(self)
     return newtemplate()      return newtemplate()
   
 def addImages2(self):  def addImages2(self):
Line 496  def addImages2(self): Line 513  def addImages2(self):
     self.content_type='images'      self.content_type='images'
     addDirsToIndexMeta(self.REQUEST.SESSION['path'],self.image_folder_name,self.content_description,self.content_type)      addDirsToIndexMeta(self.REQUEST.SESSION['path'],self.image_folder_name,self.content_description,self.content_type)
     self.REQUEST.SESSION['path']=re.search(r"/mpiwg(.*)",self.REQUEST.SESSION['path']).group(1)      self.REQUEST.SESSION['path']=re.search(r"/mpiwg(.*)",self.REQUEST.SESSION['path']).group(1)
     newtemplate=PageTemplateFile('Products/OSA_system/zpt/OSAS_upload2').__of__(self)          newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','OSAS_upload2')).__of__(self)
     return newtemplate()      return newtemplate()
           
   
Line 554  def readArchimedesXML(folder): Line 571  def readArchimedesXML(folder):
           
   
 def combineTextImage2(self,path):  def combineTextImage2(self,path):
     """erstellt bzw. ändert texttool meta tag"""          """erstellt bzw. aendert texttool meta tag"""
     dom=xml.dom.minidom.parse(path+"/index.meta")      dom=xml.dom.minidom.parse(path+"/index.meta")
     node=dom.getElementsByTagName('meta')[0] #getNode      node=dom.getElementsByTagName('meta')[0] #getNode
   
   
     subnodelist=node.getElementsByTagName('texttool')      subnodelist=node.getElementsByTagName('texttool')
     if not len(subnodelist)==0: #texttool tag existiert schon, dann löschen          if not len(subnodelist)==0: #texttool tag existiert schon, dann loeschen
         subnode=node.removeChild(subnodelist[0])          subnode=node.removeChild(subnodelist[0])
         subnode.unlink()          subnode.unlink()
   
     subnode=dom.createElement('texttool') #neu erzeugen      subnode=dom.createElement('texttool') #neu erzeugen
   
           
     presentfile=os.listdir(path+"/"+self.REQUEST['presentation'])[0]          presentfiles=os.listdir(path+"/"+self.REQUEST['presentation'])
           for presentfileTmp in presentfiles:
               if (presentfileTmp[0]!="."): #schliesse unsichbare DAteien aus.
                   presentfile=presentfileTmp
           
   
     displaynode=dom.createElement('display')      displaynode=dom.createElement('display')
Line 690  def combineTextImage2(self,path): Line 710  def combineTextImage2(self,path):
           
           
   
     urllib.urlopen("http://nausikaa2.rz-berlin.mpg.de:86/cgi-bin/toc/admin/reg.cgi?path=%s"%path).readlines()  #        urllib.urlopen("http://nausikaa2.rz-berlin.mpg.de:86/cgi-bin/toc/admin/reg.cgi?path=%s"%path).readlines()
   #
   #        if self.REQUEST.has_key('image'): # falls bilder
   #                path=re.sub('//','/',self.REQUEST['path']) # falls '//' im Pfad
   #                dlpath = re.sub('/mpiwg/online/','',path)+"/"+self.REQUEST['image']
   #
   #                logger('OSas',logging.INFO,"ssh archive@nausikaa2.rz-berlin.mpg.de /usr/local/mpiwg/scripts/scaleomat -src=/mpiwg/online -dest=/mpiwg/temp/online/scaled/thumb -dir=%s -scaleto=90 -sync >> /tmp/sc.out &"%dlpath )
   #                ret=os.popen("ssh archive@nausikaa2.rz-berlin.mpg.de /usr/local/mpiwg/scripts/scaleomat -src=/mpiwg/online -dest=/mpiwg/temp/online/scaled/thumb -dir=%s -scaleto=90 -sync >> /tmp/sc.out &"%dlpath ).read()
   #                logger('OSAS (combine)',logging.INFO,ret)
   
     if self.REQUEST.has_key('image'): # falls bilder  
         path=re.sub('//','/',self.REQUEST['path']) # falls '//' im Pfad  
         dlpath = re.sub('/mpiwg/online/','',path)+"/"+self.REQUEST['image']          #else: # falls keine Bilder (bug in reg.cgi info file ersetzen)
         os.popen("ssh archive@nausikaa2.rz-berlin.mpg.de /usr/local/mpiwg/scripts/scaleomat -src=/mpiwg/online -dest=/mpiwg/temp/online/scaled/thumb -dir=%s -scaleto=90 -sync >> /tmp/sc.out &"%dlpath )          #        f=file("/tmp/tmp_info.xml","w")
             #os.popen("ssh archive@nausikaa2.rz-berlin.mpg.de /usr/local/mpiwg/scripts/scaleomat.pl %s /mpiwg/temp/online/scaled/thumb 90 >> /tmp/sc.out &"% re.sub('/mpiwg/online/','',self.REQUEST['path']+"/"+self.REQUEST['image']))          #        tmp=patchedInfoXML(self.REQUEST['path'])
           #        f.write(tmp.encode('utf-8'))
     else: # falls keine Bilder (bug in reg.cgi info file ersetzen)          #        f.close()
         f=file("/tmp/tmp_info.xml","w")          #        splitted=path.split("/")
         tmp=patchedInfoXML(self.REQUEST['path'])          #        fn=splitted[len(splitted)-1]
         f.write(tmp.encode('utf-8'))          #        remotePath="archive@nausikaa2.rz-berlin.mpg.de:/usr/local/share/archimedes/web/docs/proj/echo/1/docs/"+fn+"/info.xml"
         f.close()          #        os.popen("scp /tmp/tmp_info.xml %s"%remotePath)
         splitted=path.split("/")  
         fn=splitted[len(splitted)-1]  
         remotePath="archive@nausikaa2.rz-berlin.mpg.de:/usr/local/share/archimedes/web/docs/proj/echo/1/docs/"+fn+"/info.xml"  
         os.popen("scp /tmp/tmp_info.xml %s"%remotePath)  
   
 def patchedInfoXML(path):  def patchedInfoXML(path):
     dom=xml.dom.minidom.parse(path+"/index.meta")      dom=xml.dom.minidom.parse(path+"/index.meta")

Removed from v.1.40  
changed lines
  Added in v.1.53


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>