--- OSA_system2/OSAS_browser.py 2005/02/10 20:23:24 1.9 +++ OSA_system2/OSAS_browser.py 2005/03/07 19:33:42 1.16 @@ -9,13 +9,18 @@ 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): @@ -27,8 +32,227 @@ class OSAS_storeOnline(SimpleItem): security=ClassSecurityInfo() _v_fileSystem={} #chache fuer filesystem + _v_metaFiles={} #chache fuer indexMeta + def getParentType(self,path): + """getFileType des parentordners""" + + realPath=os.path.split(path)[0] + + objects=self.readObjectsFromPath(realPath) + + try: + return objects[os.path.join(realPath,".")][0] + except: + return "" + def getHandlersOfPath(self): + """handler des actullen path""" + path=self.REQUEST['path'] + objects=self.readObjectsFromPath(path) + + typeObject=objects.get(os.path.join(path,"."),None) + if not typeObject: + return("",[],"") + type=typeObject[0] + + handler=self.giveHandlers(path,type) + + + 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 + """ + html=[] + server=xmlrpclib.Server(self.serverUrl) + + + f=server.getFile(path+"/index.meta") + + if not f: + + return self.getMetaInfoFromIndexMeta(path) + #return "NO_METADATA" + else: + + 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""" + + # 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: + 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. + """ + + 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(path) + + try: + + dom=xml.dom.minidom.parseString(server.getFile(indexMeta)) + except: + zLOG.LOG("OSAS_browser (findEntryInIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta) + 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: + searchPath=searchPath[1:] + #ist path ein directory? + xpath="/resource/dir[name='%s' and path='%s']"%(name,searchPath) + + dirs=xml.xpath.Evaluate(xpath,dom) + + if len(dirs)>0: + return dirs[0].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 + @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. + @todo: Rueckgabe einer Beschreibung gemaess Metadaten + """ + ret={} + server=xmlrpclib.Server(self.serverUrl) + indexMeta,stats=server.findIndexMetaWithStats(path)#findex index.meta zu path. + + if not indexMeta: + return ret + + realPath=os.path.split(indexMeta)[0] + path=path.replace(realPath,"") + if path and (path[0]==os.sep): #falls am Anfang os.sep steht lösche dieses. + path=path[1:] + + + + #teste ob schon im cache zur Zeit kein chache wenn index.meta file nicht im selben ordner wir path. + print "PPP",path,"x",realPath + if self._v_metaFiles.has_key(realPath) and (self._v_metaFiles[realPath][0]==stats[stat.ST_MTIME]) and (path==""): + print "from cache" + return self._v_metaFiles[realPath][1] + + try: + 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') + + 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="" + + #print "PP",pathX,path + 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.encode('utf-8')]=(fileType,'') + + self._v_metaFiles[realPath]=(stats[stat.ST_MTIME],ret) # speicher im chache + + return ret + + def __init__(self,id,serverUrl): """initialize a new instance @@ -59,9 +283,6 @@ class OSAS_storeOnline(SimpleItem): - - - def readObjectsFromPath(self,path="",metaDataId=None): """Liest files aus dem path und speichert im cache _v_filesystem. @@ -100,20 +321,42 @@ class OSAS_storeOnline(SimpleItem): #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=server.listdir(realPath) + return self._v_fileSystem[realPath][1] + + indexMetas=server.getAllIndexMetasOfSubDirs(realPath) + dir=indexMetas.keys() + ret={} for filename in dir: + 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]: + + 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: - ret[object]=(fileType,'') + metaDataStr=self.findEntryInIndexMeta(object) + + 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="" + + + ret[object]=(fileType,display) self._v_fileSystem[realPath]=(stats[stat.ST_MTIME],ret) # speicher im chache @@ -128,6 +371,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',''),'') @@ -153,8 +397,8 @@ class OSAS_storeOnline(SimpleItem): if not objects: objects={} - server=xmlrpclib.Server(self.serverUrl) - im=server.getSubDirsFromIndexMeta(path) + + im=self.getSubDirsFromIndexMeta(path) for key in im.keys(): #virtuelle pfade hinzufuegen @@ -170,18 +414,21 @@ class OSAS_storeOnline(SimpleItem): objectSorted=objects.keys() objectSorted.sort(sortLow) for object in objectSorted: + handler=self.giveHandlers(object,objects[object][0]) - if objects[object][0]=="OSAS_dir": - - 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])) + if not(os.path.split(object)[1]=="."): + if objects[object][0] in OSASDirObjects: + + 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])) return ret @@ -219,16 +466,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 - """ - server=xmlrpclib.Server(self.serverUrl) - tmp=server.getMetaFile(path) - #zLOG.LOG("EE",zLOG.INFO,type(tmp)) - - return tmp InitializeClass(OSAS_storeOnline)