|
|
| version 1.7, 2005/01/21 14:03:24 | version 1.21, 2005/11/25 17:49:53 |
|---|---|
| Line 9 from OFS.Folder import Folder | Line 9 from OFS.Folder import Folder |
| from OFS.SimpleItem import SimpleItem | from OFS.SimpleItem import SimpleItem |
| from Globals import InitializeClass,package_home | from Globals import InitializeClass,package_home |
| import zLOG | import zLOG |
| import base64 | |
| import bz2 | |
| import os | import os |
| import os.path | import os.path |
| import stat | import stat |
| import Ft.Xml.XPath | |
| import xml.dom.minidom | import xml.dom.minidom |
| from types import * | from types import * |
| import xmlrpclib | |
| from OSAS_helpers import * | |
| def decodeRPC(string): | |
| return bz2.decompress(base64.decodestring(string)) | |
| class OSAS_storeOnline(SimpleItem): | class OSAS_storeOnline(SimpleItem): |
| """Webfrontend für das Storagesystem | """Webfrontend für das Storagesystem |
| Line 26 class OSAS_storeOnline(SimpleItem): | Line 35 class OSAS_storeOnline(SimpleItem): |
| _v_fileSystem={} #chache fuer filesystem | _v_fileSystem={} #chache fuer filesystem |
| _v_metaFiles={} #chache fuer indexMeta | _v_metaFiles={} #chache fuer indexMeta |
| def __init__(self,id): | def getParentType(self,path): |
| """initialize a new instance | """getFileType des parentordners""" |
| @param id: Zope id""" | |
| self.id = id | |
| realPath=os.path.split(path)[0] | |
| objects=self.readObjectsFromPath(realPath) | |
| security.declareProtected('View','index_html') | try: |
| def index_html(self): | return objects[os.path.join(realPath,".")][0] |
| """main view either standard template zpt/storeOnline_index_html.zpt or storeOnline_index.html in tree""" | except: |
| if hasattr(self,'storeOnline_index.html'): | return "" |
| return getattr(self,'storeOnline_index.html')() | def getHandlersOfPath(self): |
| else: | """handler des actullen path""" |
| pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','storeOnline_index_html.zpt')).__of__(self) | path=self.REQUEST['path'] |
| return pt() | objects=self.readObjectsFromPath(path) |
| typeObject=objects.get(os.path.join(path,"."),None) | |
| if not typeObject: | |
| return("",[],"") | |
| type=typeObject[0] | |
| def findIndexMeta(self,path=""): | handler=self.giveHandlers(path,type) |
| """finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file | |
| @keyword path: default ist "", Pfad auf das Object relativ zum rootFolderName | |
| @return: None falls kein index.meta existiert sonst Pfad auf das index.meta | return (os.path.split(path)[1],handler,objects[os.path.join(path,".")][1],type) |
| def getMetaFile(self,path): | |
| """get index.meta and translate it to HTML""" | |
| """Lies Metafile ein | |
| @param path: Pfad des index.met | |
| @return: index.meta file | |
| """ | """ |
| realPath=os.path.normpath(os.path.join(self.rootFolderName,path)) | html=[] |
| #suche index.meta | server=xmlrpclib.Server(self.serverUrl) |
| while (not os.path.exists(os.path.join(realPath,'index.meta'))) and (not ((realPath=="") or (realPath=="/"))): | |
| realPath=os.path.split(realPath)[0] | |
| if realPath=='' or realPath=='/': | f=server.getFile(path+"/index.meta") |
| if os.path.exists(os.path.join(realPath,'index.meta')): | |
| return os.path.join(realPath,'index.meta') | if not f: |
| return self.getMetaInfoFromIndexMeta(path) | |
| #return "NO_METADATA" | |
| else: | else: |
| return None | |
| dom = xml.dom.minidom.parseString(f) | |
| try: | |
| name=getText(dom.getElementsByTagName("name")[0].childNodes) | |
| except: | |
| name="NOT_DEFINED!!!" | |
| try: | |
| creator=getText(dom.getElementsByTagName("creator")[0].childNodes) | |
| except: | |
| creator="NOT_DEFINED!!!" | |
| try: | |
| creation_date=getText(dom.getElementsByTagName("archive-creation-date")[0].childNodes) | |
| except: | |
| creation_date="NOT_DEFINED!!!" | |
| try: | |
| description=getText(dom.getElementsByTagName("description")[0].childNodes) | |
| except: | |
| description="NOT_DEFINED!!!" | |
| try: | |
| type=getText(dom.getElementsByTagName("content-type")[0].childNodes) | |
| except: | |
| type="" | |
| if type=="scanned document": | |
| html="<h3>Document: "+name+"</h3>" | |
| elif type=="folder": | |
| html="<h3>Folder: "+name+"</h3>" | |
| else: | |
| html="<h3>Document: "+name+"</h3>" | |
| html=html+"<p><i>created by: "+creator+" at: "+creation_date+"</i></p>" | |
| html=html+"<h4>Description</h4><p>"+description+"</p>" | |
| try: | |
| bib = dom.getElementsByTagName("meta")[0].getElementsByTagName("bib")[0] | |
| if bib.attributes.has_key('type'): | |
| html=html+"<h4>Info ("+bib.attributes['type'].value+")</h4>" | |
| else: | |
| html=html+"<h4>Info</h4>" | |
| html=html+getBib(bib.childNodes) | |
| except: | |
| """none""" | |
| # html=html.encode('utf-8','replace')+getBib(bib.childNodes).encode('utf-8','replace') | |
| return html | |
| def getMetaInfoFromIndexMeta(self,path): | |
| """metadaten zu path als html aus dem index.meta file zu path (meta tag im file bzw. dir container) | |
| @param path: Pfad auf das Object relativ zum rootFolderName | |
| @return: metadata als html | |
| """ | |
| xmlInfos=self.findEntryInIndexMeta(path) | |
| if xmlInfos: | |
| return OSAS_helpers.getMetaInfoFromXML(path,xmlInfos) | |
| else: | else: |
| return os.path.join(realPath,'index.meta') | return "" |
| def findEntryInIndexMeta(self,path): | def findEntryInIndexMeta(self,path): |
| """Finde im naechstgelegenden index.meta relativ zu path den entprechenden Eintrag fuer diesen Pfad. | """Finde im naechstgelegenden index.meta relativ zu path den entprechenden Eintrag fuer diesen Pfad. |
| Line 67 class OSAS_storeOnline(SimpleItem): | Line 149 class OSAS_storeOnline(SimpleItem): |
| @return: den Teil von Index.meta der Informationen zu path enthaelt, None wenn error. | @return: den Teil von Index.meta der Informationen zu path enthaelt, None wenn error. |
| """ | """ |
| indexMeta=self.findIndexMeta(path) # suche index.meta | server=xmlrpclib.Server(self.serverUrl) |
| indexMeta=server.findIndexMeta(path) # suche index.meta | |
| if not indexMeta: | if not indexMeta: |
| return None | return None |
| realPath=os.path.split(indexMeta)[0] | realPath=os.path.split(indexMeta)[0] |
| path=os.path.normpath(os.path.join(self.rootFolderName,path)) | path=os.path.normpath(path) |
| try: | try: |
| dom=xml.dom.minidom.parse(indexMeta) | dom = NonvalidatingReader.parseString(server.getFile(indexMeta),"http://www.mpiwg-berlin.mpg.de/") |
| except: | except: |
| zLOG.LOG("OSAS_browser (findEntryInIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta) | zLOG.LOG("OSAS_browser (findEntryInIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta) |
| #ist path ein directory? | return None |
| dirs=dom.getElementsByTagName('dir') | |
| for dir in dirs: | path=path.replace(realPath,'') |
| pathes=dir.getElementsByTagName('path') | (searchPath,name)=os.path.split(path) |
| if pathes: | if (len(searchPath)>0) and (searchPath[0]=="/"): |
| pathX=OSAS_helpers.getText(pathes[0].childNodes) | if len(searchPath)<=1: |
| else: | searchPath="" |
| pathX="" | |
| names=dir.getElementsByTagName('name') | |
| if names: | |
| name=OSAS_helpers.getText(names[0].childNodes) | |
| else: | else: |
| name="" | searchPath=searchPath[1:] |
| #ist path ein directory? | |
| xpath="/resource/dir[name='%s' and path='%s']"%(name,searchPath) | |
| dirs=Ft.Xml.XPath.Evaluate(xpath,contextNode=dom) | |
| checkpath=os.path.normpath(os.path.join(realPath,pathX,name)) | |
| if checkpath==path: | |
| return dir.toxml() | if len(dirs)>0: |
| return dirs[0].toxml | |
| #ist path ein file? | #ist path ein file? |
| files=dom.getElementsByTagName('file') | xpath="/resource/file[name='%s' and path='%s']"%(name,searchPath) |
| for dir in dirs: | |
| pathes=dir.getElementsByTagName('path') | |
| if pathes: | |
| pathX=OSAS_helpers.getText(pathes[0].childNodes) | |
| else: | |
| pathX="" | |
| names=dir.getElementsByTagName('name') | |
| if names: | |
| name=OSAS_helpers.getText(names[0].childNodes) | |
| else: | |
| name="" | |
| checkpath=os.path.normpath(os.path.join(realPath,pathX,name)) | |
| if checkpath==path: | |
| return dir.toxml() | |
| dirs=Ft.Xml.XPath.Evaluate(xpath,contextNode=dom) | |
| if len(dirs)>0: | |
| return dirs[0].toxml() | |
| return None | return None |
| def getSubDirsFromIndexMeta(self,path): | def getSubDirsFromIndexMeta(self,path): |
| """Gebe alle path untergeordenten Objekte aus | """Gebe alle path untergeordenten Objekte aus |
| Line 128 class OSAS_storeOnline(SimpleItem): | Line 199 class OSAS_storeOnline(SimpleItem): |
| @todo: Rueckgabe einer Beschreibung gemaess Metadaten | @todo: Rueckgabe einer Beschreibung gemaess Metadaten |
| """ | """ |
| ret={} | ret={} |
| indexMeta=self.findIndexMeta(path)#findex index.meta zu path. | startPath=path |
| server=xmlrpclib.Server(self.serverUrl) | |
| indexMeta,stats=server.findIndexMetaWithStats(path)#findex index.meta zu path. | |
| if not indexMeta: | if not indexMeta: |
| return ret | return ret |
| Line 140 class OSAS_storeOnline(SimpleItem): | Line 213 class OSAS_storeOnline(SimpleItem): |
| #teste ob schon im cache | #teste ob schon im cache zur Zeit kein chache wenn index.meta file nicht im selben ordner wie path. |
| stats=os.stat(indexMeta) | |
| if self._v_metaFiles.has_key(path) and (self._v_metaFiles[path][0]==stats[stat.ST_MTIME]): | #if self._v_metaFiles.has_key(startPath) and (self._v_metaFiles[realPath][0]==stats[stat.ST_MTIME]) and (path==""): |
| return self._v_metaFiles[path][1] | # |
| # return self._v_metaFiles[startPath][1] | |
| try: | try: |
| dom=xml.dom.minidom.parse(indexMeta) | dom=xml.dom.minidom.parseString(server.getFile(indexMeta)) |
| except: | except: |
| zLOG.LOG("OSAS_browser (getSubDirsFromIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta) | zLOG.LOG("OSAS_browser (getSubDirsFromIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta) |
| return ret | |
| dirs=[] | dirs=[] |
| dirs=dom.getElementsByTagName('dir')+dom.getElementsByTagName('file') | dirs=dom.getElementsByTagName('dir')+dom.getElementsByTagName('file') |
| Line 174 class OSAS_storeOnline(SimpleItem): | Line 248 class OSAS_storeOnline(SimpleItem): |
| fileType="OSAS_file_archive" | fileType="OSAS_file_archive" |
| object=os.path.join(realPath,pathX,name) | object=os.path.join(realPath,pathX,name) |
| ret[object]=(fileType,'') | ret[object.encode('utf-8')]=(fileType,'') |
| self._v_metaFiles[startPath]=(stats[stat.ST_MTIME],ret) # speicher im chache | |
| self._v_metaFiles[path]=(stats[stat.ST_MTIME],ret) # speicher im chache | |
| return ret | return ret |
| def getMetaInfoFromIndexMeta(self,path): | |
| """metadaten zu path als html aus dem index.meta file zu path (meta tag im file bzw. dir container) | def __init__(self,id,serverUrl): |
| @param path: Pfad auf das Object relativ zum rootFolderName | """initialize a new instance |
| @return: metadata als html | @param id: Zope id""" |
| """ | self.id = id |
| xmlInfos=self.findEntryInIndexMeta(path) | self.serverUrl = serverUrl |
| if xmlInfos: | |
| return OSAS_helpers.getMetaInfoFromXML(path,xmlInfos) | |
| security.declareProtected('View','index_html') | |
| def index_html(self): | |
| """main view either standard template zpt/storeOnline_index_html.zpt or storeOnline_index.html in tree""" | |
| if hasattr(self,'storeOnline_index.html'): | |
| return getattr(self,'storeOnline_index.html')() | |
| else: | else: |
| return "" | pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','storeOnline_index_html.zpt')).__of__(self) |
| return pt() | |
| def findIndexMeta(self,path=""): | |
| """finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file | |
| @keyword path: default ist "", Pfad auf das Object relativ zum rootFolderName | |
| @return: None falls kein index.meta existiert sonst Pfad auf das index.meta | |
| """ | |
| realPath=os.path.normpath(os.path.join(self.rootFolderName,path)) | |
| #suche index.meta | |
| server=xmlrpclib.Server(self.serverUrl) | |
| return server.findIndexMeta(realPath) | |
| def readObjectsFromPath(self,path="",metaDataId=None): | def readObjectsFromPath(self,path="",metaDataId=None): |
| Line 199 class OSAS_storeOnline(SimpleItem): | Line 292 class OSAS_storeOnline(SimpleItem): |
| @keyword metaDataId: Optional, id des OSAS_Metadata Object, dass benutzt werden soll, generisch wird das erste Object, dass in parent gefunden wird angezeigt. | @keyword metaDataId: Optional, id des OSAS_Metadata Object, dass benutzt werden soll, generisch wird das erste Object, dass in parent gefunden wird angezeigt. |
| @return: directory der Form [pfad zum Objekt] -> (fileType,metadatum als String) | @return: directory der Form [pfad zum Objekt] -> (fileType,metadatum als String) |
| """ | """ |
| server=xmlrpclib.Server(self.serverUrl) | |
| realPath=os.path.normpath(os.path.join(self.rootFolderName,path)) | realPath=os.path.normpath(os.path.join(self.rootFolderName,path)) |
| if metaDataId: | if metaDataId: |
| Line 220 class OSAS_storeOnline(SimpleItem): | Line 313 class OSAS_storeOnline(SimpleItem): |
| return {} | return {} |
| if not os.path.exists(realPath): | |
| #return None,"(ERROR) path %s does not exist."%path | |
| return None | |
| stats=os.stat(realPath) | |
| stats=server.getStat(realPath) | |
| if not stats: | |
| return None | |
| #teste ob schon im cache | #teste ob schon im cache |
| if self._v_fileSystem.has_key(realPath) and (self._v_fileSystem[realPath][0]==stats[stat.ST_MTIME]): | #if self._v_fileSystem.has_key(realPath) and (self._v_fileSystem[realPath][0]==stats[stat.ST_MTIME]): |
| # | |
| # return self._v_fileSystem[realPath][1] | |
| return self._v_fileSystem[realPath][1] | indexMetas=server.getAllIndexMetasOfSubDirs(realPath) |
| dir=indexMetas.keys() | |
| dir=os.listdir(realPath) | |
| ret={} | ret={} |
| for filename in dir: | for filename in dir: |
| object=os.path.join(realPath,filename) | object=os.path.join(realPath,filename) |
| fileType=OSAS_helpers.checkOSASFileType(object) | fileType=indexMetas[filename][0] |
| if fileType: | if fileType: |
| if metaData: | if (fileType=='OSAS_dir') and indexMetas.has_key(".") and indexMetas["."][1]: |
| if(OSAS_helpers.isImageFolder(object,decodeRPC(indexMetas["."][1]))): | |
| fileType='OSAS_imageFolder' | |
| elif(OSAS_helpers.isVideoFolder(object,decodeRPC(indexMetas["."][1]))): | |
| fileType='OSAS_videoFolder' | |
| if metaData and indexMetas[filename][1]: | |
| ret[object]=(fileType,metaData.getDisplayFieldsAsStr(decodeRPC(indexMetas[filename][1]))) | |
| else: | |
| metaDataStr=self.findEntryInIndexMeta(object) | |
| if metaDataStr: | |
| display=metaData.getDisplayFieldsAsStr(metaDataStr) | |
| dom = NonvalidatingReader.parseString(metaDataStr,"http://www.mpiwg-berlin.mpg.de/") | |
| if len(Ft.Xml.XPath.Evaluate("/file/meta/video-file",contextNode=dom))>0: | |
| fileType='OSAS_videoFile' | |
| ret[object]=(fileType,metaData.getDisplayFieldsAsStr(object)) | |
| else: | else: |
| ret[object]=(fileType,'') | display="" |
| ret[object]=(fileType,display) | |
| self._v_fileSystem[realPath]=(stats[stat.ST_MTIME],ret) # speicher im chache | self._v_fileSystem[realPath]=(stats[stat.ST_MTIME],ret) # speicher im chache |
| Line 257 class OSAS_storeOnline(SimpleItem): | Line 373 class OSAS_storeOnline(SimpleItem): |
| ret=[] | ret=[] |
| for handler in self.ZopeFind(self.aq_parent,obj_metatypes=['OSAS_HandlerObject__neu'],search_sub=1): | for handler in self.ZopeFind(self.aq_parent,obj_metatypes=['OSAS_HandlerObject__neu'],search_sub=1): |
| if type in handler[1].objectTypes: | if type in handler[1].objectTypes: |
| try: | try: |
| path=path.replace(getattr(handler[1],'ignorePath',''),'') | path=path.replace(getattr(handler[1],'ignorePath',''),'') |
| Line 278 class OSAS_storeOnline(SimpleItem): | Line 395 class OSAS_storeOnline(SimpleItem): |
| - (string) handler sind die Ergebnisse von giveHandlers fuer dieses Objekt | - (string) handler sind die Ergebnisse von giveHandlers fuer dieses Objekt |
| - (string) metainformationen die Metainformationen zum Objekt als Ergebnis von readObjectsFromPath | - (string) metainformationen die Metainformationen zum Objekt als Ergebnis von readObjectsFromPath |
| """ | """ |
| objects=self.readObjectsFromPath(path) | |
| if not objects: | objects=self.getSubDirsFromIndexMeta(path) |
| objects={} | |
| im=self.getSubDirsFromIndexMeta(path) | |
| im=self.readObjectsFromPath(path) | |
| if not im: | |
| im={} | |
| for key in im.keys(): | for key in im.keys(): |
| #virtuelle pfade hinzufuegen | #relle pfade hinzufuegen, virtueller wird ueberschrieben |
| if not objects.has_key(key): | |
| objects[key]=im[key] | objects[key]=im[key] |
| def sortLow(x,y): | def sortLow(x,y): |
| return cmp(x.lower(),y.lower()) | return cmp(x.lower(),y.lower()) |
| Line 297 class OSAS_storeOnline(SimpleItem): | Line 422 class OSAS_storeOnline(SimpleItem): |
| objectSorted=objects.keys() | objectSorted=objects.keys() |
| objectSorted.sort(sortLow) | objectSorted.sort(sortLow) |
| for object in objectSorted: | for object in objectSorted: |
| handler=self.giveHandlers(object,objects[object][0]) | handler=self.giveHandlers(object,objects[object][0]) |
| if objects[object][0]=="OSAS_dir": | if not(os.path.split(object)[1]=="."): |
| if objects[object][0] in OSASDirObjects: | |
| string="""<a href="?path=%s">%s</a>"""%(object,os.path.split(object)[1]) | string="""<a href="?path=%s">%s</a>"""%(object,os.path.split(object)[1]) |
| Line 308 class OSAS_storeOnline(SimpleItem): | Line 435 class OSAS_storeOnline(SimpleItem): |
| ret.append((string,handler,objects[object][1])) | ret.append((string,handler,objects[object][1])) |
| else: | else: |
| ret.append((os.path.split(object)[1],handler,objects[object][1])) | ret.append((os.path.split(object)[1],handler,objects[object][1])) |
| Line 317 class OSAS_storeOnline(SimpleItem): | Line 445 class OSAS_storeOnline(SimpleItem): |
| def path_to_link(self,pathTmp=""): | def path_to_link(self,pathTmp=""): |
| """generates navigation bar for viewfiles | """generates navigation bar for viewfiles |
| @keyword pathTmp: optional, generisch="", pfad der erstellt werden soll | @keyword pathTmp: optional, generisch="", pfad der erstellt werden soll |
| @return: html Fragment, pathTmp zerlegt, dass jeder Teil von Pfad unterhalb von rootFolderName direkt angesprunden werden kann. | @return: html Fragment, pathTmp zerlegt, dass jeder Teil von Pfad unterhalb von rootFolderName direkt angesprungen werden kann. |
| """ | """ |
| path=os.path.normpath(os.path.join(self.rootFolderName,pathTmp)) | path=os.path.normpath(os.path.join(self.rootFolderName,pathTmp)) |
| Line 346 class OSAS_storeOnline(SimpleItem): | Line 474 class OSAS_storeOnline(SimpleItem): |
| i=i-1 | i=i-1 |
| return string | return string |
| def getMetaFile(self,path): | |
| """Lies Metafile ein | |
| @param path: Pfad des index.met | |
| @return: index.meta file | |
| """ | |
| tmp=OSAS_helpers.getMetaFile(self,path) | |
| #zLOG.LOG("EE",zLOG.INFO,type(tmp)) | |
| return tmp | |
| InitializeClass(OSAS_storeOnline) | InitializeClass(OSAS_storeOnline) |