version 1.12, 2005/02/11 18:11:52
|
version 1.21, 2005/11/25 17:49:53
|
Line 9 from OFS.Folder import Folder
|
Line 9 from OFS.Folder import Folder
|
from OFS.SimpleItem import SimpleItem |
from OFS.SimpleItem import SimpleItem |
from Globals import InitializeClass,package_home |
from Globals import InitializeClass,package_home |
import zLOG |
import zLOG |
|
import base64 |
|
import bz2 |
import os |
import os |
import os.path |
import os.path |
import stat |
import stat |
|
import Ft.Xml.XPath |
import xml.dom.minidom |
import xml.dom.minidom |
from types import * |
from types import * |
import xmlrpclib |
import xmlrpclib |
from OSAS_helpers import * |
from OSAS_helpers import * |
|
|
|
def decodeRPC(string): |
|
return bz2.decompress(base64.decodestring(string)) |
|
|
|
|
class OSAS_storeOnline(SimpleItem): |
class OSAS_storeOnline(SimpleItem): |
"""Webfrontend für das Storagesystem |
"""Webfrontend für das Storagesystem |
Line 28 class OSAS_storeOnline(SimpleItem):
|
Line 34 class OSAS_storeOnline(SimpleItem):
|
|
|
_v_fileSystem={} #chache fuer filesystem |
_v_fileSystem={} #chache fuer filesystem |
_v_metaFiles={} #chache fuer indexMeta |
_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): |
def getMetaFile(self,path): |
"""get index.meta and translate it to HTML""" |
"""get index.meta and translate it to HTML""" |
"""Lies Metafile ein |
"""Lies Metafile ein |
Line 101 class OSAS_storeOnline(SimpleItem):
|
Line 135 class OSAS_storeOnline(SimpleItem):
|
@param path: Pfad auf das Object relativ zum rootFolderName |
@param path: Pfad auf das Object relativ zum rootFolderName |
@return: metadata als html |
@return: metadata als html |
""" |
""" |
|
|
xmlInfos=self.findEntryInIndexMeta(path) |
xmlInfos=self.findEntryInIndexMeta(path) |
|
|
if xmlInfos: |
if xmlInfos: |
return OSAS_helpers.getMetaInfoFromXML(path,xmlInfos) |
return OSAS_helpers.getMetaInfoFromXML(path,xmlInfos) |
else: |
else: |
Line 123 class OSAS_storeOnline(SimpleItem):
|
Line 159 class OSAS_storeOnline(SimpleItem):
|
path=os.path.normpath(path) |
path=os.path.normpath(path) |
|
|
try: |
try: |
|
dom = NonvalidatingReader.parseString(server.getFile(indexMeta),"http://www.mpiwg-berlin.mpg.de/") |
|
|
dom=xml.dom.minidom.parseString(server.getFile(indexMeta)) |
|
except: |
except: |
zLOG.LOG("OSAS_browser (findEntryInIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta) |
zLOG.LOG("OSAS_browser (findEntryInIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta) |
#ist path ein directory? |
return None |
dirs=dom.getElementsByTagName('dir') |
|
for dir in dirs: |
path=path.replace(realPath,'') |
pathes=dir.getElementsByTagName('path') |
(searchPath,name)=os.path.split(path) |
if pathes: |
if (len(searchPath)>0) and (searchPath[0]=="/"): |
pathX=OSAS_helpers.getText(pathes[0].childNodes) |
if len(searchPath)<=1: |
else: |
searchPath="" |
pathX="" |
|
names=dir.getElementsByTagName('name') |
|
if names: |
|
name=OSAS_helpers.getText(names[0].childNodes) |
|
else: |
else: |
name="" |
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) |
|
|
checkpath=os.path.normpath(os.path.join(realPath,pathX,name)) |
|
if checkpath==path: |
|
|
|
return dir.toxml() |
if len(dirs)>0: |
|
return dirs[0].toxml |
|
|
#ist path ein file? |
#ist path ein file? |
files=dom.getElementsByTagName('file') |
xpath="/resource/file[name='%s' and path='%s']"%(name,searchPath) |
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() |
|
|
|
|
dirs=Ft.Xml.XPath.Evaluate(xpath,contextNode=dom) |
|
if len(dirs)>0: |
|
return dirs[0].toxml() |
|
|
return None |
return None |
|
|
Line 177 class OSAS_storeOnline(SimpleItem):
|
Line 199 class OSAS_storeOnline(SimpleItem):
|
@todo: Rueckgabe einer Beschreibung gemaess Metadaten |
@todo: Rueckgabe einer Beschreibung gemaess Metadaten |
""" |
""" |
ret={} |
ret={} |
|
startPath=path |
server=xmlrpclib.Server(self.serverUrl) |
server=xmlrpclib.Server(self.serverUrl) |
indexMeta,stats=server.findIndexMetaWithStats(path)#findex index.meta zu path. |
indexMeta,stats=server.findIndexMetaWithStats(path)#findex index.meta zu path. |
|
|
Line 190 class OSAS_storeOnline(SimpleItem):
|
Line 213 class OSAS_storeOnline(SimpleItem):
|
|
|
|
|
|
|
#teste ob schon im cache |
#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(path) and (self._v_metaFiles[path][0]==stats[stat.ST_MTIME]): |
#if self._v_metaFiles.has_key(startPath) and (self._v_metaFiles[realPath][0]==stats[stat.ST_MTIME]) and (path==""): |
return self._v_metaFiles[path][1] |
# |
|
# return self._v_metaFiles[startPath][1] |
|
|
try: |
try: |
dom=xml.dom.minidom.parseString(server.getFile(indexMeta)) |
dom=xml.dom.minidom.parseString(server.getFile(indexMeta)) |
Line 226 class OSAS_storeOnline(SimpleItem):
|
Line 250 class OSAS_storeOnline(SimpleItem):
|
object=os.path.join(realPath,pathX,name) |
object=os.path.join(realPath,pathX,name) |
ret[object.encode('utf-8')]=(fileType,'') |
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 |
return ret |
|
|
Line 261 class OSAS_storeOnline(SimpleItem):
|
Line 285 class OSAS_storeOnline(SimpleItem):
|
|
|
|
|
|
|
|
|
|
|
|
|
def readObjectsFromPath(self,path="",metaDataId=None): |
def readObjectsFromPath(self,path="",metaDataId=None): |
"""Liest files aus dem path und speichert im cache _v_filesystem. |
"""Liest files aus dem path und speichert im cache _v_filesystem. |
|
|
Line 300 class OSAS_storeOnline(SimpleItem):
|
Line 321 class OSAS_storeOnline(SimpleItem):
|
return None |
return None |
|
|
#teste ob schon im cache |
#teste ob schon im cache |
if self._v_fileSystem.has_key(realPath) and (self._v_fileSystem[realPath][0]==stats[stat.ST_MTIME]): |
#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=server.listdir(realPath) |
|
|
|
|
indexMetas=server.getAllIndexMetasOfSubDirs(realPath) |
|
dir=indexMetas.keys() |
|
|
ret={} |
ret={} |
for filename in dir: |
for filename in dir: |
|
|
object=os.path.join(realPath,filename) |
object=os.path.join(realPath,filename) |
fileType=OSAS_helpers.checkOSASFileType(object,server) |
fileType=indexMetas[filename][0] |
|
|
if fileType: |
if fileType: |
if metaData: |
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(object,server)) |
ret[object]=(fileType,metaData.getDisplayFieldsAsStr(decodeRPC(indexMetas[filename][1]))) |
else: |
else: |
ret[object]=(fileType,'') |
metaDataStr=self.findEntryInIndexMeta(object) |
|
|
|
if metaDataStr: |
|
display=metaData.getDisplayFieldsAsStr(metaDataStr) |
|
|
|
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="" |
|
|
|
|
|
ret[object]=(fileType,display) |
|
|
self._v_fileSystem[realPath]=(stats[stat.ST_MTIME],ret) # speicher im chache |
self._v_fileSystem[realPath]=(stats[stat.ST_MTIME],ret) # speicher im chache |
|
|
Line 332 class OSAS_storeOnline(SimpleItem):
|
Line 373 class OSAS_storeOnline(SimpleItem):
|
ret=[] |
ret=[] |
|
|
for handler in self.ZopeFind(self.aq_parent,obj_metatypes=['OSAS_HandlerObject__neu'],search_sub=1): |
for handler in self.ZopeFind(self.aq_parent,obj_metatypes=['OSAS_HandlerObject__neu'],search_sub=1): |
|
|
if type in handler[1].objectTypes: |
if type in handler[1].objectTypes: |
try: |
try: |
path=path.replace(getattr(handler[1],'ignorePath',''),'') |
path=path.replace(getattr(handler[1],'ignorePath',''),'') |
Line 353 class OSAS_storeOnline(SimpleItem):
|
Line 395 class OSAS_storeOnline(SimpleItem):
|
- (string) handler sind die Ergebnisse von giveHandlers fuer dieses Objekt |
- (string) handler sind die Ergebnisse von giveHandlers fuer dieses Objekt |
- (string) metainformationen die Metainformationen zum Objekt als Ergebnis von readObjectsFromPath |
- (string) metainformationen die Metainformationen zum Objekt als Ergebnis von readObjectsFromPath |
""" |
""" |
objects=self.readObjectsFromPath(path) |
|
if not objects: |
objects=self.getSubDirsFromIndexMeta(path) |
objects={} |
|
|
|
|
|
|
im=self.readObjectsFromPath(path) |
|
if not im: |
|
im={} |
|
|
|
|
|
|
|
|
im=self.getSubDirsFromIndexMeta(path) |
|
for key in im.keys(): |
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): |
def sortLow(x,y): |
return cmp(x.lower(),y.lower()) |
return cmp(x.lower(),y.lower()) |
|
|
Line 374 class OSAS_storeOnline(SimpleItem):
|
Line 422 class OSAS_storeOnline(SimpleItem):
|
objectSorted=objects.keys() |
objectSorted=objects.keys() |
objectSorted.sort(sortLow) |
objectSorted.sort(sortLow) |
for object in objectSorted: |
for object in objectSorted: |
|
|
handler=self.giveHandlers(object,objects[object][0]) |
handler=self.giveHandlers(object,objects[object][0]) |
if objects[object][0]=="OSAS_dir": |
if not(os.path.split(object)[1]=="."): |
|
if objects[object][0] in OSASDirObjects: |
|
|
string="""<a href="?path=%s">%s</a>"""%(object,os.path.split(object)[1]) |
string="""<a href="?path=%s">%s</a>"""%(object,os.path.split(object)[1]) |
|
|
Line 385 class OSAS_storeOnline(SimpleItem):
|
Line 435 class OSAS_storeOnline(SimpleItem):
|
|
|
ret.append((string,handler,objects[object][1])) |
ret.append((string,handler,objects[object][1])) |
else: |
else: |
|
|
ret.append((os.path.split(object)[1],handler,objects[object][1])) |
ret.append((os.path.split(object)[1],handler,objects[object][1])) |
|
|
|
|
Line 394 class OSAS_storeOnline(SimpleItem):
|
Line 445 class OSAS_storeOnline(SimpleItem):
|
def path_to_link(self,pathTmp=""): |
def path_to_link(self,pathTmp=""): |
"""generates navigation bar for viewfiles |
"""generates navigation bar for viewfiles |
@keyword pathTmp: optional, generisch="", pfad der erstellt werden soll |
@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)) |
path=os.path.normpath(os.path.join(self.rootFolderName,pathTmp)) |