--- OSA_system2/OSAS_browser.py 2005/03/03 20:41:00 1.15 +++ OSA_system2/OSAS_browser.py 2007/01/31 14:30:30 1.22 @@ -8,12 +8,21 @@ from Products.PageTemplates.PageTemplate from OFS.Folder import Folder from OFS.SimpleItem import SimpleItem from Globals import InitializeClass,package_home -import zLOG + +import logging + +#ersetzt logging +def logger(txt,method,txt2): + """logging""" + logging.info(txt+ txt2) + + import base64 import bz2 import os import os.path import stat +import Ft.Xml.XPath import xml.dom.minidom from types import * import xmlrpclib @@ -41,8 +50,26 @@ class OSAS_storeOnline(SimpleItem): objects=self.readObjectsFromPath(realPath) - return objects[os.path.join(realPath,".")][0] - + 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 @@ -60,7 +87,7 @@ class OSAS_storeOnline(SimpleItem): return self.getMetaInfoFromIndexMeta(path) #return "NO_METADATA" else: - + dom = xml.dom.minidom.parseString(f) try: @@ -116,9 +143,9 @@ class OSAS_storeOnline(SimpleItem): @param path: Pfad auf das Object relativ zum rootFolderName @return: metadata als html """ - print "search for ",path + xmlInfos=self.findEntryInIndexMeta(path) - print "RRRRRRRRRRRR",xmlInfos + if xmlInfos: return OSAS_helpers.getMetaInfoFromXML(path,xmlInfos) else: @@ -132,7 +159,7 @@ class OSAS_storeOnline(SimpleItem): server=xmlrpclib.Server(self.serverUrl) indexMeta=server.findIndexMeta(path) # suche index.meta - print "found indexMeta",indexMeta + if not indexMeta: return None @@ -140,10 +167,10 @@ class OSAS_storeOnline(SimpleItem): path=os.path.normpath(path) try: - - dom=xml.dom.minidom.parseString(server.getFile(indexMeta)) + dom = NonvalidatingReader.parseString(server.getFile(indexMeta),"http://www.mpiwg-berlin.mpg.de/") + except: - zLOG.LOG("OSAS_browser (findEntryInIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta) + logger("OSAS_browser (findEntryInIndexMeta)",logging.ERROR,"Cannot parse: %s"%indexMeta) return None path=path.replace(realPath,'') @@ -155,8 +182,8 @@ class OSAS_storeOnline(SimpleItem): searchPath=searchPath[1:] #ist path ein directory? xpath="/resource/dir[name='%s' and path='%s']"%(name,searchPath) + dirs=Ft.Xml.XPath.Evaluate(xpath,contextNode=dom) - dirs=xml.xpath.Evaluate(xpath,dom) if len(dirs)>0: return dirs[0].toxml @@ -164,8 +191,8 @@ class OSAS_storeOnline(SimpleItem): #ist path ein file? xpath="/resource/file[name='%s' and path='%s']"%(name,searchPath) - dirs=xml.xpath.Evaluate(xpath,dom) + dirs=Ft.Xml.XPath.Evaluate(xpath,contextNode=dom) if len(dirs)>0: return dirs[0].toxml() @@ -180,9 +207,10 @@ class OSAS_storeOnline(SimpleItem): @todo: Rueckgabe einer Beschreibung gemaess Metadaten """ ret={} + startPath=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 @@ -193,15 +221,16 @@ class OSAS_storeOnline(SimpleItem): - #teste ob schon im cache - - if self._v_metaFiles.has_key(path) and (self._v_metaFiles[path][0]==stats[stat.ST_MTIME]): - return self._v_metaFiles[path][1] + #teste ob schon im cache zur Zeit kein chache wenn index.meta file nicht im selben ordner wie path. + + #if self._v_metaFiles.has_key(startPath) and (self._v_metaFiles[realPath][0]==stats[stat.ST_MTIME]) and (path==""): + # + # return self._v_metaFiles[startPath][1] try: dom=xml.dom.minidom.parseString(server.getFile(indexMeta)) except: - zLOG.LOG("OSAS_browser (getSubDirsFromIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta) + logger("OSAS_browser (getSubDirsFromIndexMeta)",logging.ERROR,"Cannot parse: %s"%indexMeta) return ret dirs=[] @@ -229,7 +258,7 @@ class OSAS_storeOnline(SimpleItem): object=os.path.join(realPath,pathX,name) ret[object.encode('utf-8')]=(fileType,'') - self._v_metaFiles[path]=(stats[stat.ST_MTIME],ret) # speicher im chache + self._v_metaFiles[startPath]=(stats[stat.ST_MTIME],ret) # speicher im chache return ret @@ -277,14 +306,14 @@ class OSAS_storeOnline(SimpleItem): if metaDataId: metaData=getattr(self,metaDataId) if not (getattr(metaData,'meta_type','')=='OSAS_Metadata__neu'): - zLOG.LOG('OSAS_browser (readObjectsFromPath)',zLOG.ERROR,"%s is not OSAS_Metadata") + logger('OSAS_browser (readObjectsFromPath)',logging.ERROR,"%s is not OSAS_Metadata") metaData=None else: metaDatas=self.ZopeFind(self.aq_parent,obj_metatypes=['OSAS_Metadata__neu'],search_sub=1) if metaDatas: metaData=metaDatas[0][1] else: - zLOG.LOG('OSAS_browser (readObjectsFromPath)',zLOG.INFO,"There is no OSAS_Metadata Object") + logger('OSAS_browser (readObjectsFromPath)',logging.INFO,"There is no OSAS_Metadata Object") metaData=None #print "md",metaData @@ -309,33 +338,33 @@ class OSAS_storeOnline(SimpleItem): ret={} for filename in dir: - print "doing",filename,indexMetas + object=os.path.join(realPath,filename) fileType=indexMetas[filename][0] if fileType: 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: 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: + dom = NonvalidatingReader.parseString(metaDataStr,"http://www.mpiwg-berlin.mpg.de/") + if len(Ft.Xml.XPath.Evaluate("/file/meta/video-file",contextNode=dom))>0: fileType='OSAS_videoFile' else: display="" - print object,fileType,display + ret[object]=(fileType,display) @@ -354,10 +383,10 @@ class OSAS_storeOnline(SimpleItem): for handler in self.ZopeFind(self.aq_parent,obj_metatypes=['OSAS_HandlerObject__neu'],search_sub=1): if type in handler[1].objectTypes: - try: + try: path=path.replace(getattr(handler[1],'ignorePath',''),'') except: - pass + pass url=handler[1].prefix%path text=handler[1].title string="""%s"""%(url,text) @@ -374,18 +403,24 @@ class OSAS_storeOnline(SimpleItem): - (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={} + objects=self.getSubDirsFromIndexMeta(path) - im=self.getSubDirsFromIndexMeta(path) + + + im=self.readObjectsFromPath(path) + if not im: + im={} + + + + for key in im.keys(): - #virtuelle pfade hinzufuegen + #relle pfade hinzufuegen, virtueller wird ueberschrieben - if not objects.has_key(key): - objects[key]=im[key] - + objects[key]=im[key] + + def sortLow(x,y): return cmp(x.lower(),y.lower()) @@ -397,18 +432,19 @@ class OSAS_storeOnline(SimpleItem): 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]) - - 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 @@ -417,7 +453,7 @@ class OSAS_storeOnline(SimpleItem): def path_to_link(self,pathTmp=""): """generates navigation bar for viewfiles @keyword pathTmp: optional, generisch="", pfad der erstellt werden soll - @return: html Fragment, pathTmp zerlegt, dass jeder Teil von Pfad unterhalb von rootFolderName direkt angesprunden werden kann. + @return: html Fragment, pathTmp zerlegt, dass jeder Teil von Pfad unterhalb von rootFolderName direkt angesprungen werden kann. """ path=os.path.normpath(os.path.join(self.rootFolderName,pathTmp)) @@ -448,7 +484,7 @@ class OSAS_storeOnline(SimpleItem): InitializeClass(OSAS_storeOnline) - + def manage_addOSAS_storeOnlineForm(self): """interface for adding the OSAS_storeOnline""" pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addStoreOnline.zpt')).__of__(self)