--- OSA_system2/OSAS_browser.py 2005/01/21 14:03:24 1.7 +++ OSA_system2/OSAS_browser.py 2005/03/03 20:41:00 1.15 @@ -9,11 +9,19 @@ from OFS.Folder import Folder from OFS.SimpleItem import SimpleItem from Globals import InitializeClass,package_home import zLOG +import base64 +import bz2 import os import os.path import stat import xml.dom.minidom from types import * +import xmlrpclib +from OSAS_helpers import * + +def decodeRPC(string): + return bz2.decompress(base64.decodestring(string)) + class OSAS_storeOnline(SimpleItem): """Webfrontend für das Storagesystem @@ -25,101 +33,145 @@ class OSAS_storeOnline(SimpleItem): _v_fileSystem={} #chache fuer filesystem _v_metaFiles={} #chache fuer indexMeta - - def __init__(self,id): - """initialize a new instance - @param id: Zope id""" - self.id = id + def getParentType(self,path): + """getFileType des parentordners""" + + realPath=os.path.split(path)[0] + + objects=self.readObjectsFromPath(realPath) + + return objects[os.path.join(realPath,".")][0] + 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 + """ + html=[] + server=xmlrpclib.Server(self.serverUrl) + - 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')() + f=server.getFile(path+"/index.meta") + + if not f: + + return self.getMetaInfoFromIndexMeta(path) + #return "NO_METADATA" else: - pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','storeOnline_index_html.zpt')).__of__(self) - return pt() + + 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="

Document: "+name+"

" + elif type=="folder": + html="

Folder: "+name+"

" + else: + html="

Document: "+name+"

" + + html=html+"

created by: "+creator+" at: "+creation_date+"

" + html=html+"

Description

"+description+"

" + try: + bib = dom.getElementsByTagName("meta")[0].getElementsByTagName("bib")[0] + if bib.attributes.has_key('type'): + html=html+"

Info ("+bib.attributes['type'].value+")

" + else: + html=html+"

Info

" + html=html+getBib(bib.childNodes) + except: + """none""" - 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 + # 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 """ - realPath=os.path.normpath(os.path.join(self.rootFolderName,path)) - #suche index.meta - 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=='/': - if os.path.exists(os.path.join(realPath,'index.meta')): - return os.path.join(realPath,'index.meta') - else: - return None + print "search for ",path + xmlInfos=self.findEntryInIndexMeta(path) + print "RRRRRRRRRRRR",xmlInfos + if xmlInfos: + return OSAS_helpers.getMetaInfoFromXML(path,xmlInfos) else: - return os.path.join(realPath,'index.meta') - + return "" + def findEntryInIndexMeta(self,path): """Finde im naechstgelegenden index.meta relativ zu path den entprechenden Eintrag fuer diesen Pfad. @param path: Pfad auf das Object relativ zum rootFolderName @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 + print "found indexMeta",indexMeta if not indexMeta: return None realPath=os.path.split(indexMeta)[0] - path=os.path.normpath(os.path.join(self.rootFolderName,path)) + path=os.path.normpath(path) try: - dom=xml.dom.minidom.parse(indexMeta) + + dom=xml.dom.minidom.parseString(server.getFile(indexMeta)) except: zLOG.LOG("OSAS_browser (findEntryInIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta) - #ist path ein directory? - dirs=dom.getElementsByTagName('dir') - 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) + return None + + path=path.replace(realPath,'') + (searchPath,name)=os.path.split(path) + if (len(searchPath)>0) and (searchPath[0]=="/"): + if len(searchPath)<=1: + searchPath="" else: - name="" + searchPath=searchPath[1:] + #ist path ein directory? + xpath="/resource/dir[name='%s' and path='%s']"%(name,searchPath) - checkpath=os.path.normpath(os.path.join(realPath,pathX,name)) - if checkpath==path: - - return dir.toxml() + dirs=xml.xpath.Evaluate(xpath,dom) - #ist path ein file? - files=dom.getElementsByTagName('file') - 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="" + if len(dirs)>0: + return dirs[0].toxml - checkpath=os.path.normpath(os.path.join(realPath,pathX,name)) - if checkpath==path: - - return dir.toxml() + #ist path ein file? + xpath="/resource/file[name='%s' and path='%s']"%(name,searchPath) + dirs=xml.xpath.Evaluate(xpath,dom) + + if len(dirs)>0: + return dirs[0].toxml() return None + def getSubDirsFromIndexMeta(self,path): """Gebe alle path untergeordenten Objekte aus @@ -128,8 +180,9 @@ class OSAS_storeOnline(SimpleItem): @todo: Rueckgabe einer Beschreibung gemaess Metadaten """ ret={} - indexMeta=self.findIndexMeta(path)#findex index.meta zu path. - + server=xmlrpclib.Server(self.serverUrl) + indexMeta,stats=server.findIndexMetaWithStats(path)#findex index.meta zu path. + print "checking",path,indexMeta if not indexMeta: return ret @@ -141,15 +194,15 @@ class OSAS_storeOnline(SimpleItem): #teste ob schon im cache - stats=os.stat(indexMeta) + if self._v_metaFiles.has_key(path) and (self._v_metaFiles[path][0]==stats[stat.ST_MTIME]): return self._v_metaFiles[path][1] try: - dom=xml.dom.minidom.parse(indexMeta) + dom=xml.dom.minidom.parseString(server.getFile(indexMeta)) except: zLOG.LOG("OSAS_browser (getSubDirsFromIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta) - + return ret dirs=[] dirs=dom.getElementsByTagName('dir')+dom.getElementsByTagName('file') @@ -174,24 +227,43 @@ class OSAS_storeOnline(SimpleItem): fileType="OSAS_file_archive" object=os.path.join(realPath,pathX,name) - ret[object]=(fileType,'') + ret[object.encode('utf-8')]=(fileType,'') self._v_metaFiles[path]=(stats[stat.ST_MTIME],ret) # speicher im chache + 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) - @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) + + def __init__(self,id,serverUrl): + """initialize a new instance + @param id: Zope id""" + self.id = id + self.serverUrl = serverUrl + + + 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: - 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): """Liest files aus dem path und speichert im cache _v_filesystem. @@ -199,7 +271,7 @@ 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. @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)) if metaDataId: @@ -220,29 +292,52 @@ class OSAS_storeOnline(SimpleItem): 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 - if self._v_fileSystem.has_key(realPath) and (self._v_fileSystem[realPath][0]==stats[stat.ST_MTIME]): - - return self._v_fileSystem[realPath][1] - - dir=os.listdir(realPath) + #if self._v_fileSystem.has_key(realPath) and (self._v_fileSystem[realPath][0]==stats[stat.ST_MTIME]): + # + # return self._v_fileSystem[realPath][1] + + indexMetas=server.getAllIndexMetasOfSubDirs(realPath) + dir=indexMetas.keys() + ret={} for filename in dir: + print "doing",filename,indexMetas object=os.path.join(realPath,filename) - fileType=OSAS_helpers.checkOSASFileType(object) + fileType=indexMetas[filename][0] if fileType: - if metaData: - - ret[object]=(fileType,metaData.getDisplayFieldsAsStr(object)) + if (fileType=='OSAS_dir') and indexMetas.has_key(".") and indexMetas["."][1]: + print "TEEEEEEEEEE" + 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]: + print "do",filename + ret[object]=(fileType,metaData.getDisplayFieldsAsStr(decodeRPC(indexMetas[filename][1]))) else: - ret[object]=(fileType,'') + metaDataStr=self.findEntryInIndexMeta(object) + print "MMMMMDDDDD",metaDataStr + if metaDataStr: + display=metaData.getDisplayFieldsAsStr(metaDataStr) + dom=xml.dom.minidom.parseString(metaDataStr) + + if len(xml.xpath.Evaluate("/file/meta/video-file",dom))>0: + fileType='OSAS_videoFile' + + else: + display="" + print object,fileType,display + + ret[object]=(fileType,display) self._v_fileSystem[realPath]=(stats[stat.ST_MTIME],ret) # speicher im chache @@ -257,6 +352,7 @@ class OSAS_storeOnline(SimpleItem): ret=[] for handler in self.ZopeFind(self.aq_parent,obj_metatypes=['OSAS_HandlerObject__neu'],search_sub=1): + if type in handler[1].objectTypes: try: path=path.replace(getattr(handler[1],'ignorePath',''),'') @@ -281,6 +377,8 @@ class OSAS_storeOnline(SimpleItem): objects=self.readObjectsFromPath(path) if not objects: objects={} + + im=self.getSubDirsFromIndexMeta(path) for key in im.keys(): #virtuelle pfade hinzufuegen @@ -297,7 +395,9 @@ class OSAS_storeOnline(SimpleItem): objectSorted=objects.keys() objectSorted.sort(sortLow) for object in objectSorted: + handler=self.giveHandlers(object,objects[object][0]) + print "format",objects[object][0] if objects[object][0]=="OSAS_dir": string="""%s"""%(object,os.path.split(object)[1]) @@ -346,15 +446,6 @@ class OSAS_storeOnline(SimpleItem): i=i-1 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)