--- ImageArchive/ImageArchive.py 2006/07/20 10:41:40 1.97
+++ ImageArchive/ImageArchive.py 2008/08/15 14:10:23 1.104
@@ -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:
@@ -53,7 +67,7 @@ tdir="tmp"
#tdir = "/mpiwg/temp/tmp/archivesImageServer/"
#tdir="/tmp/archivesImageServer/"
-imageExtensions=['jpg','jpeg','tif','tiff','png']
+imageExtensions=['.jpg','.jpeg','.tif','.tiff','.png','.gif']
def splitPath(str):
str2=str.replace("\\","/")
@@ -307,7 +321,7 @@ class ImageDigilib(Folder,Persistent,Imp
def isAccessible(self):
"""gives true if obejct is accessible taking the rights of the user into account"""
-
+ logTemp("isaccessible")
#TODO: implement rights, currently true if external and false if internal, and true if user has role authenticated
username=self.REQUEST['AUTHENTICATED_USER']
@@ -499,7 +513,7 @@ class ImageDigilib(Folder,Persistent,Imp
self.scaleWorkingVersions()
- self.scaleToJpg()
+ #self.scaleToJpg()
if RESPONSE:
RESPONSE.redirect(self.aq_parent.absolute_url()+"?filename="+self.filename)
@@ -518,12 +532,12 @@ class ImageDigilib(Folder,Persistent,Imp
newName=os.path.join(path,self.getId())
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()
@@ -564,10 +578,10 @@ 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()
@@ -628,7 +642,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 +653,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 +772,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 +789,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:
@@ -793,12 +808,12 @@ class ImageCollection(OrderedFolder, Per
name=os.path.splitext(name)[0]
for extension in imageExtensions:
- nameExt=name+"."+extension
+ nameExt=name+extension
if hasattr(self,nameExt):
return getattr(self,nameExt)
- nameExt=name+"_."+extension
+ nameExt=name+"_"+extension
if hasattr(self,nameExt):
return getattr(self,nameExt)
@@ -1676,7 +1691,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 +1735,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:
+ logger("ImageArchiveMD:import", logging.INFO, "adding ZOPE: %s"%file)
ret=ret+"
"+file+" created!"
newObj=ImageDigilib(file,file)
#print newObj,file
@@ -1932,13 +1952,15 @@ class ImageCollectionMD(ImageCollection,
except:
"""nothing yet"""
-
- args={}
- args['_table']=self.imageCollectionConfig.getTable()
- args[self.imageCollectionConfig.getKey()]=file
-
- if not self.ZSQLInlineSearch(args=args):
- self.ZSQLAdd(args=args)
+ # check entry in database
+ args={}
+ args['_table']=self.imageCollectionConfig.getTable()
+ args[self.imageCollectionConfig.getKey()]=file
+
+ if not self.ZSQLInline(args=args):
+ logger("ImageArchiveMD:import", logging.INFO, "adding DB: %s"%file)
+ self.ZSQLAdd(args=args)
+
#print ret
#pt=PageTemplateFile('Products/ImageArchive/out.zpt')).__of__(self)
#print self.ImageStoragePath
@@ -1952,7 +1974,7 @@ class ImageCollectionMD(ImageCollection,
self.scaleWorkingVersions()
- self.scaleToJpgs()
+ #self.scaleToJpgs()
if RESPONSE:
RESPONSE.redirect('manage_main')
@@ -2036,6 +2058,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")
@@ -2069,7 +2092,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=[]
@@ -2220,13 +2243,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:
@@ -2238,6 +2267,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:
@@ -2299,9 +2331,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'):
@@ -2470,4 +2500,4 @@ def manage_AddImageZogiLib(self,id=None,
def manage_AddImageZogiLibForm(self):
"""to be done"""
-
\ No newline at end of file
+