--- ImageArchive/ImageArchive.py 2006/08/31 11:40:06 1.99
+++ ImageArchive/ImageArchive.py 2009/01/06 16:13:51 1.107
@@ -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
@@ -24,9 +26,21 @@ from threading import Thread
import Queue
import cgi
import sys
-import zLOG
+
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
try:
@@ -294,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):
@@ -307,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']
@@ -391,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:
@@ -499,7 +520,7 @@ class ImageDigilib(Folder,Persistent,Imp
self.scaleWorkingVersions()
- self.scaleToJpg()
+ #self.scaleToJpg()
if RESPONSE:
RESPONSE.redirect(self.aq_parent.absolute_url()+"?filename="+self.filename)
@@ -515,15 +536,15 @@ 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):
- zLOG.LOG("ImageArchive:scaleToJpg", zLOG.INFO, "%s already exists"%newName)
+ logger("ImageArchive:scaleToJpg", logging.INFO, "%s already exists"%newName)
else:
try:
os.rename(imagePath,newName)
except:
- zLOG.LOG("ImageArchive:scaleToJpg", zLOG.ERROR, "%s "%newName)
+ logger("ImageArchive:scaleToJpg", logging.ERROR, "%s "%newName)
return False
ext= os.path.splitext(imagePath)[1].lower()
@@ -544,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):
@@ -564,18 +587,26 @@ class ImageDigilib(Folder,Persistent,Imp
#kopieren der bestehenden Version in den Versions ordner.
imageNewPath=os.path.join(path,"V%i_%s"%(versionNumber,self.filename))
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)
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
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
@@ -585,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)
@@ -628,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:
@@ -638,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):
@@ -757,14 +795,14 @@ class ImageCollection(OrderedFolder, Per
fileStr=" -dir=%s"%fileTmp
scaleStr=scaleStr+fileStr
else:
- zLOG.LOG("ImageCollection:scale",zLOG.ERROR,"no directory or filename given")
+ logger("ImageCollection:scale",logging.ERROR,"no directory or filename given")
return False
if dest is not None:
destStr=" -dest=%s"%os.path.join(destBasis,dest)
scaleStr=scaleStr+destStr
else:
- zLOG.LOG("ImageCollection:scale",zLOG.ERROR,"no destionation given")
+ logger("ImageCollection:scale",logging.ERROR,"no destionation given")
return False
if scaleTo:
@@ -774,12 +812,12 @@ class ImageCollection(OrderedFolder, Per
scaleByStr=" -scaleby=%s"%scaleBy
scaleStr=scaleStr+scaleByStr
else:
- zLOG.LOG("ImageCollection:scale",zLOG.ERROR,"no destionation given")
+ logger("ImageCollection:scale",logging.ERROR,"no destionation given")
return False
#ret=scaleStr
- #zLOG.LOG("ImageCollection:scale",zLOG.INFO,scaleStr)
+ logger("ImageCollection:scale",logging.INFO,scaleStr)
ret=os.popen2(scaleStr,1)[1].read()
if RESPONSE:
@@ -1676,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)
@@ -1719,32 +1758,26 @@ 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)"+file+" already exists!"
else:
- zLOG.LOG("ImageArchiveMD:import", zLOG.INFO, "adding ZOPE: %s"%file)
+ logger("ImageArchiveMD:import", logging.INFO, "adding ZOPE: %s"%file)
ret=ret+"
"+file+" created!"
newObj=ImageDigilib(file,file)
#print newObj,file
@@ -1947,8 +1980,8 @@ class ImageCollectionMD(ImageCollection,
args['_table']=self.imageCollectionConfig.getTable()
args[self.imageCollectionConfig.getKey()]=file
- if not self.ZSQLInlineSearch(args=args):
- zLOG.LOG("ImageArchiveMD:import", zLOG.INFO, "adding DB: %s"%file)
+ if not self.ZSQLInline(args=args):
+ logger("ImageArchiveMD:import", logging.INFO, "adding DB: %s"%file)
self.ZSQLAdd(args=args)
#print ret
@@ -2048,6 +2081,7 @@ class ImageCollectionMD(ImageCollection,
rc=[]
fnIds={}
+
for found in self.ZSQLInlineSearch(args=self.REQUEST.form):
key=getattr(found,self.imageCollectionConfig.getKey())
key=self.getImageByName(key,onlyName="yes")
@@ -2081,7 +2115,7 @@ class ImageCollectionMD(ImageCollection,
def index_html(self,fn=None,selection=None,generic='No',REQUEST=None,RESPONSE=None):
"""main template collection"""
-
+ logTime("index_html %s"%self.REQUEST['QUERY_STRING'])
mode=self.REQUEST.get('mode','view')
if fn:
ret=[]
@@ -2232,13 +2266,19 @@ class ImageCollectionMD(ImageCollection,
def thumblistMD(self):
"""main template collection"""
+ logTime("thumbList MD %s"%self.REQUEST['QUERY_STRING'])
+
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()
+
def getRights(self,id):
"""get the rights from a database"""
#print self.rightsQuery%id
results=self.ZSQLSimpleSearch(self.getRightsQuery()%id)
+ logging.error("rightsQuery: %s"%(self.getRightsQuery()%id))
if results:
result = getattr(results[0],self.getRightsQueryField())
else:
@@ -2250,6 +2290,9 @@ class ImageCollectionMD(ImageCollection,
#return url
url=urllib.unquote(url)
+
+ url=url.replace(" ","+") # ersetze Leerzeichen in der URL durch "+"
+ print url
xmldoc=urllib.urlopen(url).read()
#return xmldoc
try:
@@ -2311,9 +2354,7 @@ class ImageCollectionMD(ImageCollection,
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','overview_selectedMD.zpt')).__of__(self)
return pt()
- pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','overview_selectedMD.zpt')).__of__(self)
- return pt()
-
+
def selection(self):
"""show only selected"""
if self.REQUEST.has_key('filename'):