--- OSA_system2/OSAS_browser.py 2004/11/29 09:48:07 1.1 +++ OSA_system2/OSAS_browser.py 2004/12/23 08:30:55 1.2 @@ -12,6 +12,7 @@ import zLOG import os import os.path import stat +import xml.dom.minidom class OSAS_storeOnline(SimpleItem): """Webfrontend für das Storagesystem @@ -31,7 +32,7 @@ class OSAS_storeOnline(SimpleItem): security.declareProtected('View','index_html') def index_html(self): - """main view either standard template or storeOnline_index.html in tree""" + """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: @@ -39,6 +40,129 @@ class OSAS_storeOnline(SimpleItem): return pt() + def findIndexMeta(self,path=""): + """finde index_meta fuer diesen eventuell virtuellen Pfad + @param path: optional, 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 + 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=='/': + return None + else: + return os.path.join(realPath,'index.meta') + + def findEntryInIndexMeta(self,path): + """fragm xml zum path + @param path: Pfad auf das Object relativ zum rootFolderName + @return: den Teil von Index.meta der Informationen zu path enthaelt. + """ + + indexMeta=self.findIndexMeta(path) + + realPath=os.path.split(indexMeta)[0] + path=os.path.normpath(os.path.join(self.rootFolderName,path)) + + dom=xml.dom.minidom.parse(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) + else: + name="" + + checkpath=os.path.normpath(os.path.join(realPath,pathX,name)) + if checkpath==path: + + return dir.toxml() + + #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="" + + checkpath=os.path.normpath(os.path.join(realPath,pathX,name)) + if checkpath==path: + + return dir.toxml() + + + return None + + def getSubDirsFromIndexMeta(self,path): + + """Gebe alle path untergeordenten Objekte aus + @param path: optional, default ist "", Pfad auf das Object relativ zum rootFolderName + @return: Directory [pfad auf das Objekt]->(fileType,''), fileType ist hierbei OSAS_dir_archive falls Object ein directory und OSAS_file_archive falls das Object ein File ist,der zweite Eintrag des Tupels ist zur Zeit immer '', spaeter wird hier die Beschreibung gemaess Metadaten stehen, wie bei readObjectsFromPath. + """ + ret={} + indexMeta=self.findIndexMeta(path) + if not indexMeta: + return ret + realPath=os.path.split(indexMeta)[0] + path=path.replace(realPath,"") + if path and (path[0]==os.sep): + path=path[1:] + + + dom=xml.dom.minidom.parse(indexMeta) + + dirs=[] + dirs=dom.getElementsByTagName('dir')+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 pathX==path: + if dir.tagName=="dir": + fileType="OSAS_dir_archive" + else: + fileType="OSAS_file_archive" + + object=os.path.join(realPath,pathX,name) + ret[object]=(fileType,'') + + + return ret + + + def getMetaInfoFromIndexMeta(self,path): + """metadaten zu path als html aus dem index.meta file zu path + @param path: optional, default ist "", Pfad auf das Object relativ zum rootFolderName + @return: metadata als html + """ + xmlInfos=self.findEntryInIndexMeta(path) + return OSAS_helpers.getMetaInfoFromXML(path,xmlInfos) + def readObjectsFromPath(self,path=""): @@ -46,6 +170,7 @@ class OSAS_storeOnline(SimpleItem): - to do: files aus metadaten @param path : path relativ zum root folder des Storagesystems + @return: directory der Form [pfad zum Objekt] -> (fileType,metadatum als String) """ realPath=os.path.normpath(os.path.join(self.rootFolderName,path)) @@ -56,8 +181,9 @@ class OSAS_storeOnline(SimpleItem): if not os.path.exists(realPath): - return None,"(ERROR) path %s does not exist."%path - + #return None,"(ERROR) path %s does not exist."%path + return None + stats=os.stat(realPath) # teste ob schon im cache @@ -72,6 +198,7 @@ class OSAS_storeOnline(SimpleItem): fileType=OSAS_helpers.checkOSASFileType(object) if fileType: + ret[object]=(fileType,metaData.getDisplayFieldsAsStr(object)) self._v_fileSystem[realPath]=(stats[stat.ST_MTIME],ret) # speicher im chache @@ -79,7 +206,11 @@ class OSAS_storeOnline(SimpleItem): return ret def giveHandlers(self,path,type): - """teste ob für diese Typ, viewer definiert sind""" + """teste ob fuer diesen Typ, viewer definiert sind und gibt einen entsprechenden Link zurueck, der das Object mit diesem Handler ausfuehrt. + @param path: Pfad auf das Objekt + @param type: Typ des Objektes + @return: (string) html-Fragment, link der das Objekt mit diesem Handler anzeigt. + """ ret=[] for viewer in self.ZopeFind(self.aq_parent,obj_metatypes=['OSAS_ViewerObject__neu'],search_sub=1): @@ -93,8 +224,24 @@ class OSAS_storeOnline(SimpleItem): def generateTree(self,path=""): - """erzeuge navigations elemente""" + """erzeuge liest die Objekte aus die im Pfad gespeichert sind + @param path: optional mit default='', Pfad relativ zu rootFolderName + @return: List von Tripeln, (link_html,array of handlers,metainformationen) hierbei ist + - (string) link_html ein html-Fragement, falls das Objekt vom Typ OSAS_dir ist, ist dies ein Link auf dieses Verzeichnis, sonst der Dateiname + - (string) handler sind die Ergebnisse von giveHandlers fuer dieses Objekt + - (string) metainformationen die Metainformationen zum Objekt als Ergebnis von readObjectsFromPath + """ objects=self.readObjectsFromPath(path) + if not objects: + objects={} + im=self.getSubDirsFromIndexMeta(path) + for key in im.keys(): + #virtuelle pfade hinzufuegen + + if not objects.has_key(key): + objects[key]=im[key] + + def sortLow(x,y): return cmp(x.lower(),y.lower()) @@ -109,6 +256,10 @@ class OSAS_storeOnline(SimpleItem): string="""%s"""%(object,os.path.split(object)[1]) ret.append((string,handler,objects[object][1])) + elif objects[object][0]=="OSAS_dir_archive": + string="""%s (A)"""%(object,os.path.split(object)[1]) + + ret.append((string,handler,objects[object][1])) else: ret.append((os.path.split(object)[1],handler,objects[object][1])) @@ -147,7 +298,7 @@ class OSAS_storeOnline(SimpleItem): def getMetaFile(self,path): """Lese Metafile ein""" - return OSAS_helpers.getMetaFile(path) + return OSAS_helpers.getMetaFile(self,path) InitializeClass(OSAS_storeOnline)