--- ImageArchive/ImageArchive.py 2006/05/24 09:56:58 1.93 +++ ImageArchive/ImageArchive.py 2008/08/18 13:27:42 1.105 @@ -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: @@ -49,11 +63,11 @@ except: manage_options=() - -tdir = "/mpiwg/temp/tmp/archivesImageServer/" +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("\\","/") @@ -80,16 +94,19 @@ class generateSet: """generateSetThread""" - def __init__(self,filenames,filenamesIds,ImageViewerPath,ids,url,local=None,version="working"): + def __init__(self,filenames,filenamesIds,ImageViewerPath,ImageStoragePath,destBasis,ids,url,local=None,version="working"): """init generateSet""" self.filenames=filenames self.filenamesIds=filenamesIds self.ImageViewerPath=ImageViewerPath + self.ImageStoragePath=ImageStoragePath + self.destBasis=destBasis self.ids=ids self.local=local self.url=url self.version=version self.done=None + self.response="" def __call__(self): @@ -115,26 +132,34 @@ class generateSet: for id in self.filenames: - if self.filenamesIds.has_key(id[0]): + if self.filenamesIds.has_key(id[0]) and self.filenamesIds[id[0]][0]: filename=self.filenamesIds[id[0]][0]+"_"+id[0] else: filename=id[0] self.response+=str("
Get File: %s
\n"%filename)
-
+ toggle=False
+
if self.local:
if self.version=="working":
-
- sourcePath="/mpiwg/temp/online/scaled/small/"+self.ImageViewerPath+"/"+os.path.splitext(id[0])[0]+".jpg"
- else:
- sourcePath="/mpiwg/online/"+self.ImageViewerPath+"/"+id[0]
+
+ sourcePath=self.destBasis+"/"+self.ImageViewerPath+"/"+os.path.splitext(id[0])[0]+".jpg"
+ if not os.path.exists(sourcePath):
+ self.response+=str("
%s doesn't exist I'll try the non scaled image
"%sourcePath) + toggle=True + if (self.version!="working") or toggle: + toggle=False + sourcePath=self.ImageStoragePath+"/"+id[0] + if not os.path.exists(sourcePath): + sourcePath=self.ImageStoragePath+"/"+os.path.splitext(id[0])[0]+".jpg" + targetPath=tmpPath+"/"+filename try: shutil.copyfile(sourcePath,targetPath) except: - self.response+=(str("Error in File: %s (possible missing)
\n"%filename))
+ self.response+=(str("
Error in File: %s (possible missing)
\n"%sourcePath))
else:
if self.version=="working":
requestString=self.ImageViewerPath+"/"+os.path.splitext(urllib.quote(id[0]))[0]+"&dh=2000&dw=2000"
@@ -283,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):
@@ -296,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"""
-
+ 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']
@@ -380,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:
@@ -488,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)
@@ -504,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()
@@ -533,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):
@@ -553,18 +587,25 @@ 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!
f.write(filedata)
f.close()
try:
- os.chmod(imagePath,0664)
+ os.chmod(newImagePath,0664)
except:
pass
#scale thumb
@@ -578,13 +619,19 @@ class ImageDigilib(Folder,Persistent,Imp
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)
@@ -617,7 +664,8 @@ class ImageDigilib(Folder,Persistent,Imp
- self.REQUEST.SESSION['string']=""% path
+ imageString=""% path
+ self.REQUEST.SESSION['string']=imageString
if url:
return ""% path
else:
@@ -627,7 +675,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):
@@ -746,14 +794,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:
@@ -763,11 +811,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
+ logger("ImageCollection:scale",logging.INFO,scaleStr)
ret=os.popen2(scaleStr,1)[1].read()
if RESPONSE:
@@ -781,12 +830,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)
@@ -828,7 +877,7 @@ class ImageCollection(OrderedFolder, Per
if not threadName or threadName=="":
- threadStart=generateSet(self.REQUEST.SESSION['filenames'],self.REQUEST.SESSION['filenamesIds'],self.ImageViewerPath,self.show_thumbs(),self.absolute_url(),local=local,version=version)
+ threadStart=generateSet(self.REQUEST.SESSION['filenames'],self.REQUEST.SESSION['filenamesIds'],self.ImageViewerPath,self.ImageStoragePath,self.destBasis,self.show_thumbs(),self.absolute_url(),local=local,version=version)
thread=Thread(target=threadStart)
thread.start()
@@ -919,9 +968,9 @@ class ImageCollection(OrderedFolder, Per
dest=os.path.join(self.scaledBasis,'thumb')
self.scale(dir=self.getImageStoragePath(),dest=dest,scaleTo=100,RESPONSE=RESPONSE)
#ret=os.popen("ssh nausikaa2.rz-berlin.mpg.de /usr/local/mpiwg/scripts/scaleomat.pl -src=/mpiwg/online/ -dir=%s -dest=/mpiwg/temp/online/scaled/thumb -scaleto=100 &"% self.ImageViewerPath)
- if RESPONSE:
- RESPONSE.write(ret.read())
- RESPONSE.write("\n")
+ #if RESPONSE:
+ # RESPONSE.write(ret.read())
+ # RESPONSE.write("\n")
return "RESCALING STARTED"
@@ -1593,16 +1642,17 @@ class ImageCollection(OrderedFolder, Per
return ret
- def show_thumbs_selected_rows(self,numberOfColumns):
+ def show_thumbs_selected_rows(self,numberOfColumns,start=0,max=10000):
"""Ausgabe anzahl"""
ids=self.show_selected_thumbs()
if not ids:
return None
self.REQUEST.SESSION['ids']=ids
- number=int(len(ids)/numberOfColumns)+1
- self.REQUEST.SESSION['number']=range(number)
- return range(number+1)
+ number=min(start+int(len(ids)/numberOfColumns)+1,max)
+
+ self.REQUEST.SESSION['number']=range(start,number)
+ return range(start,number+1)
def setColTimesRowForm(self):
"""form for matrix setting"""
@@ -1663,7 +1713,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)
@@ -1706,32 +1757,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+" created!"
newObj=ImageDigilib(file,file)
#print newObj,file
@@ -1919,13 +1974,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
@@ -1939,7 +1996,7 @@ class ImageCollectionMD(ImageCollection,
self.scaleWorkingVersions()
- self.scaleToJpgs()
+ #self.scaleToJpgs()
if RESPONSE:
RESPONSE.redirect('manage_main')
@@ -2023,6 +2080,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")
@@ -2056,7 +2114,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=[]
@@ -2207,13 +2265,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:
@@ -2225,6 +2289,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:
@@ -2286,9 +2353,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'):