--- ImageArchive/ImageArchive.py 2004/11/24 17:03:23 1.40 +++ ImageArchive/ImageArchive.py 2006/02/07 20:29:31 1.75 @@ -1,9 +1,14 @@ +genericServerPath="http://www.mpiwg-berlin.mpg.de/zogilib_images" #can be changed with main config + + + from OFS.Folder import Folder 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 @@ -12,6 +17,24 @@ import xml.dom.minidom import operator import tempfile import shutil +from types import * +import time +from threading import Thread +import Queue +import cgi +import zLOG + +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: @@ -20,27 +43,236 @@ except: print "ECHO Elements not imported" class ECHO_basis: """leer""" + manage_options=() +tdir = "/mpiwg/temp/tmp/archivesImageServer/" +#tdir="/tmp/archivesImageServer/" + 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="
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+="
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+="""
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+( @@ -49,6 +281,31 @@ 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 '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) @@ -78,128 +335,265 @@ 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,0644) + os.chmod(filename,0664) except: """hack""" - #scale thumb - + #scale 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() + """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) + + #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() + + + if RESPONSE: + RESPONSE.redirect(self.aq_parent.absolute_url()+"?filename="+self.filename) + + + def updateImage(self,file,rename=None,RESPONSE=None): + """lade neues Version des Bildes""" + #teste ob Dokumenten ordner schon vorhanden + #imagePath=os.path.join(self.ImageStoragePath,self.getId()) + 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: - os.chmod(imagePath,0664) + #zLOG.LOG("ImageArchive:updateImage", zLOG.INFO, "rename: %s -> %s"%(imagePath,imageNewPath)) + os.rename(imagePath,imageNewPath) 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) + zLOG.LOG("ImageArchive:updateImage", zLOG.ERROR, "rename: %s -> %s didn't work!"%(imagePath,imageNewPath)) + + #lesen des upload files und schreiben + filedata=file.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: + """hack""" + #scale thumb + + self.scaleThumbs() - #DEVEL:take nausikaa for server solution + #scale standard + + self.scaleWorkingVersions() + + if rename: + self.renameImage(file.filename) + - 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 + 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']="%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 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()
- nr=ids.index(id[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("
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("""
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 scaleThumbs(self,RESPONSE=None):
"""scale thumbs"""
-
- #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")
-
+ if RESPONSE:
+ RESPONSE.write(ret.read())
+ RESPONSE.write("\n")
+
return "RESCALING STARTED"
def scaleWorkingVersions(self,RESPONSE=None):
"""scale working versions"""
-
- #scale standard
+
+ #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"
+ 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
- if ECHO_basis:
- optTMP= Folder.manage_options+ECHO_basis.manage_options
- else:
- optTMP= Folder.manage_options
+ 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"""
+
+ for image in self.ZopeFind(self,obj_metatypes=["ImageDigilib"]):
+
+ image[1].manageMetaData(strict)
+ return "ok"
- def importMetaForm(self):
+
+ 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)
@@ -476,18 +847,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:
@@ -521,7 +892,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):
@@ -543,46 +914,62 @@ 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 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)
+ 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__:
@@ -595,11 +982,13 @@ 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
if use_default:
@@ -609,10 +998,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):
@@ -636,16 +1028,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"""
@@ -670,16 +1116,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"""
@@ -689,21 +1135,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__:
@@ -715,15 +1163,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()
@@ -737,39 +1185,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()
@@ -796,20 +1244,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+="""