Diff for /ImageArchive/ImageArchive.py between versions 1.100 and 1.107

version 1.100, 2006/12/08 13:54:21 version 1.107, 2009/01/06 16:13:51
Line 1 Line 1
   """version 1 des Imageservers, wird ersetzt durch version2"""
   
 genericServerPath="http://www.mpiwg-berlin.mpg.de/zogilib_images" #can be changed with main config  genericServerPath="http://www.mpiwg-berlin.mpg.de/zogilib_images" #can be changed with main config
   
   
Line 24  from threading import Thread Line 26  from threading import Thread
 import Queue  import Queue
 import cgi  import cgi
 import sys  import sys
 import zLOG  
 import shutil  import shutil
   
   import logging
   
   #ersetzt logging
   def logger(txt,method,txt2):
       """logging"""
       logging.info(txt+ txt2)
   
   def logTime(msg=""):
       """log the time"""
       logging.info("%s %s"%(msg,time.clock()))
       
   
 from AccessControl import ClassSecurityInfo, getSecurityManager  from AccessControl import ClassSecurityInfo, getSecurityManager
   
 try:  try:
Line 294  class ImageDigilib(Folder,Persistent,Imp Line 308  class ImageDigilib(Folder,Persistent,Imp
     manage_options = Folder.manage_options+(      manage_options = Folder.manage_options+(
                   
         {'label':'Add Metadata','action':'addMetaObjectForm'},          {'label':'Add Metadata','action':'addMetaObjectForm'},
                   {'label':'View Info','action':'editImageDigilib'},
         )          )
   
       def editImageDigilib(self):
           """edit image date"""
           pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','editImageDigilib.zpt')).__of__(self)
           return pt()        
   
   
                   
     def getAccessRight(self):      def getAccessRight(self):
Line 307  class ImageDigilib(Folder,Persistent,Imp Line 326  class ImageDigilib(Folder,Persistent,Imp
           
     def isAccessible(self):      def isAccessible(self):
         """gives true if obejct is accessible taking the rights of the user into account"""          """gives true if obejct is accessible taking the rights of the user into account"""
                   logTime("isaccessible")
         #TODO: implement rights, currently  true if external and false if internal, and true if user has role authenticated          #TODO: implement rights, currently  true if external and false if internal, and true if user has role authenticated
           
         username=self.REQUEST['AUTHENTICATED_USER']          username=self.REQUEST['AUTHENTICATED_USER']
Line 391  class ImageDigilib(Folder,Persistent,Imp Line 410  class ImageDigilib(Folder,Persistent,Imp
         """upload an Image from an Requast"""          """upload an Image from an Requast"""
         #path_name=self.ImageStoragePath          #path_name=self.ImageStoragePath
         fn = self.filename or splitPath(fileupload.filename)          fn = self.filename or splitPath(fileupload.filename)
           fn = os.path.splitext(fn)[0]+os.path.splitext(fileupload.filename)[1] # Extensions des gespeicherten Files sollte gleich dem hochgeladenen File sein.
         filename=path_name+"/"+fn          filename=path_name+"/"+fn
         filedata=fileupload.read()          filedata=fileupload.read()
         f=open(filename,"w")          f=open(filename,"w")
         f.write(filedata)          f.write(filedata)
         f.close()          f.close()
         self.filename = fn          self.filename = fn
           
         try:          try:
             os.chmod(filename,0664)              os.chmod(filename,0664)
         except:          except:
Line 515  class ImageDigilib(Folder,Persistent,Imp Line 536  class ImageDigilib(Folder,Persistent,Imp
             os.mkdir(path,0775)              os.mkdir(path,0775)
             os.chmod(path,0775)              os.chmod(path,0775)
                           
         newName=os.path.join(path,self.getId())          newName=os.path.join(path,self.getId()+str(time.time()))
   
         if os.path.exists(newName):          if os.path.exists(newName):
             zLOG.LOG("ImageArchive:scaleToJpg", zLOG.INFO, "%s already exists"%newName)              logger("ImageArchive:scaleToJpg", logging.INFO, "%s already exists"%newName)
         else:          else:
             try:              try:
                 os.rename(imagePath,newName)                  os.rename(imagePath,newName)
             except:              except:
                 zLOG.LOG("ImageArchive:scaleToJpg", zLOG.ERROR, "%s "%newName)                  logger("ImageArchive:scaleToJpg", logging.ERROR, "%s "%newName)
                 return False                  return False
                           
         ext= os.path.splitext(imagePath)[1].lower()          ext= os.path.splitext(imagePath)[1].lower()
Line 544  class ImageDigilib(Folder,Persistent,Imp Line 565  class ImageDigilib(Folder,Persistent,Imp
         #teste ob Dokumenten ordner schon vorhanden          #teste ob Dokumenten ordner schon vorhanden
         #imagePath=os.path.join(self.getImageStoragePath(),self.getId())          #imagePath=os.path.join(self.getImageStoragePath(),self.getId())
                   
           logging.error("updateImage:"+self.filename)
         identifyField="filename"          identifyField="filename"
                   
         if _fileupload and _fileupload.filename!="":          if _fileupload and _fileupload.filename!="":
             imagePath=os.path.join(self.getImageStoragePath(),self.filename)              imagePath=os.path.join(self.getImageStoragePath(),self.filename)
               idWithoutSuffix= os.path.splitext(self.getId())[0]
             path=os.path.join(self.getImageStoragePath(),"."+self.getId()+".dir")              path=os.path.join(self.getImageStoragePath(),"."+self.getId()+".dir")
                                   
             if not os.path.exists(path):              if not os.path.exists(path):
Line 564  class ImageDigilib(Folder,Persistent,Imp Line 587  class ImageDigilib(Folder,Persistent,Imp
             #kopieren der bestehenden Version in den Versions ordner.              #kopieren der bestehenden Version in den Versions ordner.
             imageNewPath=os.path.join(path,"V%i_%s"%(versionNumber,self.filename))              imageNewPath=os.path.join(path,"V%i_%s"%(versionNumber,self.filename))
             try:                  try:    
                     #zLOG.LOG("ImageArchive:updateImage", zLOG.INFO, "rename: %s -> %s"%(imagePath,imageNewPath))                      #logger("ImageArchive:updateImage", logging.INFO, "rename: %s -> %s"%(imagePath,imageNewPath))
                     os.rename(imagePath,imageNewPath)                      os.rename(imagePath,imageNewPath)
             except:              except:
                 zLOG.LOG("ImageArchive:updateImage", zLOG.ERROR, "rename: %s -> %s didn't work!"%(imagePath,imageNewPath))                        logger("ImageArchive:updateImage ", logging.ERROR, "rename: %s -> %s didn't work!"%(imagePath,imageNewPath))      
           
             #lesen des upload files und schreiben              #lesen des upload files und schreiben
             filedata=_fileupload.read()              filedata=_fileupload.read()
             f=open(imagePath,"w") # if we wanted to have filename=id we should do it here!              
               #passe suffix an
               oldNameBase=os.path.splitext(imagePath)[0]
               uploadFileExt=os.path.splitext(_fileupload.filename)[1]
               
               newImagePath=oldNameBase+uploadFileExt
               
               f=open(newImagePath,"w") # if we wanted to have filename=id we should do it here!
               logging.error("saving:"+newImagePath)
             f.write(filedata)              f.write(filedata)
             f.close()              f.close()
             try:              try:
                 os.chmod(imagePath,0664)                  os.chmod(newImagePath,0664)
             except:              except:
                 pass                  pass
             #scale thumb              #scale thumb
Line 585  class ImageDigilib(Folder,Persistent,Imp Line 616  class ImageDigilib(Folder,Persistent,Imp
             #scale standard              #scale standard
           
             self.scaleWorkingVersions()              self.scaleWorkingVersions()
             self.scaleToJpg()              #self.scaleToJpg()
             if _rename:              if _rename:
                 self.renameImage(_fileupload.filename)                  self.renameImage(_fileupload.filename)
                   
               else: 
                   self.filename=os.path.splitext(self.filename)[0]+uploadFileExt # Aendere zumindest die Extensiion
             
           try: #todo: sollte nur aufgerufen werden, wenn eine Datenbank dahinter liegt.
         args=self.REQUEST.form          args=self.REQUEST.form
                 
         args['-identify']=identifyField+"="+args['_identifyField']          args['-identify']=identifyField+"="+args['_identifyField']
                     
         self.ZSQLChange(args=args)          self.ZSQLChange(args=args)
                     
           except:
               pass
           
         if RESPONSE:          if RESPONSE:
             RESPONSE.redirect(self.aq_parent.absolute_url()+"?filename="+self.filename)              RESPONSE.redirect(self.aq_parent.absolute_url()+"?filename="+self.filename)
                   
Line 628  class ImageDigilib(Folder,Persistent,Imp Line 665  class ImageDigilib(Folder,Persistent,Imp
                   
   
           
         self.REQUEST.SESSION['string']="<img border=\"0\" src=\"%s\">"% path          imageString="<img border=\"0\" src=\"%s\">"% path
           self.REQUEST.SESSION['string']=imageString
         if url:          if url:
             return "<img border=\"0\" src=\"%s\">"% path              return "<img border=\"0\" src=\"%s\">"% path
         else:          else:
Line 638  class ImageDigilib(Folder,Persistent,Imp Line 676  class ImageDigilib(Folder,Persistent,Imp
                 return getattr(self,overview[0][0])()                  return getattr(self,overview[0][0])()
             else:              else:
                 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','thumbMD.zpt')).__of__(self)                  pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','thumbMD.zpt')).__of__(self)
                 return pt()                  return pt(imageString=imageString)
   
   
     def image(self,dw=None,dh=None):      def image(self,dw=None,dh=None):
Line 757  class ImageCollection(OrderedFolder, Per Line 795  class ImageCollection(OrderedFolder, Per
             fileStr=" -dir=%s"%fileTmp              fileStr=" -dir=%s"%fileTmp
             scaleStr=scaleStr+fileStr              scaleStr=scaleStr+fileStr
         else:          else:
             zLOG.LOG("ImageCollection:scale",zLOG.ERROR,"no directory or filename given")              logger("ImageCollection:scale",logging.ERROR,"no directory or filename given")
             return False              return False
                   
         if dest is not None:          if dest is not None:
             destStr=" -dest=%s"%os.path.join(destBasis,dest)              destStr=" -dest=%s"%os.path.join(destBasis,dest)
             scaleStr=scaleStr+destStr              scaleStr=scaleStr+destStr
         else:          else:
             zLOG.LOG("ImageCollection:scale",zLOG.ERROR,"no destionation given")              logger("ImageCollection:scale",logging.ERROR,"no destionation given")
             return False              return False
                   
         if scaleTo:          if scaleTo:
Line 774  class ImageCollection(OrderedFolder, Per Line 812  class ImageCollection(OrderedFolder, Per
             scaleByStr=" -scaleby=%s"%scaleBy              scaleByStr=" -scaleby=%s"%scaleBy
             scaleStr=scaleStr+scaleByStr              scaleStr=scaleStr+scaleByStr
         else:          else:
             zLOG.LOG("ImageCollection:scale",zLOG.ERROR,"no destionation given")              logger("ImageCollection:scale",logging.ERROR,"no destionation given")
             return False              return False
             
                 
         #ret=scaleStr          #ret=scaleStr
     #zLOG.LOG("ImageCollection:scale",zLOG.INFO,scaleStr)          logger("ImageCollection:scale",logging.INFO,scaleStr)
         ret=os.popen2(scaleStr,1)[1].read()          ret=os.popen2(scaleStr,1)[1].read()
     
         if RESPONSE:          if RESPONSE:
Line 1677  class ImageCollection(OrderedFolder, Per Line 1715  class ImageCollection(OrderedFolder, Per
         if showall=='yes':          if showall=='yes':
             rows=int(idsnumber/cols)+1              rows=int(idsnumber/cols)+1
                           
           logTime("getColTimesRow finished")
         return (cols,rows)          return (cols,rows)
                                   
                   
Line 1720  class ImageCollection(OrderedFolder, Per Line 1759  class ImageCollection(OrderedFolder, Per
         self.REQUEST.SESSION['ids']=ids          self.REQUEST.SESSION['ids']=ids
         number=int(len(ids)/numberOfColumns)+1          number=int(len(ids)/numberOfColumns)+1
           
           logTime("show_thumbs_rows finished (%s)"%str(number))
         return range(number+1)          return range(number+1)
   
     def show_thumbs_columns(self,row,numberOfColumns):      def show_thumbs_columns(self,row,numberOfColumns):
         """Ausgabe einer Liste der Reihe"""          """Ausgabe einer Liste der Reihe"""
         ids=self.REQUEST.SESSION['ids']          ids=self.REQUEST.SESSION['ids']
         max=len(ids)          max=len(ids)
           logTime("show_thumb_columns finishes row: %s"%row)
         if (row*numberOfColumns)<max:          if (row*numberOfColumns)<max:
             return ids[(row-1)*numberOfColumns:row*numberOfColumns]              return ids[(row-1)*numberOfColumns:row*numberOfColumns]
         else:          else:
Line 1924  class ImageCollectionMD(ImageCollection, Line 1965  class ImageCollectionMD(ImageCollection,
                     ret=ret+"<br>"+file+" already exists!"                      ret=ret+"<br>"+file+" already exists!"
   
                 else:                  else:
                     zLOG.LOG("ImageArchiveMD:import", zLOG.INFO, "adding ZOPE: %s"%file)                      logger("ImageArchiveMD:import", logging.INFO, "adding ZOPE: %s"%file)
                     ret=ret+"<br>"+file+" created!"                      ret=ret+"<br>"+file+" created!"
                     newObj=ImageDigilib(file,file)                      newObj=ImageDigilib(file,file)
                     #print newObj,file                      #print newObj,file
Line 1940  class ImageCollectionMD(ImageCollection, Line 1981  class ImageCollectionMD(ImageCollection,
                 args[self.imageCollectionConfig.getKey()]=file                  args[self.imageCollectionConfig.getKey()]=file
   
                 if not self.ZSQLInline(args=args):                  if not self.ZSQLInline(args=args):
                     zLOG.LOG("ImageArchiveMD:import", zLOG.INFO, "adding DB: %s"%file)                      logger("ImageArchiveMD:import", logging.INFO, "adding DB: %s"%file)
                     self.ZSQLAdd(args=args)                      self.ZSQLAdd(args=args)
     
         #print ret          #print ret
Line 2040  class ImageCollectionMD(ImageCollection, Line 2081  class ImageCollectionMD(ImageCollection,
                   
         rc=[]          rc=[]
         fnIds={}          fnIds={}
   
         for found in self.ZSQLInlineSearch(args=self.REQUEST.form):          for found in self.ZSQLInlineSearch(args=self.REQUEST.form):
             key=getattr(found,self.imageCollectionConfig.getKey())              key=getattr(found,self.imageCollectionConfig.getKey())
             key=self.getImageByName(key,onlyName="yes")                      key=self.getImageByName(key,onlyName="yes")        
Line 2073  class ImageCollectionMD(ImageCollection, Line 2115  class ImageCollectionMD(ImageCollection,
     def index_html(self,fn=None,selection=None,generic='No',REQUEST=None,RESPONSE=None):      def index_html(self,fn=None,selection=None,generic='No',REQUEST=None,RESPONSE=None):
         """main template collection"""          """main template collection"""
   
                   logTime("index_html %s"%self.REQUEST['QUERY_STRING'])
         mode=self.REQUEST.get('mode','view')          mode=self.REQUEST.get('mode','view')
         if fn:          if fn:
             ret=[]              ret=[]
Line 2224  class ImageCollectionMD(ImageCollection, Line 2266  class ImageCollectionMD(ImageCollection,
   
     def thumblistMD(self):      def thumblistMD(self):
         """main template collection"""          """main template collection"""
           logTime("thumbList MD %s"%self.REQUEST['QUERY_STRING'])
           
         pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','thumbListMD.zpt')).__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','thumbListMD.zpt')).__of__(self)
           self.REQUEST.RESPONSE.setHeader('Cache-Control','max-age=3600')
           self.REQUEST.RESPONSE.setHeader('Last-Modified',self.bobobase_modification_time().toZone('GMT').rfc822())
         return pt()          return pt()
           
       
     def getRights(self,id):      def getRights(self,id):
         """get the rights from a database"""          """get the rights from a database"""
         #print self.rightsQuery%id          #print self.rightsQuery%id
         results=self.ZSQLSimpleSearch(self.getRightsQuery()%id)          results=self.ZSQLSimpleSearch(self.getRightsQuery()%id)
           logging.error("rightsQuery: %s"%(self.getRightsQuery()%id))
         if results:          if results:
             result = getattr(results[0],self.getRightsQueryField())              result = getattr(results[0],self.getRightsQueryField())
         else:          else:

Removed from v.1.100  
changed lines
  Added in v.1.107


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