Diff for /OSAS/OSA_system/OSAS_add.py between versions 1.26 and 1.50

version 1.26, 2004/04/15 21:30:42 version 1.50, 2007/01/31 14:28:04
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 52  def getISO(): Line 61  def getISO():
   
         ret={}          ret={}
         for lineraw in f:          for lineraw in f:
             line=lineraw.encode('ascii','replace')                          line=lineraw.encode('ascii','replace').strip()
             value=string.split(line,'\t')[0].encode('ascii','replace')              value=string.split(line,'\t')[0].encode('ascii','replace')
             key=string.split(line,'\t')[1].encode('ascii','replace')              key=string.split(line,'\t')[1].encode('ascii','replace')
             ret[key]=value              ret[key]=value
Line 67  def add2(self): Line 76  def add2(self):
     self.bibdata={}      self.bibdata={}
     for referenceType in self.referencetypes:      for referenceType in self.referencetypes:
         #print referenceType          #print referenceType
                   if referenceType[1].title == self.reftype: 
         self.bibdata[referenceType[1].title]=referenceType[1].fields          self.bibdata[referenceType[1].title]=referenceType[1].fields
         self.bibdata['data']=referenceType[1]          self.bibdata['data']=referenceType[1]
     self.fields=self.bibdata[self.reftype]      self.fields=self.bibdata[self.reftype]
Line 80  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 115  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 131  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()
           
   
 def add4(self):  def add4(self):
   
     self.path=re.search(r"/mpiwg(.*)",self.REQUEST.SESSION['path']).group(1)      self.path=re.search(r"/mpiwg(.*)",self.REQUEST.SESSION['path']).group(1)
           
     self.folder_name=self.REQUEST['folder_name']      self.folder_name=self.REQUEST['folder_name']
     # next has to be changed -> error if back button is used!!      # next has to be changed -> error if back button is used!!
     self.REQUEST.SESSION['folder_name']=self.folder_name      self.REQUEST.SESSION['folder_name']=self.folder_name
           #return self.REQUEST['submit']
   
           try:    
                   #os.popen('mkdir '+self.REQUEST.SESSION['path'])
                   os.mkdir(os.path.join(self.REQUEST.SESSION['path'],self.REQUEST['folder_name']))
                   os.chmod(os.path.join(self.REQUEST.SESSION['path'],self.REQUEST['folder_name']),0775)
   
           except:
   
                   """nothing"""
   
     if self.REQUEST['submit']=="upload images":      if self.REQUEST['submit']=="upload images":
         self.REQUEST.SESSION['path']=os.path.join(self.REQUEST.SESSION['path'],self.REQUEST['folder_name'])          self.REQUEST.SESSION['path']=os.path.join(self.REQUEST.SESSION['path'],self.REQUEST['folder_name'])
                   
   
         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()
           
           elif self.REQUEST['submit']=="upload pdf":
                   os.mkdir(os.path.join(self.REQUEST.SESSION['path'],self.REQUEST['folder_name']))
                   return addPdf(self,os.path.join(self.REQUEST.SESSION['path'],self.REQUEST['folder_name']))
     else:      else:
         os.mkdir(os.path.join(self.REQUEST.SESSION['path'],self.REQUEST['folder_name']))          os.mkdir(os.path.join(self.REQUEST.SESSION['path'],self.REQUEST['folder_name']))
         return addText(self,os.path.join(self.REQUEST.SESSION['path'],self.REQUEST['folder_name']))          return addText(self,os.path.join(self.REQUEST.SESSION['path'],self.REQUEST['folder_name']))
Line 153  def add4(self): Line 183  def add4(self):
           
 def add5(self):  def add5(self):
     """ADD INDEX.META"""      """ADD INDEX.META"""
     newtemplate=PageTemplateFile('Products/OSA_system/zpt/OSAS_add_metadata').__of__(self)          try:
                   os.chmod(self.REQUEST.SESSION['path'],0775)
           except:
                   pass
   
           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 171  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()          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')
     f.writelines(renderxml)          try:
                   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 191  def add6(self): Line 233  def add6(self):
     else:      else:
                 #print self.add_metadata['archive-path']                  #print self.add_metadata['archive-path']
         self.viewpath=re.search(r"/mpiwg/online/(.*)",self.add_metadata['archive-path']).group(1)          self.viewpath=re.search(r"/mpiwg/online/(.*)",self.add_metadata['archive-path']).group(1)
         if not (self.REQUEST.SESSION['no_upload']=="text"):          
             newtemplate2=PageTemplateFile('Products/OSA_system/zpt/OSAS_saved').__of__(self)          if (self.REQUEST.SESSION.has_key('no_upload')) and (self.REQUEST.SESSION['no_upload']=="text"):
                           """text upload"""
                           return 1
           else:   
                           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()
         else:  
             """text upload"""  
             return 1  
   
   
   
Line 238  def addPresentation(self,path): Line 281  def addPresentation(self,path):
             except:              except:
                 date=""                  date=""
     i=1      i=1
     while os.path.exists("%02d-presentation"%i):          while os.path.exists(path+"/%02d-presentation"%i):
         i+=1          i+=1
         self.REQUEST.SESSION['presentationname']="%02d-presentation"%i          self.REQUEST.SESSION['presentationname']="%02d-presentation"%i
     self.REQUEST.SESSION['path']=path      self.REQUEST.SESSION['path']=path
     self.REQUEST.SESSION['xmlvorschlag']="""<info>  
           tmpTxt="""<?xml version="1.0" encoding="UTF-8"?>
           <info>
     <author>%s</author>      <author>%s</author>
     <title>%s</title>      <title>%s</title>
     <date>%s</date>      <date>%s</date>
     <display>yes</display>      <display>yes</display>
 </info>"""%(author,title,date)  </info>"""%(author,title,date)
           
     newtemplate=PageTemplateFile('Products/OSA_system/zpt/addPresentation').__of__(self)          self.REQUEST.SESSION['xmlvorschlag']=tmpTxt.encode('utf-8')
           
           newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addPresentation')).__of__(self)
     return newtemplate()      return newtemplate()
   
 def addPresentation2(self):  def addPresentation2(self):
Line 279  def addPresentation2(self): Line 326  def addPresentation2(self):
     f.write(xmlinfo)      f.write(xmlinfo)
     f.close()      f.close()
     try:      try:
         os.chmod(path+"/"+folder_name,0755)                  os.chmod(path+"/"+folder_name,0775)
     except:      except:
         """NO"""          """NO"""
   
     os.chmod(path+"/"+folder_name+"/"+file_name,0644)          os.chmod(path+"/"+folder_name+"/"+file_name,0664)
     addDirsToIndexMeta(path,folder_name,content_description,'presentation')      addDirsToIndexMeta(path,folder_name,content_description,'presentation')
           
     return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?path='+path)      return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?path='+path)
   
   
   def addPdf(self,path,folder=None):
           """add fulltext to the path"""
           self.REQUEST.SESSION['existing_names']=['pageimg'] # to be done generate list of existing text files
           self.REQUEST.SESSION['pathnew']=path
           newtemplate=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addPdf')).__of__(self)
           return newtemplate()
   
   def addPdf2(self):
           """addtext"""
           folder_name="pdf" # foldername fixed
           
           if self.REQUEST['file_name']=="":
                   file_name=self.REQUEST['fileupload'].filename
           else:
                   file_name=self.REQUEST['file_name']
                   
           #print self.REQUEST['folder_name']
           content_description=self.REQUEST['content_description']
           path=self.REQUEST.SESSION['pathnew']
   
           filedata=self.REQUEST.form['fileupload'].read()
           try:
                   os.mkdir(path+"/"+folder_name)
           except:
                   """nothing"""
           f=open(path+"/"+folder_name+"/"+file_name,"w")
           f.write(filedata)
           f.close()
           os.chmod(path+"/"+folder_name,0755)
           os.chmod(path+"/"+folder_name+"/"+file_name,0644)
           addDirsToIndexMeta(path,folder_name,content_description,'pdf')
   
           return self.REQUEST.RESPONSE.redirect(self.REQUEST['URL2']+'?path='+path)
   
 def addText(self,path,folder=None):  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['path']=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 300  def addText2(self): Line 382  def addText2(self):
     folder_name=self.REQUEST['folder_name']      folder_name=self.REQUEST['folder_name']
     #print self.REQUEST['folder_name']      #print self.REQUEST['folder_name']
     content_description=self.REQUEST['content_description']      content_description=self.REQUEST['content_description']
     path=self.REQUEST.SESSION['path']          path=self.REQUEST.SESSION['pathnew']
     file_name=self.REQUEST['fileupload'].filename      file_name=self.REQUEST['fileupload'].filename
     filedata=self.REQUEST.form['fileupload'].read()      filedata=self.REQUEST.form['fileupload'].read()
     os.mkdir(path+"/"+folder_name)      os.mkdir(path+"/"+folder_name)
Line 359  def addTextExternal(self,path,texturl,ve Line 441  def addTextExternal(self,path,texturl,ve
     node.appendChild(subnode)      node.appendChild(subnode)
   
     writefile=file(path+"/index.meta","w")      writefile=file(path+"/index.meta","w")
     writefile.write(dom.toxml().encode('utf-8'))          writefile.write(dom.toxml(encoding="UTF-8"))
     writefile.close()      writefile.close()
   
     #change texttool tag      #change texttool tag
Line 388  def addTextExternal(self,path,texturl,ve Line 470  def addTextExternal(self,path,texturl,ve
   
     #index.meta ausgeben      #index.meta ausgeben
     writefile=file(path+"/index.meta","w")      writefile=file(path+"/index.meta","w")
     writefile.write(dom.toxml().encode('utf-8'))          writefile.write(dom.toxml(encoding="UTF-8"))
     writefile.close()      writefile.close()
           
     #registrieren      #registrieren
Line 417  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 431  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 461  def addDirsToIndexMeta(path,folder_name, Line 543  def addDirsToIndexMeta(path,folder_name,
     node.appendChild(subnode)      node.appendChild(subnode)
   
     writefile=file(path+"/index.meta","w")      writefile=file(path+"/index.meta","w")
     writefile.write(dom.toxml().encode('utf-8'))          writefile.write(dom.toxml(encoding='UTF-8'))
     writefile.close()      writefile.close()
   
 def readArchimedesXML(folder):  def readArchimedesXML(folder):
Line 578  def combineTextImage2(self,path): Line 660  def combineTextImage2(self,path):
             xsltnode.appendChild(xsltnodetext)              xsltnode.appendChild(xsltnodetext)
             subnode.appendChild(xsltnode)              subnode.appendChild(xsltnode)
                           
           if self.REQUEST.has_key('digiliburlprefix'):
                   if not self.REQUEST['digiliburlprefix']=="":
                           xsltnode=dom.createElement('digiliburlprefix')
                           xsltnodetext=dom.createTextNode(self.REQUEST['digiliburlprefix'])
                           xsltnode.appendChild(xsltnodetext)
                           subnode.appendChild(xsltnode)
                           
     node.appendChild(subnode)      node.appendChild(subnode)
           
     try:      try:
Line 613  def combineTextImage2(self,path): Line 702  def combineTextImage2(self,path):
             """nothing"""              """nothing"""
                           
     writefile=file(path+"/index.meta","w")      writefile=file(path+"/index.meta","w")
     writefile.write(dom.toxml().encode('utf-8'))          writefile.write(dom.toxml(encoding="UTF-8"))
     writefile.close()      writefile.close()
           
           
Line 621  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      if self.REQUEST.has_key('image'): # falls bilder
         os.popen("ssh 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']))                  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)                  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 )
         f=file("/tmp/tmp_info.xml","w")                  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()
         f.write(patchedInfoXML(self.REQUEST['path']))                  logger('OSAS (combine)',logging.INFO,ret)
         f.close()  
         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"          #else: # falls keine Bilder (bug in reg.cgi info file ersetzen)
         os.popen("scp /tmp/tmp_info.xml %s"%remotePath)          #        f=file("/tmp/tmp_info.xml","w")
           #        tmp=patchedInfoXML(self.REQUEST['path'])
           #        f.write(tmp.encode('utf-8'))
           #        f.close()
           #        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.26  
changed lines
  Added in v.1.50


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