--- OSA_system2/OSAS_browser.py 2004/11/29 09:48:07 1.1
+++ OSA_system2/OSAS_browser.py 2004/12/23 10:48:28 1.3
@@ -12,6 +12,8 @@ import zLOG
import os
import os.path
import stat
+import xml.dom.minidom
+from types import *
class OSAS_storeOnline(SimpleItem):
"""Webfrontend für das Storagesystem
@@ -22,6 +24,7 @@ class OSAS_storeOnline(SimpleItem):
security=ClassSecurityInfo()
_v_fileSystem={} #chache fuer filesystem
+ _v_metaFiles={} #chache fuer indexMeta
def __init__(self,id):
"""initialize a new instance"""
@@ -31,7 +34,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,13 +42,145 @@ 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, None wenn error.
+ """
+
+ indexMeta=self.findIndexMeta(path)
+ if not indexMeta:
+ return None
+ 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:]
+
+ stats=os.stat(indexMeta)
+
+ #teste ob schon im cache
+ if self._v_metaFiles.has_key(indexMeta) and (self._v_metaFiles[indexMeta][0]==stats[stat.ST_MTIME]):
+
+ return self._v_metaFiles[indexMeta][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,'')
+
+ self._v_metaFiles[indexMeta]=(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
+ @param path: optional, default ist "", Pfad auf das Object relativ zum rootFolderName
+ @return: metadata als html
+ """
+ xmlInfos=self.findEntryInIndexMeta(path)
+ if xmlInfos:
+ return OSAS_helpers.getMetaInfoFromXML(path,xmlInfos)
+ else:
+ return ""
def readObjectsFromPath(self,path=""):
"""Liest files aus dem path und speichert im cache _v_filesystem.
- - 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,14 +191,15 @@ 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
- #if self._v_fileSystem.has_key(realPath) and (self._v_fileSystem[realPath][0]==stats[stat.ST_MTIME]):
+ #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]
+ return self._v_fileSystem[realPath][1]
dir=os.listdir(realPath)
ret={}
@@ -72,6 +208,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 +216,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 +234,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 +266,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 +308,10 @@ class OSAS_storeOnline(SimpleItem):
def getMetaFile(self,path):
"""Lese Metafile ein"""
- return OSAS_helpers.getMetaFile(path)
+ tmp=OSAS_helpers.getMetaFile(self,path)
+ #zLOG.LOG("EE",zLOG.INFO,type(tmp))
+
+ return tmp
InitializeClass(OSAS_storeOnline)