--- OSA_system2/OSAS_browser.py 2005/01/21 14:03:24 1.7 +++ OSA_system2/OSAS_browser.py 2005/02/11 16:27:01 1.10 @@ -14,6 +14,9 @@ import os.path import stat import xml.dom.minidom from types import * +import xmlrpclib +from OSAS_helpers import * + class OSAS_storeOnline(SimpleItem): """Webfrontend für das Storagesystem @@ -25,58 +28,103 @@ 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 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 + xmlInfos=self.findEntryInIndexMeta(path) + 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 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? @@ -120,6 +168,7 @@ class OSAS_storeOnline(SimpleItem): return None + def getSubDirsFromIndexMeta(self,path): """Gebe alle path untergeordenten Objekte aus @@ -128,7 +177,8 @@ 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. if not indexMeta: return ret @@ -141,15 +191,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,22 +224,44 @@ 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): @@ -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,18 +292,19 @@ 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) + dir=server.listdir(realPath) ret={} for filename in dir: object=os.path.join(realPath,filename) @@ -281,6 +354,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 @@ -346,15 +421,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)