--- ImageArchive/ImageArchive.py 2004/12/21 17:22:22 1.41 +++ ImageArchive/ImageArchive.py 2006/05/22 21:09:53 1.92 @@ -1,9 +1,15 @@ +genericServerPath="http://www.mpiwg-berlin.mpg.de/zogilib_images" #can be changed with main config + + +from Ft.Xml.Domlette import NonvalidatingReader from OFS.Folder import Folder +from OFS.OrderedFolder import OrderedFolder from OFS.SimpleItem import SimpleItem from Globals import Persistent,package_home from Acquisition import Implicit from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplate import PageTemplate +from xmlrpclib import ServerProxy import re import os import os.path @@ -13,6 +19,25 @@ import operator import tempfile import shutil from types import * +import time +from threading import Thread +import Queue +import cgi +import sys +import zLOG +import shutil + +from AccessControl import ClassSecurityInfo, getSecurityManager + +try: + from Products.ZSQLExtend.ZSQLExtend import ZSQLExtendFolder +except: + print "ZSQL Extend Folder nicht importiert" + print "Metadatendfolder funktioniert nicht!!!" + class ZSQLExtendFolder: + """leer""" + manage_options=() + try: @@ -21,28 +46,238 @@ except: print "ECHO Elements not imported" class ECHO_basis: """leer""" + manage_options=() +tdir = "/mpiwg/temp/tmp/archivesImageServer/" +#tdir="/tmp/archivesImageServer/" + +imageExtensions=['jpg','jpeg','tif','tiff','png'] def splitPath(str): - str2=str.replace("\\","/") - return os.path.split(str2)[1] + str2=str.replace("\\","/") + return os.path.split(str2)[1] def getText(nodelist): rc = "" for node in nodelist: - if node.nodeType == node.TEXT_NODE: + if node.nodeType == node.TEXT_NODE: rc = rc + node.data return rc +def getTextFromNode(nodename): + nodelist=nodename.childNodes + rc = "" + for node in nodelist: + if node.nodeType == node.TEXT_NODE: + rc = rc + node.data + return rc + +class generateSet: + """generateSetThread""" + + + def __init__(self,filenames,filenamesIds,ImageViewerPath,ids,url,local=None,version="working"): + """init generateSet""" + self.filenames=filenames + self.filenamesIds=filenamesIds + self.ImageViewerPath=ImageViewerPath + self.ids=ids + self.local=local + self.url=url + self.version=version + self.done=None + + + def __call__(self): + """call generate Set""" + + storeTempDir=tempfile.tempdir + tempfile.tempdir=tdir + + tmpPath=tempfile.mktemp() + tmpZip=tempfile.mktemp()+".gtz" + tmpFn=os.path.split(tmpZip)[1] + + if not os.path.exists(tempfile.tempdir): + os.mkdir(tempfile.tempdir) + + if not os.path.exists(tmpPath): + os.mkdir(tmpPath) + + self.response="" + + + self.response="

1. step: getting the images

" + + for id in self.filenames: + + if self.filenamesIds.has_key(id[0]): + filename=self.filenamesIds[id[0]][0]+"_"+id[0] + else: + filename=id[0] + + self.response+=str("

Get File: %s
\n"%filename) + + + 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] + targetPath=tmpPath+"/"+filename + try: + shutil.copyfile(sourcePath,targetPath) + except: + self.response+=(str("

Error in File: %s (possible missing)
\n"%filename)) + else: + if self.version=="working": + requestString=self.ImageViewerPath+"/"+os.path.splitext(urllib.quote(id[0]))[0]+"&dh=2000&dw=2000" + path=getattr(self,'serverPath',genericServerPath)+"/scaledImage?fn="+requestString + + else: + requestString=self.ImageViewerPath+"/"+os.path.splitext(urllib.quote(id[0]))[0]+"&mo=rawfile,hires" + path=getattr(self,'serverPath',genericServerPath)+"/scaledImage?fn="+requestString + + + image=urllib.urlopen(path).read() + + + fh=file(tmpPath+"/"+filename,"w") + + + fh.write(image) + fh.close() + + #folgeseiten + + if int(self.filenamesIds[id[0]][1])>1: + #ids=self.show_thumbs() + + try: + nr=self.ids.index(id[0]) + except: + self.response+=str("

Error in File: %s (possible missing)
\n"%id[0]) + + nr=0 + + numberOfPages=self.filenamesIds[id[0]][1] + for k in range(int(numberOfPages)-1): + i=k+1 + if self.filenamesIds.has_key(id[0]): + filename=self.filenamesIds[id[0]][0]+"_"+self.ids[nr+i] + else: + filename=id[0] + + self.response+=str("

Get File: %s
\n"%filename) + + if self.local: + sourcePath="/mpiwg/online/"+self.ImageViewerPath+"/"+self.ids[nr+i] + targetPath=tmpPath+"/"+filename + try: + shutil.copyfile(sourcePath,targetPath) + + except: + self.response+=str("

Error in File: %s (missing?)
\n"%filename) + + else: + + requestString=self.ImageViewerPath+"/"+os.path.splitext(ids[nr+i])[0]+"&mo=rawfile,hires" + path=getattr(self,'serverPath',genericServerPath)+"/scaledImage?fn="+requestString + + image=urllib.urlopen(path).read() + + + fh=file(tmpPath+"/"+filename,"w") + fh.write(image) + fh.close() + + self.response+="

2. step: creating the downloadable file

" + self.response+="

Create gtar
" + self.response+="

This can take a while....
\n" + + fh=os.popen2("gnutar zcvf %s %s/*"%(tmpZip,tmpPath),1)[1] + self.response+="
" + for c in fh.read(): + self.response+=c + if c==")": + self.response+="
\n" + + + + + shutil.rmtree(tmpPath) + + self.response+="

finished
\n" + + len=os.stat(tmpZip)[6] + downloadUrl=self.url+"/downloadSet" + self.response+="""

Click here for download ( %i Byte)

\n"""%(tmpFn,len) + self.response+="""

The file will be stored for a while, you can download it later, the URL is:

+

%s?fn=%s\n"""%(tmpFn,downloadUrl,tmpFn) + + self.done=True + def getResult(self): + """get result""" + return self.response + + def isDone(self): + if self.done: + return True + else: + return False + +class metaData(SimpleItem): + """Klasse fuer metadaten""" + meta_type="metaData" + + def __init__(self,xmlurl,container=None): + """__init__""" + return self.update(xmlurl,container) + + + def update(self,xmlurl,container=None): + """update""" + + try: + xmlfh=urllib.urlopen(xmlurl) + dom=xml.dom.minidom.parse(xmlfh) + except: + return None + + md=dom.getElementsByTagName(container) + mlist=[] + if md: + for node in md[0].childNodes: + if node.nodeType==dom.ELEMENT_NODE: + name=node.tagName + content=getTextFromNode(node) + setattr(self,name,content) + mlist.append(name) + self.mlist=mlist[0:] + else: + self.mlist=[] + + def index_html(self): + """index""" + ret="" + for tag in self.mlist: + ret+="

%s=%s

"%(tag,getattr(self,tag)) + return ret+"" + + + + class ImageDigilib(Folder,Persistent,Implicit): """Anzeige object fuer digilib""" meta_type="ImageDigilib" - + security=ClassSecurityInfo() leiden_meta_fields=['image_id','date','country','place','people','description','photographer'] manage_options = Folder.manage_options+( @@ -51,6 +286,40 @@ class ImageDigilib(Folder,Persistent,Imp ) + + + def getAccessRight(self): + """get the accessright, return is string "extern" or "intern" """ + return self.getRights(self.filename.split('.')[0]) + + security.declarePublic('isAccessible') + + def isAccessible(self): + """gives true if obejct is accessible taking the rights of the user into account""" + + #TODO: implement rights, currently true if external and false if internal, and true if user has role authenticated + + username=self.REQUEST['AUTHENTICATED_USER'] + #print username + #print self.acl_users.getUserNames() + user=getSecurityManager().getUser() + + roles=user.getRoles() + + + if self.getRightsQuery()=="": + #query empty then always true + return True + + + if 'Authenticated' in roles: + return True + + if self.getAccessRight()=="extern": + return True + else: + return False + def addMetaObject(self,id,RESPONSE=None): """Add an MetaObject""" objectType=getattr(self.Control_Panel.Products.ImageMetaData,self.genericMetaDataType) @@ -80,128 +349,310 @@ class ImageDigilib(Folder,Persistent,Imp self.filename=filename self.meta=meta + def getBasename(self): + """returns base filename (sans extension)""" + return os.path.splitext(self.filename)[0] + def getMeta(self): """ausgabe der metadaten""" return self.meta - + + def manageMetaData(self,strict=None): + """create or updateMetadata""" + + md=self.ZopeFind(self,obj_metatypes=["metaData"]) + + if not md: + self._setObject("metaData",metaData(self.meta,"ROW")) + + else: + if not strict: + md[0][1].update(self.meta,"ROW") + else: + print "strict" + if len(md[0][1].mlist)==0: + print " +++",self.getId() + md[0][1].update(self.meta,"ROW") + else: + print " ---",self.getId() + def uploadImage(self,fileupload,path_name): """upload an Image from an Requast""" #path_name=self.ImageStoragePath - fn=splitPath(fileupload.filename) + fn = self.filename or splitPath(fileupload.filename) 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: """hack""" - #scale thumb - + #< thumb + self.scaleThumbs() - #scale standard + #scale standard - self.scaleWorkingVersions() + self.scaleWorkingVersions() - - + + def downloadWorkingVersion(self): - """download working version (2000 pixel)""" - - return self.download(fmt="&dw=2000&dh=2000",suffix=".jpg") + """download working version (2000 pixel)""" + + return self.download(fmt="&dw=2000&dh=2000",suffix=".jpg") def download(self,fmt="&mo=rawfile,hires",suffix=None): """download""" - path="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?fn="+self.ImageViewerPath+"/"+os.path.splitext(self.filename)[0]+fmt - - if self.REQUEST.SESSION.has_key('filenamesIds') and self.REQUEST.SESSION['filenamesIds'].has_key(self.filename): - filename=self.REQUEST.SESSION['filenamesIds'][self.filename][0]+"_"+self.filename - else: - filename=self.filename - - if suffix: - filename=os.path.splitext(filename)[0]+suffix - - self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename="%s" """%filename) - self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") - image=urllib.urlopen(path).read() - self.REQUEST.RESPONSE.write(image) - self.REQUEST.RESPONSE.close() + + requestString=self.ImageViewerPath+"/"+os.path.splitext(self.filename)[0]+fmt + path=getattr(self,'serverPath',genericServerPath)+"/scaledImage?fn="+requestString + + + if self.REQUEST.SESSION.has_key('filenamesIds') and self.REQUEST.SESSION['filenamesIds'].has_key(self.filename): + filename=self.REQUEST.SESSION['filenamesIds'][self.filename][0]+"_"+self.filename + else: + filename=self.filename + + if suffix: + filename=os.path.splitext(filename)[0]+suffix + + self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename="%s" """%filename) + self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") + #print path + imagefh=urllib.urlopen(path,'rb') + + self.REQUEST.RESPONSE.write(imagefh.read()) + self.REQUEST.RESPONSE.close() #return self.REQUEST.RESPONSE.redirect(path) def updateImageForm(self): - """form""" - pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','upDateImageForm.zpt')).__of__(self) - return pt() - - def updateImage(self,file,RESPONSE): - """lade neues Version des Bildes""" - #teste ob Dokumenten ordner schon vorhanden - imagePath=os.path.join(self.ImageStoragePath,self.getId()) - path=os.path.join(self.ImageStoragePath,"."+self.getId()+".dir") - print "path",path - if not os.path.exists(path): - os.mkdir(path,0775) - os.chmod(path,0775) - - versionNumber=getattr(self,'versionNumber',0)+1 - - #teste ob version schon existiert - - while os.path.exists(os.path.join(path,"V%i_%s"%(versionNumber,self.getId()))): - versionNumber+=1 - - #kopieren der bestehenden Version in den Versions ordner. - imageNewPath=os.path.join(path,"V%i_%s"%(versionNumber,self.getId())) - os.rename(imagePath,imageNewPath) - - #lesen des upload files und schreiben - filedata=file.read() - f=open(imagePath,"w") - f.write(filedata) - f.close() - try: - os.chmod(imagePath,0664) - except: - """hack""" - #scale thumb - - self.scaleThumbs() - - #scale standard - - self.scaleWorkingVersions() - - if RESPONSE: - RESPONSE.redirect(self.absolute_url()) - - return "done" - - def thumb(self): - """show thumb""" - thumbname=os.path.splitext(self.filename)[0]+".jpg" - ## if not os.path.exists("/mpiwg/temp/online/scaled/small/"+self.ImageViewerPath+"/"+thumbname): -## image=urllib.urlopen("http://nausikaa2.rz-berlin.mpg.de:18080/digitallibrary/servlet/Scaler/?fn="+self.ImageViewerPath+"/"+self.filename+"&dw=150&mo=lores").read() -## f=open("/mpiwg/temp/online/scaled/small/"+self.ImageViewerPath+"/"+thumbname,"w") -## f.write(image) -## f.close() -## os.popen("ssh nausikaa2.rz-berlin.mpg.de /usr/local/mpiwg/scripts/scaleomat.pl %s /mpiwg/temp/online/scaled/small 150 &"% self.ImageViewerPath) + """form""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','upDateImageForm.zpt')).__of__(self) + return pt() + + + security.declareProtected('View management screens','renameImageForm') + def renameImageForm(self): + """form""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','renameImageForm.zpt')).__of__(self) + return pt() + + security.declareProtected('View management screens','renameImage') + def renameImage(self,newname,RESPONSE=None): + """umbenennen""" + #umbennen des files im folder + oldname=self.getId() + self.aq_parent.manage_renameObjects(ids=[oldname],new_ids=[newname]) + self.title=newname[0:] + self.filename=newname[0:] + #umbennen des files auf dem server + oldpath=os.path.join(self.ImageStoragePath,oldname) + newpath=os.path.join(self.ImageStoragePath,newname) + os.rename(oldpath,newpath) - #DEVEL:take nausikaa for server solution + #umbenennen des versionsfolders + oldfolder=os.path.join(self.ImageStoragePath,"."+oldname+".dir") + newfolder=os.path.join(self.ImageStoragePath,"."+newname+".dir") + if os.path.exists(oldfolder): + os.rename(oldfolder,newfolder) + else: + os.mkdir(newfolder) + + #schreibe info uber umbennenung + + renameName=os.path.join(newfolder,"renamed") + if os.path.exists(renameName): + fh=file(renameName,'a') + else: + fh=file(renameName,'w') + + tm=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) + try: + user=self.REQUEST['AUTHENTICATED_USER'] + except: + user="unknown" + + str="""%s %s %s %s\n"""%(tm,user,oldname,newname) + fh.write(str) + fh.close() + + #scale thumb + + self.scaleThumbs() + + #scale standard + + self.scaleWorkingVersions() + + self.scaleToJpg() + if RESPONSE: + RESPONSE.redirect(self.aq_parent.absolute_url()+"?filename="+self.filename) + + def scaleToJpg(self,RESPONSE=None): + """create a jpg""" + + #create backup of the original file - path="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?fn="+self.ImageViewerPath+"/"+os.path.splitext(self.filename)[0]+"&dw=100&dh=100&mo=lores" - #path="/mpiwg/online/"+self.ImageViewerPath+"/"+thumbname + imagePath=os.path.join(self.ImageStoragePath,self.filename) + path=os.path.join(self.ImageStoragePath,"."+self.getId()+".dir") + + if not os.path.exists(path): + os.mkdir(path,0775) + os.chmod(path,0775) + + newName=os.path.join(path,self.getId()) + + if os.path.exists(newName): + zLOG.LOG("ImageArchive:scaleToJpg", zLOG.INFO, "%s already exists"%newName) + else: + try: + os.rename(imagePath,newName) + except: + zLOG.LOG("ImageArchive:scaleToJpg", zLOG.ERROR, "%s "%newName) + return False + + ext= os.path.splitext(imagePath)[1].lower() + if ext.rstrip()==".jpg": + shutil.copy(newName,imagePath) + print "copy",imagePath + return True + + print "SCALED",imagePath + dest="/Volumes/paviaExtern/docuserver/images/exhibitionImages/" + dir=self.getId() + src=path + self.scale(dest=dest,dir=dir,src=path,scaleBy=1,RESPONSE=RESPONSE) + return True + + def updateImage(self,_fileupload,_rename=None,RESPONSE=None): + """lade neues Version des Bildes""" + #teste ob Dokumenten ordner schon vorhanden + #imagePath=os.path.join(self.ImageStoragePath,self.getId()) + + identifyField="filename" + + if _fileupload and _fileupload.filename!="": + imagePath=os.path.join(self.ImageStoragePath,self.filename) + path=os.path.join(self.ImageStoragePath,"."+self.getId()+".dir") + + if not os.path.exists(path): + os.mkdir(path,0775) + os.chmod(path,0775) + + versionNumber=getattr(self,'versionNumber',0)+1 + + #teste ob version schon existiert + + while os.path.exists(os.path.join(path,"V%i_%s"%(versionNumber,self.filename))): + versionNumber+=1 + + #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)) + os.rename(imagePath,imageNewPath) + except: + zLOG.LOG("ImageArchive:updateImage", zLOG.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! + f.write(filedata) + f.close() + try: + os.chmod(imagePath,0664) + except: + pass + #scale thumb + + self.scaleThumbs() + + #scale standard + + self.scaleWorkingVersions() + self.scaleToJpg() + if _rename: + self.renameImage(_fileupload.filename) + + + args=self.REQUEST.form + + args['-identify']=identifyField+"="+args['_identifyField'] + + self.ZSQLChange(args=args) + + if RESPONSE: + RESPONSE.redirect(self.aq_parent.absolute_url()+"?filename="+self.filename) + + + return "done" + + security.declarePublic('thumb') + def thumb(self,url=None): + """show thumb""" + thumbname=os.path.splitext(self.filename)[0]+".jpg" + requestString=self.ImageViewerPath+"/"+os.path.splitext(self.filename)[0]+"&dw=100&dh=100&mo=lores" + path=getattr(self,'serverPath',genericServerPath)+"/scaledImage?fn="+requestString + + self.REQUEST.SESSION['string']=""% path - pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','thumb.zpt')).__of__(self) - return pt() + if url: + return ""% path + else: + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','thumb.zpt')).__of__(self) + return pt() + + + def thumbMD(self,url=None): + """show thumb mit Metadaten erwarten image in ImageCollectionMD + """ + thumbname=os.path.splitext(self.filename)[0]+".jpg" + + requestString=self.ImageViewerPath+"/"+os.path.splitext(self.filename)[0]+"&dw=100&dh=100&mo=lores" + path=getattr(self,'serverPath',genericServerPath)+"/scaledImage?fn="+requestString + + + self.REQUEST.SESSION['string']=""% path + if url: + return ""% path + else: + + overview=self.ZopeFind(self.aq_parent,obj_ids=['thumb.html']) + if overview: + return getattr(self,overview[0][0])() + else: + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','thumbMD.zpt')).__of__(self) + return pt() + + + def image(self,dw=None,dh=None): + """show image only with scaler""" + str=[] + if (not dw) and (not dh): + str.append("mo=file") + if dw: + str.append("dw=%s"%dw) + + if dh: + str.append("dw=%s"%dh) + + str.append("lv=2&fn=%s"%self.ImageViewerPath+"/"+os.path.splitext(self.filename)[0]) + + + requestString="&".join(str) + + self.REQUEST.RESPONSE.redirect(getattr(self,'serverPath',genericServerPath)+"/scaledImage?"+requestString) + def index_html(self): - """show image""" + """show image with zogilib""" #DEVELOP: take first one for server - - path="http://content.mpiwg-berlin.mpg.de/zogilib_images?lv=2&fn="+self.ImageViewerPath+"/"+os.path.splitext(self.filename)[0] + #path="http://127.0.0.1:8080/zogilib_images?lv=2&fn="+self.ImageViewerPath+"/"+os.path.splitext(self.filename)[0] + path=getattr(self,'serverPath',genericServerPath)+"?lv=2&fn="+self.ImageViewerPath+"/"+os.path.splitext(self.filename)[0] return self.REQUEST.RESPONSE.redirect(path) @@ -214,7 +665,8 @@ def manage_AddImageDigilib(self,id,fileu """Add ImageCollection""" #fileupload=self.REQUEST['fileupload'] - fn=splitPath(fileupload.filename) + #fn=splitPath(fileupload.filename) + fn = id # filename is the same as id newObj=ImageDigilib(id,fn,meta) self._setObject(id,newObj) @@ -225,226 +677,284 @@ def manage_AddImageDigilib(self,id,fileu -class ImageCollection(Folder, Persistent, Implicit,ECHO_basis): - - """Sammelordner für Bilder""" +class ImageCollection(OrderedFolder, Persistent, Implicit,ECHO_basis): + """Sammelordner fuer Bilder""" meta_type="ImageCollection" - + + security=ClassSecurityInfo() + + #scalerPath="http://127.0.0.1:18080/digitallibrary/servlet/Scaler/?fn=" + #scalerPath="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?fn=" + + zipThreads={} + zipThreads2={} genericMetaDataType="leiden_meta" leiden_meta_fields=['image_id','date','country','place','people','description','photographer'] + scaledBasis="/mpiwg/temp/online/scaled" defaultMetaString="http://fm-web.mpiwg-berlin.mpg.de:8050/FMRes/FMPJS?-db=Wissenschaftlerportraits.fp5&-layID=69&-token=25&-max=1&-format=formvwcss.htm&-mode=browse&images::filename=%s&-find" ## TEST FUER IMAGEDATENBANK WP - + imgcoll_main = PageTemplateFile('zpt/overview', globals()) + imgcoll_mainMD = PageTemplateFile('zpt/overviewMD', globals()) + imgcoll_thumb = PageTemplateFile('zpt/thumb', globals()) + imgcoll_thumbMD = PageTemplateFile('zpt/thumbMD', globals()) + + destBasis="/docuserver/scaled/" + srcBasis="/docuserver/images" + def scale(self,dest=None,dir=None,src=None,scaleTo=None,scaleBy=None,RESPONSE=None): + """scaler""" + #scaleomatStr="ssh nausikaa2.rz-berlin.mpg.de /usr/local/mpiwg/scripts/scaleomat.pl -src=/mpiwg/online/ %s" + scaleomatStr="/docuserver/libs/scaleomat/scaleomat.pl" + + destBasis=self.destBasis + srcBasis=self.srcBasis + if src: + srcStr=" -src=%s"%src + else: + srcStr=" -src=%s"%srcBasis + + scaleStr=scaleomatStr+srcStr + if dir: + dirTmp=dir.replace(srcBasis,'') + dirStr=" -dir=%s"%dirTmp + scaleStr=scaleStr+dirStr + elif filename: + fileTmp=filename.replace(srcBasis,'') + fileStr=" -dir=%s"%fileTmp + scaleStr=scaleStr+fileStr + else: + zLOG.LOG("ImageCollection:scale",zLOG.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") + return False + + if scaleTo: + scaleToStr=" -scaleto=%s"%scaleTo + scaleStr=scaleStr+scaleToStr + elif scaleBy: + scaleByStr=" -scaleby=%s"%scaleBy + scaleStr=scaleStr+scaleByStr + else: + zLOG.LOG("ImageCollection:scale",zLOG.ERROR,"no destionation given") + return False + + + #ret=scaleStr + ret=os.popen2(scaleStr,1)[1].read() + + if RESPONSE: + RESPONSE.write(ret) + return True + + def getImageObject(self,name): + """gibt objeckt name zurueck""" + if hasattr(self,name): + return getattr(self,name) + + name=os.path.splitext(name)[0] + for extension in imageExtensions: + nameExt=name+"."+extension + + if hasattr(self,nameExt): + return getattr(self,nameExt) + + nameExt=name+"_."+extension + if hasattr(self,nameExt): + return getattr(self,nameExt) + + return getattr(self,"defaultImg") + + def getServerPath(self): + """get Server path""" + return getattr(self,'serverPath',genericServerPath) + + def getScalerPath(self): + """get ScalerPath""" + path=getattr(self,'serverPath',genericServerPath)+"/scaledImage?fn=" + + def getImageViewerPath(self): + """get ImageViewerPath""" + return self.ImageViewerPath + + def getImageStoragePath(self): + """get ImageStoragePath""" + return self.ImageStoragePath + + def refreshTxt(self): + """txt fuer refresh""" + tn=self.REQUEST.SESSION['threadName'] + return """ 2;url=%s?repeat=%s """%(self.absolute_url()+"/createSet",tn) + + def createSet(self,RESPONSE=None,local=None,version="working",repeat=None): + """download aller gewaehlten files""" + + threadName=repeat + + + 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) + thread=Thread(target=threadStart) + + thread.start() + + + self.zipThreads[thread.getName()[0:]]=threadStart + self.zipThreads2[thread.getName()[0:]]=thread + self.REQUEST.SESSION['threadName']=thread.getName()[0:] + wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['zip_wait_template']) + if wait_template: + return wait_template[0][1]() + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_wait.zpt')).__of__(self) + return pt() + #xmltrans.run() + else: + self.REQUEST.SESSION['threadName']=threadName + + if (self.zipThreads[threadName].getResult()==None): + + wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['wait_template']) + if wait_template: + return wait_template[0][1]() + + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_wait.zpt')).__of__(self) + return pt() + else: + if self.zipThreads[threadName].isDone(): + self.REQUEST.SESSION['result']=self.zipThreads[threadName].getResult() + self.zipThreads2[threadName].join() + del(self.zipThreads2[threadName]) + del(self.zipThreads[threadName]) + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_result.zpt')).__of__(self) + return pt() + + else: + self.REQUEST.SESSION['result']=self.zipThreads[threadName].getResult() + self.REQUEST.SESSION['threadName']=threadName + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','zip_wait_result.zpt')).__of__(self) + return pt() + + + + + + def checkThreads(self): + """teste running threads""" + ret=""" + +

Threads of %s

"""%(self.absolute_url(),self.getId()) + + for threadName in self.zipThreads.keys(): + if self.zipThreads2[threadName].isAlive(): + ret+="

%s --> alive

"%threadName + else: + ret+="

%s --> dead

"%threadName + return ret+"" - def createSet(self,RESPONSE=None,local=None,version="working"): - """download aller gewaehlten files""" - tempfile.tempdir="/tmp/archivesImageServer" - - tmpPath=tempfile.mktemp() - - - tmpZip=tempfile.mktemp()+".zip" - tmpFn=os.path.split(tmpZip)[1] - - - if not os.path.exists(tempfile.tempdir): - os.mkdir(tempfile.tempdir) - - if not os.path.exists(tmpPath): - os.mkdir(tmpPath) - - - if RESPONSE: - RESPONSE.setHeader("Content-Type","text/html") - RESPONSE.write("

I am creating the download archive

") - RESPONSE.write("

1. step: getting the images

") - - if not self.REQUEST.SESSION.has_key('filenames'): - RESPONSE.write("

ERROR

") - RESPONSE.write("

I forgot, the selected files. Please reselect.\n") - return 0 - - for id in self.REQUEST.SESSION['filenames']: - - if self.REQUEST.SESSION.has_key('filenamesIds') and self.REQUEST.SESSION['filenamesIds'].has_key(id[0]): - filename=self.REQUEST.SESSION['filenamesIds'][id[0]][0]+"_"+id[0] - else: - filename=id[0] - - if RESPONSE: - RESPONSE.write(str("

Get File: %s
\n"%filename)) - - if local: - if 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] - targetPath=tmpPath+"/"+filename - try: - shutil.copyfile(sourcePath,targetPath) - except: - if RESPONSE: - RESPONSE.write(str("

Error in File: %s (possible missing)
\n"%filename)) - else: - """nothing""" - else: - if version=="working": - path="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?fn="+self.ImageViewerPath+"/"+os.path.splitext(urllib.quote(id[0]))[0]+"&dh=2000&dw=2000" - else: - path="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?fn="+self.ImageViewerPath+"/"+os.path.splitext(urllib.quote(id[0]))[0]+"&mo=rawfile,hires" - image=urllib.urlopen(path).read() - - - fh=file(tmpPath+"/"+filename,"w") - - - fh.write(image) - fh.close() - - #folgeseiten - if int(self.REQUEST.SESSION['filenamesIds'][id[0]][1])>1: - ids=self.show_thumbs() - try: - nr=ids.index(id[0]) - except: - if RESPONSE: - RESPONSE.write(str("

Error in File: %s (possible missing)
\n"%id[0])) - else: - """nothing""" - - nr=0 - - numberOfPages=self.REQUEST.SESSION['filenamesIds'][id[0]][1] - for k in range(int(numberOfPages)-1): - i=k+1 - if self.REQUEST.SESSION.has_key('filenamesIds') and self.REQUEST.SESSION['filenamesIds'].has_key(id[0]): - filename=self.REQUEST.SESSION['filenamesIds'][id[0]][0]+"_"+ids[nr+i] - else: - filename=id[0] - - if RESPONSE: - RESPONSE.write(str("

Get File: %s
\n"%filename)) - - if local: - sourcePath="/mpiwg/online/"+self.ImageViewerPath+"/"+ids[nr+1] - targetPath=tmpPath+"/"+filename - try: - shutil.copyfile(sourcePath,targetPath) - except: - if RESPONSE: - RESPONSE.write(str("

Error in File: %s (missing?)
\n"%filename)) - else: - """nothing""" - else: - path="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?fn="+self.ImageViewerPath+"/"+os.path.splitext(ids[nr+i])[0]+"&mo=rawfile,hires" - - image=urllib.urlopen(path).read() - - - fh=file(tmpPath+"/"+filename,"w") - fh.write(image) - fh.close() - - if RESPONSE: - RESPONSE.write("

2. step: creating the downloadable file

") - RESPONSE.write("

Create Zip
") - RESPONSE.write("

This can take a while....
\n") - if RESPONSE: - fh=os.popen2("zip -u %s %s/*"%(tmpZip,tmpPath),1)[1] - RESPONSE.write("
") - for c in fh.read(): - RESPONSE.write(c) - - if c==")": - RESPONSE.write("
\n") - - - else: - os.popen("zip -u %s %s/*"%(tmpZip,tmpPath)) - - - shutil.rmtree(tmpPath) - - if RESPONSE: - RESPONSE.write("

finished
\n") - - if RESPONSE: - len=os.stat(tmpZip)[6] - downloadUrl=self.absolute_url()+"/downloadSet" - RESPONSE.write("""

Click here for download ( %i Byte)

\n"""%(tmpFn,len)) - RESPONSE.write("""

The file will be stored for a while, you can download it later, the URL is:

-

%s?fn=%s\n"""%(tmpFn,downloadUrl,tmpFn)) - RESPONSE.close() - def downloadSet(self,fn): - """download prepared set""" - filename="/tmp/archivesImageServer/"+fn - - self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename="%s" """%"image.zip") - self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") - len=os.stat(filename)[6] - self.REQUEST.RESPONSE.setHeader("Content-Length",len) - images=file(filename).read() - self.REQUEST.RESPONSE.write(images) - self.REQUEST.RESPONSE.close() + """download prepared set""" + filename=os.path.join(tdir,fn) + + + self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename="%s" """%"image.tgz") + self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") + len=os.stat(filename)[6] + self.REQUEST.RESPONSE.setHeader("Content-Length",len) + images=file(filename).read() + self.REQUEST.RESPONSE.write(images) + self.REQUEST.RESPONSE.close() - - + + def scaleToJpgs(self,RESPONSE=None): + """scale all tifs to jps""" + + for x in self._objects: + + if (not hasattr(getattr(self,x['id']),'scaleToJpg')) or (not getattr(self,x['id']).scaleToJpg()): + if RESPONSE: + RESPONSE.write('error:%s'%x) + + + def scaleThumbs(self,RESPONSE=None): """scale thumbs""" - - #scale thumbs - 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") - + + #scale thumbs + dest=os.path.join(self.scaledBasis,'thumb') + self.scale(dir=self.ImageStoragePath,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") + return "RESCALING STARTED" def scaleWorkingVersions(self,RESPONSE=None): """scale working versions""" - - #scale standard - - 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/small -scaleto=2000 &"% self.ImageViewerPath) - if RESPONSE: - RESPONSE.write(ret.read()) - RESPONSE.write("\n") - return "rescaling started" - + + #scale standard + + dest=os.path.join(self.scaledBasis,'small') + self.scale(dir=self.ImageStoragePath,dest=dest,scaleTo=1000,RESPONSE=RESPONSE) + + dest=os.path.join(self.scaledBasis,'medium') + self.scale(dir=self.ImageStoragePath,dest=dest,scaleTo=2000,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/small -scaleto=2000 &"% self.ImageViewerPath) + if RESPONSE: + RESPONSE.write(ret.read()) + RESPONSE.write("\n") + return "rescaling started" - def __init__(self,id,title,ImageStoragePath,ImageViewerPath,defaultMetaString): + def __init__(self,id,title,ImageStoragePath,ImageViewerPath,defaultMetaString,serverPath=genericServerPath): self.id=id self.title=title self.ImageStoragePath=ImageStoragePath self.ImageViewerPath=ImageViewerPath self.defaultMetaString=defaultMetaString + self.serverPath=serverPath + self.defaultrows = 6 + self.defaultcols = 2 optTMP= Folder.manage_options manage_options = optTMP+( {'label':'Main Config','action':'ImageCollection_config'}, {'label':'Import','action':'ImportFiles'}, - {'label':'Recalculate Metadata','action':'recalculateMeta'}, - {'label':'Import Metadata','action':'importMetaForm'}, + {'label':'Recalculate MetadataLink','action':'recalculateMetaLink'}, + {'label':'Import Metadata File','action':'importMetaFileForm'}, + {'label':'Import Metadata','action':'importMetaData'}, {'label':'Rescale thumbs','action':'scaleThumbs'}, - {'label':'Rescale working version','action':'scaleWorkingVersions'}, + {'label':'Rescale working version','action':'scaleWorkingVersions'}, ) + + def importMetaData(self,strict=None): + """import metadata, if strict ist not None then only metadata will be rebuild where metadata is empty""" - def importMetaForm(self): + for image in self.ZopeFind(self,obj_metatypes=["ImageDigilib"]): + + image[1].manageMetaData(strict) + return "ok" + + + def importMetaFileForm(self): """import metadata""" pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','importMeta.zpt')).__of__(self) return pt() - def importMeta(self,fileupload,tag): + def importMetaFile(self,fileupload,tag): """import""" filedata=fileupload.read() dom=xml.dom.minidom.parseString(filedata) @@ -486,18 +996,18 @@ class ImageCollection(Folder, Persistent filename=request.SESSION["filename"] try: nr=ids.index(filename) - + except: nr=0 else: nr=0 if nr==len(ids)-1: - return "" + return "" else: - if returnFn: - return ids[nr+1] - + if returnFn: + return ids[nr+1] + if selected: return "next image" else: @@ -531,7 +1041,7 @@ class ImageCollection(Folder, Persistent def meta_default(self,filename): """url der metadaten""" - return self.defaultMetaString % filename + return self.defaultMetaString % urllib.quote(filename) def getThumbAttribute(self,id,attr): if hasattr(self,id): @@ -553,46 +1063,65 @@ class ImageCollection(Folder, Persistent url=urllib.unquote(url) xmldoc=urllib.urlopen(url).read() #return xmldoc - try: - dom=xml.dom.minidom.parseString(xmldoc) + try: + dom=xml.dom.minidom.parseString(xmldoc) except: - return xmldoc - images=dom.getElementsByTagName('image') + return "ERROR: (%s %s) %s"%(sys.exc_info()[0],sys.exc_info()[1],xmldoc) + + images=dom.getElementsByTagName('image') rc=[] - fnIds={} + fnIds={} for image in images: - imagename=image.getElementsByTagName('imagename')[0] + imagename=image.getElementsByTagName('imagename')[0] + + - - idnr=image.getElementsByTagName('idnr')[0] - id=getText(idnr.childNodes) - numberOfPages=image.getElementsByTagName('numberOfPages')[0] - nopT=getText(numberOfPages.childNodes) - try: - nop=int(nopT) - except: - nop=0 + idnr=image.getElementsByTagName('idnr')[0] + id=getText(idnr.childNodes) + try: + numberOfPages=image.getElementsByTagName('numberOfPages')[0] + except: + numberOfPages=None + + if numberOfPages: + nopT=getText(numberOfPages.childNodes) + try: + nop=int(nopT) + except: + nop=0 + else: + nop=0 + texts=getText(imagename.childNodes).split("\n") #mehrere bilder in return getrennter liste for text in texts: if not text=="": - try: - rc.append((str(text),id,nop)) - fnIds[str(text)]=(id,nop) - except: - rc.append((repr(text),id,nop)) - fnIds[repr(text)]=(id,nop) + text=self.getImageByName(text,onlyName="yes") + try: + rc.append((str(text),id,nop)) + fnIds[str(text)]=(id,nop) + except: + rc.append((repr(text),id,nop)) + fnIds[repr(text)]=(id,nop) rc.sort() self.REQUEST.SESSION['filenames']=rc - self.REQUEST.SESSION['filenamesIds']=fnIds - + self.REQUEST.SESSION['filenamesIds']=fnIds + + overview=self.ZopeFind(self,obj_ids=['overview_selected.html']) + + if overview: + return overview[0][1]() + else: + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','overview_selected.zpt')).__of__(self) + return pt() + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','overview_selected.zpt')).__of__(self) return pt() - def recalculateMeta(self): + def recalculateMetaLink(self): """recalculate the metadata""" for entryid in self.__dict__: @@ -605,11 +1134,11 @@ class ImageCollection(Folder, Persistent def addImage(self): """Add an Image""" - + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addImage.zpt')).__of__(self) return pt() - def addImage2(self,fileupload,meta,use_default=None,RESPONSE=None): + def addImage2(self,fileupload,fileName=None,meta=None,use_default=None,RESPONSE=None): """Add""" #print "FU",fileupload @@ -621,10 +1150,13 @@ class ImageCollection(Folder, Persistent meta=None else: meta=None - fn=splitPath(fileupload.filename) - + + fn=fileName or splitPath(fileupload.filename) + manage_AddImageDigilib(self,fn,fileupload,meta=meta) - return RESPONSE.redirect(self.REQUEST['URL1']+'/'+fn) + + if RESPONSE: + return RESPONSE.redirect(self.REQUEST['URL1']+'/'+fn) #return self.REQUEST['URL1']+'/'+fileupload.filename def ImportFiles2(self,RESPONSE=None): @@ -633,8 +1165,9 @@ class ImageCollection(Folder, Persistent ret="" #print self.__dict__ for file in files: - if not file[0]==".": - if self.__dict__.has_key(file): + fn=os.path.splitext(file)[0] + if not (file[0]=="."): + if self.__dict__.has_key(file) or self.__dict__.has_key(fn+'.tif') or self.__dict__.has_key(fn+'.tiff') : ret=ret+"
"+file+" already exists!" else: @@ -648,16 +1181,70 @@ class ImageCollection(Folder, Persistent #pt=PageTemplateFile('Products/ImageArchive/out.zpt')).__of__(self) #print self.ImageStoragePath - #scale thumb - + #scale thumb + self.scaleThumbs() - #scale standard + #scale standard - self.scaleWorkingVersions() - + self.scaleWorkingVersions() + RESPONSE.redirect('manage_main') + + ## def importStructure(self,path): +## """import""" +## splitted=os.path.split(path) +## if os.path.isDir(path) and (len(splitted[1])>0) and (splitted[1][0]=="."): +## manage_AddImageCollection(self,splitted[1],splitted[1],path,self.ImageViewerPath,self.defaultMetaString,RESPONSE=None) + +## obj=getattr(self,splitted[1]) +## obj.ImportFiles() + + def ImportStructure(self,RESPONSE=None): + """Import the existing files of a folder""" + files=os.listdir(self.ImageStoragePath) + ret="" + #print self.__dict__ + + + for file in files: + + if os.path.isdir(os.path.join(self.ImageStoragePath,file)): + imageStoragePath=os.path.join(self.ImageStoragePath,file) + imageViewerPath=os.path.join(self.ImageViewerPath,file) + manage_AddImageCollection(self,file,file,imageStoragePath,imageViewerPath,self.defaultMetaString) + + obj=getattr(self,file) + obj.ImportStructure() + else: + if not file[0]==".": + if self.__dict__.has_key(file): + + ret=ret+"
"+file+" already exists!" + else: + ret=ret+"
"+file+" created!" + newObj=ImageDigilib(file,file) + #print newObj,file + #print newObj + try: + self._setObject(file,newObj) + except: + """nothing yet""" + #print ret + #pt=PageTemplateFile('Products/ImageArchive/out.zpt')).__of__(self) + #print self.ImageStoragePath + + #scale thumb + + self.scaleThumbs() + + #scale standard + + self.scaleWorkingVersions() + + if RESPONSE: + RESPONSE.redirect('manage_main') def ImportFiles(self,RESPONSE=None): """Import the existing files of a folder""" @@ -665,10 +1252,12 @@ class ImageCollection(Folder, Persistent ret="" #print self.__dict__ for file in files: - if not file[0]==".": - if self.__dict__.has_key(file): + fn=os.path.splitext(file)[0] + if not (file[0]=="."): + if self.__dict__.has_key(file) or self.__dict__.has_key(fn+'.tif') or self.__dict__.has_key(fn+'.tiff') : ret=ret+"
"+file+" already exists!" + else: ret=ret+"
"+file+" created!" newObj=ImageDigilib(file,file) @@ -682,16 +1271,16 @@ class ImageCollection(Folder, Persistent #pt=PageTemplateFile('Products/ImageArchive/out.zpt')).__of__(self) #print self.ImageStoragePath - #scale thumb - + #scale thumb + self.scaleThumbs() - #scale standard + #scale standard - self.scaleWorkingVersions() - - if RESPONSE: - RESPONSE.redirect('manage_main') + self.scaleWorkingVersions() + + if RESPONSE: + RESPONSE.redirect('manage_main') def ImageCollection_config(self): """Nothing yet""" @@ -701,21 +1290,23 @@ class ImageCollection(Folder, Persistent pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','ChangeImageCollectionForm.zpt')).__of__(self) return pt() - def ChangeImageCollection(self,title,ImageStoragePath,ImageViewerPath,defaultMetaString,RESPONSE=None): + def ChangeImageCollection(self,title,ImageStoragePath,ImageViewerPath,defaultMetaString,serverPath,RESPONSE=None): """Change""" self.title=title self.ImageStoragePath=ImageStoragePath self.ImageViewerPath=ImageViewerPath self.defaultMetaString=defaultMetaString + self.serverPath=serverPath if RESPONSE is not None: RESPONSE.redirect('manage_main') def show_selected_thumbs(self): #ids=[] - - return self.REQUEST.SESSION['filenames'] - + try: + return self.REQUEST.SESSION['filenames'] + except: + return None def show_thumbs(self): ids=[] for entry in self.__dict__: @@ -727,15 +1318,15 @@ class ImageCollection(Folder, Persistent ids.sort() return ids - def firstSets(self,selected=None): + def firstSets(self,selected=None,text='first set'): ids=self.show_thumbs() if ids: if selected: - return "first sets" + return ""+text+"" else: - return "first sets" + return ""+text+"" - def lastSets(self,selected=None): + def lastSets(self,selected=None,text='last set'): ids=self.show_thumbs() if ids: colRows=self.getColTimesRow() @@ -749,39 +1340,39 @@ class ImageCollection(Folder, Persistent nr=0 if selected: - return "last set" + return ""+text+"" else: - return "last sets" + return ""+text+"" - def nextSets(self,selected=None): + def nextSets(self,selected=None,text='next set'): """show nextimage""" ids=self.show_thumbs() colRows=self.getColTimesRow() + pagesize = colRows[0] * colRows[1] if ids: if colRows[1]: - if self.REQUEST.SESSION.has_key("filename"): filename=self.REQUEST.SESSION["filename"] try: - nr=ids.index(filename)+colRows[0]*colRows[1] + nr=ids.index(filename)+pagesize if nr>=len(ids): - nr=len(ids)-1 + return "" except: - nr=0 + nr=pagesize else: - nr=0 + nr = pagesize - if nr==len(ids)-1: + if nr>=len(ids)-1: return "" else: if selected: - return "next set" + return ""+text+"" else: - return "next set" + return ""+text+"" - def prevSets(self,selected=None): + def prevSets(self,selected=None,text='previous sets'): """show nextimage""" #return self.getId() @@ -808,20 +1399,96 @@ class ImageCollection(Folder, Persistent return "" else: if selected: - return "previous sets" + return ""+text+"" else: - return "previous sets" + return ""+text+"" else: return "" + + def showFolders(self): + """show subfolders""" + ret="" + link=""" %s
""" + + if self.aq_parent.meta_type=="ImageCollection": + ret+=link%(self.aq_parent.absolute_url(), "back ("+self.aq_parent.title+")") + ret+="
" + + iCs=self.ZopeFind(self,obj_metatypes=["ImageCollection"]) + if not iCs: + return ret + else: + + link=""" %s
""" + for iC in iCs: + ret+=link%(iC[1].absolute_url(),iC[0]) + ret+="
" + return ret + + + def getSetSelector(self, selected=None): + """returns the HTML select element for the sets""" + actualNr=0 + ids=self.show_thumbs() + colRows=self.getColTimesRow() + pagesize = colRows[0]*colRows[1] + numpages = int(len(ids)/pagesize) + if not ((len(ids) % pagesize)==0): + numpages+=1 + + ret="" + if numpages>1: + if selected: + ret+="""" + + return ret + + def isAllSets(self, showall=None): + """returns if there are any sets""" + ids=self.show_thumbs() + colRows=self.getColTimesRow(showall=showall) + pagesize = colRows[0]*colRows[1] + return (len(ids) <= pagesize) + + + def allSets(self, texton='show all', textoff='show groups'): + """returns HTML to toggle 'show all'""" + if self.isAllSets(showall='No'): + return "" + showall=self.REQUEST.SESSION.get('showall','no') + if showall=='no': + ret=''+texton+'' + else: + ret=''+textoff+'' + return ret + + def showRuler(self,selected=None): """show ruler""" - showall =self.REQUEST.SESSION.get('showall','no') + showall=self.REQUEST.SESSION.get('showall','no') ids=self.show_thumbs() if len(ids)==0: return "No entries" if showall=='no': + actualNr=0 ids=self.show_thumbs() colRows=self.getColTimesRow() num=int(len(ids)/(colRows[0]*colRows[1])) @@ -829,19 +1496,63 @@ class ImageCollection(Folder, Persistent num+=1 a=colRows[0]*colRows[1] #print num,num+1 + if num>1: - ret="Show thumbnail group no:
" + ret="" + if selected: + ret+="""" + anf="Show thumbnail group no:
" + + + try: + if selected: + href=self.REQUEST['URL1']+"/selection?filename="+ids[(actualNr-1)*a] + else: + href=self.REQUEST['URL1']+"?filename="+ids[int((actualNr-1)*a)] + + anf+="""%s  """%(href,"prev") + except: + pass + ret=anf+ret + + try: + + if selected: + href=self.REQUEST['URL1']+"/selection?filename="+ids[(actualNr+1)*a] + else: + href=self.REQUEST['URL1']+"?filename="+ids[int((actualNr+1)*a)] + + end="""%s  """%(href,"next") + except: + end="" + ret=ret+end + - ret+="""%i  """%(href,i) + #for i in range(num): + # + # ret +="
" #alle 10 linebreak einfuegen + # k=i*a + # if selected: + # href=self.REQUEST['URL1']+"/selection?filename="+ids[k] + # else: + # href=self.REQUEST['URL1']+"?filename="+ids[int(k)] + # + # ret+="""%i  """%(href,i) else: ret="" @@ -850,10 +1561,14 @@ class ImageCollection(Folder, Persistent ret="""show groups """%self.REQUEST['URL1'] return ret + def show_thumbs_selected_rows(self,numberOfColumns): """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) @@ -883,48 +1598,54 @@ class ImageCollection(Folder, Persistent RESPONSE.setCookie("ImageViewerCols",cols) RESPONSE.redirect(self.REQUEST['URL1']+"/setDone") - + + def setDefaultColTimesRow(self, cols, rows): + """sets default columns and rows""" + self.defaultcols = cols + self.defaultrows = rows + def getColTimesRow(self,showall='No'): """coltimesrow""" REQUEST=self.REQUEST """matrix""" if REQUEST.cookies.has_key("ImageViewerRows"): - try: rows=int(REQUEST.cookies["ImageViewerRows"]) except: - rows=6 + rows=getattr(self,'defaultrows',6) else: - rows=6 + rows=getattr(self,'defaultrows',6) if REQUEST.cookies.has_key("ImageViewerCols"): #print "COLS",REQUEST.cookies["ImageViewerCols"] cols=int(REQUEST.cookies["ImageViewerCols"]) else: - cols=2 + cols=getattr(self,'defaultcols',3) + idsnumber=len(self.show_thumbs()) if rows: if cols*rows >idsnumber: rows=int(idsnumber/cols)+1 - #print cols,rows + if showall is None: + showall=self.REQUEST.SESSION.get('showall', 'No') if showall=='yes': rows=int(idsnumber/cols)+1 return (cols,rows) - def show_thumbs_rows(self,numberOfColumns,numberOfRows=None,startId=None): + def show_thumbs_rows(self,numberOfColumns,numberOfRows=None,startId=None,showall="No"): """Ausgabe anzahl""" idsAll=self.show_thumbs() - if len(idsAll)==0: #keine Einträge + if len(idsAll)==0: #keine Eintraege return 0 - if self.REQUEST.SESSION.has_key("filename"): + if self.REQUEST.SESSION.has_key("filename") and not (showall=="yes"): filename=self.REQUEST.SESSION["filename"] - + filename=self.getImageByName(filename,onlyName="yes") try: startId=filename @@ -997,7 +1718,8 @@ class ImageCollection(Folder, Persistent """navigation""" #self.REQUEST.SESSION['URL']=self.REQUEST['URL0'] pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','navigation_selected.zpt')).__of__(self) - return pt() + + return pt().data def navig_html(self): """navigation""" @@ -1016,9 +1738,69 @@ class ImageCollection(Folder, Persistent self.REQUEST.SESSION['filename']=filen pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','overview_selected2.zpt')).__of__(self) return pt() + + def getImageByName(self,filename,onlyName=None): + """get filename""" + #print repr(filename) + #FIXME: umlaute in filename + fn=getattr(self,repr(filename),None) + if not fn: + filenameM=filename.split(".")[0] + + founds=self.ZopeFind(self,obj_metatypes=['ImageDigilib']) + + + for found in founds: + foundM=found[0].split(".")[0] + + if filenameM.lower()==foundM.lower(): + if onlyName: + return found[0] + else: + return found[1] + #HACK teste noch ob am ende des filenames eventuell ein "_" und loesche das. + if foundM[-1]=="_": + foundM=foundM[0:-1] + + if filenameM.lower()==foundM.lower(): + if onlyName: + return found[0] + else: + return found[1] + + if onlyName: + return filename + else: + return fn - def index_html(self): + + security.declareProtected('View','index_html') + def index_html(self,fn=None,generic='No'): """main template collection""" + + if fn: + ret=[] + + if type(fn) is ListType: + """experimentell mehr als ein filename""" + for filename in fn: + if not (filename == ""): + ret.append((filename,'',1)) + else: + ret.append((fn,'',1)) + + self.REQUEST.SESSION['filenames']=ret + #self.REQUEST.SESSION['filenamesIds']=fnIds + + overview=self.ZopeFind(self,obj_ids=['overview_selected.html']) + + + if overview and (generic =='No'): + return overview[0][1]() + else: + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','overview_selected.zpt')).__of__(self) + return pt() + if self.REQUEST.has_key('filename'): filen=self.REQUEST['filename'] else: @@ -1032,9 +1814,22 @@ class ImageCollection(Folder, Persistent else: self.REQUEST.SESSION['showall']=self.REQUEST.SESSION.get('showall','no') - - pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','overview.zpt')).__of__(self) - return pt() + + overview=self.ZopeFind(self,obj_ids=['overview.html']) + if overview and (generic == 'No'): + return overview[0][1]() + elif hasattr(self,'templates'): + pt=self.templates.imgcoll_main.__of__(self) + return pt() + else: + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','overview.zpt')).__of__(self) + return pt() + + def navigation(self): + """generate navigation bar""" + + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','navigation_fragment')).__of__(self) + return pt() def manage_AddImageCollectionForm(self): """Nothing yet""" @@ -1050,6 +1845,450 @@ def manage_AddImageCollection(self,id,ti RESPONSE.redirect('manage_main') + +class ImageCollectionMD(ImageCollection,ZSQLExtendFolder): + """Imageviewer and Metadata""" + meta_type="ImageCollection MD" + #scalerPath="http://127.0.0.1:18080/digitallibrary/servlet/Scaler/?fn=" + scalerPath="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?fn=" + rightsQueryDefault="SELECT accessibility from vision_main where id_image=(SELECT id from vision_images where filename ~ '%s*' )" + rightsQueryFieldDefault="accessibility" + + manage_options=ImageCollection.manage_options+( + {'label':'ZSQLExtend','action':'changeZSQLExtendForm'}, + {'label':'Change Rights Query','action':'changeRightsQueryForm'}, + ) + + try: + changeZSQLExtendForm=ZSQLExtendFolder.changeZSQLExtendForm + except: + pass + + + def ImportFiles(self,RESPONSE=None): + """Import the existing files of a folder""" + files=os.listdir(self.ImageStoragePath) + ret="" + #print self.__dict__ + for file in files: + + if not (file[0]=="."): + fn=os.path.splitext(file)[0] + if self.__dict__.has_key(file) or self.__dict__.has_key(fn+'.tif') or self.__dict__.has_key(fn+'.tiff') : + + ret=ret+"
"+file+" already exists!" + + else: + ret=ret+"
"+file+" created!" + newObj=ImageDigilib(file,file) + #print newObj,file + #print newObj + try: + self._setObject(file,newObj) + except: + """nothing yet""" + + + args={} + args['_table']=self.imageCollectionConfig.getTable() + args[self.imageCollectionConfig.getKey()]=file + + if not self.ZSQLInlineSearch(args=args): + self.ZSQLAdd(args=args) + #print ret + #pt=PageTemplateFile('Products/ImageArchive/out.zpt')).__of__(self) + #print self.ImageStoragePath + + #scale thumb + + + self.scaleThumbs() + + #scale standard + + self.scaleWorkingVersions() + + self.scaleToJpgs() + + if RESPONSE: + RESPONSE.redirect('manage_main') + + def addImage(self): + """Add an Image""" + + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addImageMD.zpt')).__of__(self) + return pt() + + def addImage2(self,_fileupload,_fileName=None,_meta=None,_use_default=None,RESPONSE=None): + """Add""" + + filenameKey="filename" + #print "FU",fileupload + + if _use_default: + try: + meta=self.meta_default(_fileupload.filename) + except: + meta=None + else: + meta=None + + fn=_fileName or splitPath(_fileupload.filename) + + manage_AddImageDigilib(self,fn,_fileupload,meta=meta) + + args=self.REQUEST.form + args[filenameKey]=fn + + self.ZSQLAdd(args=args) + + self.scaleThumbs() + self.scaleWorkingVersions() + + getattr(self,fn).scaleToJpg() + if RESPONSE: + return RESPONSE.redirect(self.REQUEST['URL1']+'/'+fn) + #return self.REQUEST['URL1']+'/'+fileupload.filename + + def navig_html(self): + """navigation""" + #self.REQUEST.SESSION['URL']=self.REQUEST['URL0'] + + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','navigationMD.zpt')).__of__(self) + return pt() + + def navig_selected_html(self): + """navigation""" + #self.REQUEST.SESSION['URL']=self.REQUEST['URL0'] + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','navigation_selectedMD.zpt')).__of__(self) + + return pt() + + def decode(self,str): + """decoder""" + if not str: + return "" + if type(str) is StringType: + try: + return str.decode('utf-8') + except: + return str.decode('latin-1') + else: + + return str + + def standardSearch(self): + """standard search page""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','standardSearchPage.zpt')).__of__(self) + return pt() + + def searchResultXML(self): + """xmlformat""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','searchResultXML.zpt')).__of__(self) + return pt() + + def searchDB(self,REQUEST=None,RESPONSE=None,xml=None): + """search""" + + rc=[] + fnIds={} + for found in self.ZSQLInlineSearch(args=self.REQUEST.form): + key=getattr(found,self.imageCollectionConfig.getKey()) + key=self.getImageByName(key,onlyName="yes") + rc.append((key,'',0)) + fnIds[key]=('',0) + + rc.sort() + self.REQUEST.SESSION['filenames']=rc + self.REQUEST.SESSION['filenamesIds']=fnIds + + overview=self.ZopeFind(self,obj_ids=['overview_selectedMD.html']) + + if overview: + return overview[0][1]() + else: + 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() + + #urlTmp=REQUEST['URL1'] + + #url=urlTmp+'/searchResultXML?-table=%s&'%self.imageCollectionConfig.getTable()+REQUEST['QUERY_STRING'] + + #if xml is None: + # RESPONSE.redirect('xmlinput?url='+urllib.quote(url)) + #else: + # RESPONSE.redirect(url) + + def index_html(self,fn=None,selection=None,generic='No',REQUEST=None,RESPONSE=None): + """main template collection""" + + + mode=self.REQUEST.get('mode','view') + if fn: + ret=[] + + if type(fn) is ListType: + """experimentell mehr als ein filename""" + for filename in fn: + if not (filename == ""): + ret.append((filename,'',1)) + else: + ret.append((fn,'',1)) + + self.REQUEST.SESSION['filenames']=ret + #self.REQUEST.SESSION['filenamesIds']=fnIds + + overview=self.ZopeFind(self,obj_ids=['overview_selected.html']) + + + if overview and (generic =='No'): + return overview[0][1]() + else: + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','overview_selectedMD.zpt')).__of__(self) + return pt() + + + # filename given, then only display this file + if self.REQUEST.has_key('filename'): + + filen=self.REQUEST['filename'] + else: + filen="" + + + self.REQUEST.SESSION['filename']=filen[0:] + +# if not self.REQUEST.SESSION['filename']=="": +# url=getattr(self.getImageByName(self.REQUEST.SESSION['filename']),'absolute_url')() +# if mode=="view": +# self.REQUEST.RESPONSE.redirect(url) +# elif mode=="download": +# self.REQUEST.RESPONSE.redirect(url+"/download") +# + if self.REQUEST.has_key('showall'): + + self.REQUEST.SESSION['showall']=self.REQUEST.get('showall') + else: + self.REQUEST.SESSION['showall']=self.REQUEST.SESSION.get('showall','no') + + + if selection: + #selection i.e. selection already stored at self.REQUEST.SESSION['filenames'] + overview=self.ZopeFind(self,obj_ids=['overview_selected.html']) + + + if overview and (generic =='No'):# + + return overview[0][1]() + else: + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','overview_selectedMD.zpt')).__of__(self) + return pt() + + + #no filename then show overview + + overview=self.ZopeFind(self,obj_ids=['overview.html']) + if overview and (generic == 'No'): + + + return overview[0][1]() + elif hasattr(self,'templates'): + + pt=self.templates.imgcoll_mainMD.__of__(self) + return pt() + else: + + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','overviewMD.zpt')).__of__(self) + return pt() + + def nextImage(self,request,selected=None,returnFn=None): + """show nextimage""" + + if not selected and self.REQUEST.has_key('fn'): + imagename=self.REQUEST['fn'].split('/')[-1] + + imagename=self.getImageByName(imagename,onlyName=True) + + nr=self.getObjectPosition(imagename) + + objects=self.objectIds() + if len(objects)==nr+1: + return "" + else: + fn="/".join(self.REQUEST['fn'].split('/')[0:-1])+"/"+objects[nr+1] + return "next image" + + def prevImage(self,request,selected=None,returnFn=None): + """show nextimage""" + + if not selected and self.REQUEST.has_key('fn'): + imagename=self.REQUEST['fn'].split('/')[-1] + + imagename=self.getImageByName(imagename,onlyName=True) + + nr=self.getObjectPosition(imagename) + + objects=self.objectIds() + if nr==0: + return "" + else: + fn="/".join(self.REQUEST['fn'].split('/')[0:-1])+"/"+objects[nr-1] + return "prev image" + + + def changeRightsQueryForm(self): + """change Rights Query""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','ChangeRightsQueryForm.zpt')).__of__(self) + return pt() + + def changeRightsQuery(self,rightsQuery,rightsQueryField,RESPONSE=None): + """change Rightsquery""" + + self.rightsQuery=rightsQuery + self.rightsQueryField=rightsQueryField + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + + + def getRightsQuery(self): + """get Query""" + return getattr(self,'rightsQuery',self.rightsQueryDefault) + + def getRightsQueryField(self): + """get Query Fiueld""" + return getattr(self,'rightsQueryField',self.rightsQueryFieldDefault) + + + + def setGenericSearchStringForm(self): + """form setze generischen search string fuer MD""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','setGenericSearchStringForm.zpt')).__of__(self) + return pt() + + def setGenericSearchString(self,searchString): + """setze generischen search string""" + self.searchString=searchString + + def thumblistMD(self): + """main template collection""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','thumbListMD.zpt')).__of__(self) + return pt() + + def getRights(self,id): + """get the rights from a database""" + #print self.rightsQuery%id + results=self.ZSQLSimpleSearch(self.getRightsQuery()%id) + if results: + result = getattr(results[0],self.getRightsQueryField()) + else: + result = '' + return result + + def xmlinput(self,url): + """Anzeige von ausgewaehlten thumbs""" + #return url + + url=urllib.unquote(url) + xmldoc=urllib.urlopen(url).read() + #return xmldoc + try: + dom=NonvalidatingReader.parseUri(url) + + except: + return "ERROR: (%s %s) %s"%(sys.exc_info()[0],sys.exc_info()[1],xmldoc) + + + imagenames=dom.xpath("//imagename") + rc=[] + fnIds={} + for imagename in imagenames: + + #imagename=image.xpath('./imagename')[0] + #print "im",imagename + + + + idnr=imagename.xpath('../idnr')[0] + id=getText(idnr.childNodes) + try: + numberOfPages=imagename.xpath('../numberOfPages')[0] + except: + numberOfPages=None + + if numberOfPages: + nopT=getText(numberOfPages.childNodes) + try: + nop=int(nopT) + except: + nop=0 + else: + nop=0 + + texts=getText(imagename.childNodes).split("\n") #mehrere bilder in return getrennter liste + for text in texts: + if not text=="": + #print "a" + text=self.getImageByName(text,onlyName="yes") + #print "b" + try: + rc.append((str(text),id,nop)) + fnIds[str(text)]=(id,nop) + except: + rc.append((repr(text),id,nop)) + fnIds[repr(text)]=(id,nop) + + #print "done" + rc.sort() + self.REQUEST.SESSION['filenames']=rc + self.REQUEST.SESSION['filenamesIds']=fnIds + + overview=self.ZopeFind(self,obj_ids=['overview_selectedMD.html']) + + if overview: + return overview[0][1]() + else: + 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'): + filen=self.REQUEST['filename'] + else: + filen="" + self.REQUEST.SESSION['filename']=filen + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','overview_selectedMD.zpt')).__of__(self) + return pt() + + def thumblistSelectedMD(self): + """main template collection""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','thumbselectedMD.zpt')).__of__(self) + return pt() + +def manage_AddImageCollectionMDForm(self): + """Nothing yet""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','AddImageCollectionFormMD.zpt')).__of__(self) + return pt() + +def manage_AddImageCollectionMD(self,id,title,ImageStoragePath,ImageViewerPath,defaultMetaString,RESPONSE=None): + """Add ImageCollection""" + newObj=ImageCollectionMD(id,title,ImageStoragePath,ImageViewerPath,defaultMetaString) + self._setObject(id,newObj) + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + + + class ImageCollectionIFrame(ImageCollection): """Class fuer Collection set als IFrame""" @@ -1061,10 +2300,10 @@ class ImageCollectionIFrame(ImageCollect return "" def rotate(self,angle,url,RESPONSE): - """rotate""" - - RESPONSE.redirect("javascript:document.domain='mpg.de';parent.iframe.right.rotation(%i)"%int(angle)) - RESPONSE.redirect(url) + """rotate""" + + RESPONSE.redirect("javascript:document.domain='mpg.de';parent.iframe.right.rotation(%i)"%int(angle)) + RESPONSE.redirect(url) def request(self): """request""" return self.REQUEST @@ -1106,3 +2345,85 @@ def manage_AddImageCollectionIFrame(self RESPONSE.redirect('manage_main') +class ImageZogiLib(ImageDigilib): + """Anzeige Object fuer Bilder ausserhalb von collections + ImageViewerPath und ImageStoragePath und wenn vorhanden Pfad zur Collection + werden zusaetzlich abgespeichert + """ + #TODO: scaler path notwendig? + meta_type="ImageZogiLib" + + manage_options=ImageDigilib.manage_options+( + {'label':'Main Config','action':'changeImageZogiLibForm'}, + ) + + def __init__(self,id,fn,ImageViewerPath,ImageStoragePath,scalerPath,ImageCollectionPath=None,REQUEST=None): + ImageDigilib.__init__(self,id,fn) + self.ImageViewerPath=ImageViewerPath + self.ImageStoragePath=ImageStoragePath + self.ImageCollectionPath=ImageCollectionPath + self.scalerPath=scalerPath + + def changeImageZogiLibForm(self): + """change zogilib Form""" + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeImageZogiLib.zpt')).__of__(self) + return pt() + + + def changeImageZogilib(fn,ImageViewerPath,ImageStoragePath,scalerPath,ImageCollectionPath,REQUEST=None): + """Change it""" + self.ImageViewerPath=ImageViewerPath + self.ImageStoragePath=ImageStoragePath + self.ImageCollectionPath=ImageColectionPath + self.scalerPath=scalerPath + +def manage_AddImageZogiLib(self,id=None,ImageViewerPath=None,ImageStoragePath=None,fileUpload=None,ImageCollectionPath=None,scalerPath=None,libPath=None,caption=None,RESPONSE=None): + """hinzufuegen eineis zogilibImage""" + + if libPath: + splitted=libPath.split("?") + urlSplit=splitted[0].split("/") + params=cgi.parse_qs(splitted[1]) + #is LibPath a digilib path? + if urlSplit[-1]=="Scaler": + if type(params['fn']) is ListType: + fnParam=params['fn'][0] + else: + fnParam=params['fn'] + fileNameSplit=os.path.split(fnParam) + ImageViewerPath=fileNameSplit[0] + id=fileNameSplit[1] + scalerPath=splitted[0]+"?fn=" + else: #assume if not the path is a path to an ImageCollection + if type(params['filename']) is ListType: + id=params['filename'][0] + else: + id=params['filename'] + + server=ServerProxy(splitted[0]) + ImageCollectionPath=libPath + ImageViewerPath=server.getImageViewerPath() + ImageStoragePath=server.getImageStoragePath() + scalerPath=server.getScalerPath() + + + + if fileUpload: + fn=splitPath(fileUpload.filename) + else: + fn=id + + newObj=ImageZogiLib(id,fn,ImageViewerPath,ImageStoragePath,scalerPath,ImageCollectionPath) + + self._setObject(id,newObj) + getattr(self,id).caption=caption[0:] + if fileUpload: + getattr(self,id).uploadImage(fileupload,self.ImageStoragePath) + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + +def manage_AddImageZogiLibForm(self): + """to be done""" + \ No newline at end of file