--- ImageArchive/ImageArchive.py 2007/01/31 14:24:17 1.103 +++ ImageArchive/ImageArchive.py 2010/06/15 14:08:12 1.108 @@ -1,3 +1,5 @@ +"""version 1 des Imageservers, wird ersetzt durch version2""" + genericServerPath="http://www.mpiwg-berlin.mpg.de/zogilib_images" #can be changed with main config @@ -34,7 +36,10 @@ 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 @@ -303,9 +308,14 @@ class ImageDigilib(Folder,Persistent,Imp manage_options = Folder.manage_options+( {'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): @@ -316,7 +326,7 @@ class ImageDigilib(Folder,Persistent,Imp def isAccessible(self): """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 username=self.REQUEST['AUTHENTICATED_USER'] @@ -400,12 +410,14 @@ class ImageDigilib(Folder,Persistent,Imp """upload an Image from an Requast""" #path_name=self.ImageStoragePath 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 filedata=fileupload.read() f=open(filename,"w") f.write(filedata) f.close() self.filename = fn + try: os.chmod(filename,0664) except: @@ -524,7 +536,7 @@ class ImageDigilib(Folder,Persistent,Imp os.mkdir(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): logger("ImageArchive:scaleToJpg", logging.INFO, "%s already exists"%newName) @@ -553,10 +565,12 @@ class ImageDigilib(Folder,Persistent,Imp #teste ob Dokumenten ordner schon vorhanden #imagePath=os.path.join(self.getImageStoragePath(),self.getId()) + logging.error("updateImage:"+self.filename) identifyField="filename" if _fileupload and _fileupload.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") if not os.path.exists(path): @@ -576,15 +590,23 @@ class ImageDigilib(Folder,Persistent,Imp #logger("ImageArchive:updateImage", logging.INFO, "rename: %s -> %s"%(imagePath,imageNewPath)) os.rename(imagePath,imageNewPath) except: - logger("ImageArchive:updateImage", logging.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 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.close() try: - os.chmod(imagePath,0664) + os.chmod(newImagePath,0664) except: pass #scale thumb @@ -594,17 +616,23 @@ class ImageDigilib(Folder,Persistent,Imp #scale standard self.scaleWorkingVersions() - self.scaleToJpg() + #self.scaleToJpg() if _rename: self.renameImage(_fileupload.filename) + else: + self.filename=os.path.splitext(self.filename)[0]+uploadFileExt # Aendere zumindest die Extensiion - args=self.REQUEST.form + try: #todo: sollte nur aufgerufen werden, wenn eine Datenbank dahinter liegt. + 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: RESPONSE.redirect(self.aq_parent.absolute_url()+"?filename="+self.filename) @@ -637,7 +665,8 @@ class ImageDigilib(Folder,Persistent,Imp - self.REQUEST.SESSION['string']=""% path + imageString=""% path + self.REQUEST.SESSION['string']=imageString if url: return ""% path else: @@ -647,7 +676,7 @@ class ImageDigilib(Folder,Persistent,Imp return getattr(self,overview[0][0])() else: 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): @@ -788,7 +817,7 @@ class ImageCollection(OrderedFolder, Per #ret=scaleStr - #logger("ImageCollection:scale",logging.INFO,scaleStr) + logger("ImageCollection:scale",logging.INFO,scaleStr) ret=os.popen2(scaleStr,1)[1].read() if RESPONSE: @@ -1263,8 +1292,8 @@ class ImageCollection(OrderedFolder, Per if os.path.isdir(os.path.join(self.getImageStoragePath(),file)): ImageStoragePath=os.path.join(self.getImageStoragePath(),file) imageViewerPath=os.path.join(self.ImageViewerPath,file) - manage_AddImageCollection(self,file,file,self.getImageStoragePath(),imageViewerPath,self.defaultMetaString) - + #manage_AddImageCollection(self,file,file,self.getImageStoragePath(),imageViewerPath,self.defaultMetaString) + manage_AddImageCollection(self,file,file,imageViewerPath,self.defaultMetaString,self.destBasis,self.srcBasis,self.serverPath) obj=getattr(self,file) obj.ImportStructure() else: @@ -1685,7 +1714,8 @@ class ImageCollection(OrderedFolder, Per showall=self.REQUEST.SESSION.get('showall', 'No') if showall=='yes': rows=int(idsnumber/cols)+1 - + + logTime("getColTimesRow finished") return (cols,rows) @@ -1728,13 +1758,15 @@ class ImageCollection(OrderedFolder, Per self.REQUEST.SESSION['ids']=ids number=int(len(ids)/numberOfColumns)+1 - + + logTime("show_thumbs_rows finished (%s)"%str(number)) return range(number+1) def show_thumbs_columns(self,row,numberOfColumns): """Ausgabe einer Liste der Reihe""" ids=self.REQUEST.SESSION['ids'] max=len(ids) + logTime("show_thumb_columns finishes row: %s"%row) if (row*numberOfColumns)