version 1.7, 2005/01/21 14:03:24
|
version 1.9, 2005/02/10 20:23:24
|
Line 14 import os.path
|
Line 14 import os.path
|
import stat |
import stat |
import xml.dom.minidom |
import xml.dom.minidom |
from types import * |
from types import * |
|
import xmlrpclib |
|
|
|
|
|
|
class OSAS_storeOnline(SimpleItem): |
class OSAS_storeOnline(SimpleItem): |
"""Webfrontend für das Storagesystem |
"""Webfrontend für das Storagesystem |
Line 24 class OSAS_storeOnline(SimpleItem):
|
Line 27 class OSAS_storeOnline(SimpleItem):
|
security=ClassSecurityInfo() |
security=ClassSecurityInfo() |
|
|
_v_fileSystem={} #chache fuer filesystem |
_v_fileSystem={} #chache fuer filesystem |
_v_metaFiles={} #chache fuer indexMeta |
|
|
|
def __init__(self,id): |
|
|
|
|
def __init__(self,id,serverUrl): |
"""initialize a new instance |
"""initialize a new instance |
@param id: Zope id""" |
@param id: Zope id""" |
self.id = id |
self.id = id |
|
self.serverUrl = serverUrl |
|
|
|
|
security.declareProtected('View','index_html') |
security.declareProtected('View','index_html') |
Line 50 class OSAS_storeOnline(SimpleItem):
|
Line 54 class OSAS_storeOnline(SimpleItem):
|
""" |
""" |
realPath=os.path.normpath(os.path.join(self.rootFolderName,path)) |
realPath=os.path.normpath(os.path.join(self.rootFolderName,path)) |
#suche index.meta |
#suche index.meta |
while (not os.path.exists(os.path.join(realPath,'index.meta'))) and (not ((realPath=="") or (realPath=="/"))): |
server=xmlrpclib.Server(self.serverUrl) |
realPath=os.path.split(realPath)[0] |
return server.findIndexMeta(realPath) |
|
|
if realPath=='' or realPath=='/': |
|
if os.path.exists(os.path.join(realPath,'index.meta')): |
|
return os.path.join(realPath,'index.meta') |
|
else: |
|
return None |
|
else: |
|
return os.path.join(realPath,'index.meta') |
|
|
|
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. |
|
""" |
|
|
|
indexMeta=self.findIndexMeta(path) # suche index.meta |
|
|
|
if not indexMeta: |
|
return None |
|
|
|
realPath=os.path.split(indexMeta)[0] |
|
path=os.path.normpath(os.path.join(self.rootFolderName,path)) |
|
|
|
try: |
|
dom=xml.dom.minidom.parse(indexMeta) |
|
except: |
|
zLOG.LOG("OSAS_browser (findEntryInIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%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. |
|
@todo: Rueckgabe einer Beschreibung gemaess Metadaten |
|
""" |
|
ret={} |
|
indexMeta=self.findIndexMeta(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 |
|
stats=os.stat(indexMeta) |
|
if self._v_metaFiles.has_key(path) and (self._v_metaFiles[path][0]==stats[stat.ST_MTIME]): |
|
return self._v_metaFiles[path][1] |
|
|
|
try: |
|
dom=xml.dom.minidom.parse(indexMeta) |
|
except: |
|
zLOG.LOG("OSAS_browser (getSubDirsFromIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%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="" |
|
|
|
#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]=(fileType,'') |
|
|
|
self._v_metaFiles[path]=(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 (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 readObjectsFromPath(self,path="",metaDataId=None): |
def readObjectsFromPath(self,path="",metaDataId=None): |
Line 199 class OSAS_storeOnline(SimpleItem):
|
Line 69 class OSAS_storeOnline(SimpleItem):
|
@keyword metaDataId: Optional, id des OSAS_Metadata Object, dass benutzt werden soll, generisch wird das erste Object, dass in parent gefunden wird angezeigt. |
@keyword metaDataId: Optional, id des OSAS_Metadata Object, dass benutzt werden soll, generisch wird das erste Object, dass in parent gefunden wird angezeigt. |
@return: directory der Form [pfad zum Objekt] -> (fileType,metadatum als String) |
@return: directory der Form [pfad zum Objekt] -> (fileType,metadatum als String) |
""" |
""" |
|
server=xmlrpclib.Server(self.serverUrl) |
realPath=os.path.normpath(os.path.join(self.rootFolderName,path)) |
realPath=os.path.normpath(os.path.join(self.rootFolderName,path)) |
|
|
if metaDataId: |
if metaDataId: |
Line 220 class OSAS_storeOnline(SimpleItem):
|
Line 90 class OSAS_storeOnline(SimpleItem):
|
return {} |
return {} |
|
|
|
|
if not os.path.exists(realPath): |
|
#return None,"(ERROR) path %s does not exist."%path |
|
return None |
|
|
|
stats=os.stat(realPath) |
|
|
stats=server.getStat(realPath) |
|
|
|
if not stats: |
|
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=os.listdir(realPath) |
dir=server.listdir(realPath) |
ret={} |
ret={} |
for filename in dir: |
for filename in dir: |
object=os.path.join(realPath,filename) |
object=os.path.join(realPath,filename) |
Line 281 class OSAS_storeOnline(SimpleItem):
|
Line 152 class OSAS_storeOnline(SimpleItem):
|
objects=self.readObjectsFromPath(path) |
objects=self.readObjectsFromPath(path) |
if not objects: |
if not objects: |
objects={} |
objects={} |
im=self.getSubDirsFromIndexMeta(path) |
|
|
server=xmlrpclib.Server(self.serverUrl) |
|
im=server.getSubDirsFromIndexMeta(path) |
for key in im.keys(): |
for key in im.keys(): |
#virtuelle pfade hinzufuegen |
#virtuelle pfade hinzufuegen |
|
|
Line 351 class OSAS_storeOnline(SimpleItem):
|
Line 224 class OSAS_storeOnline(SimpleItem):
|
@param path: Pfad des index.met |
@param path: Pfad des index.met |
@return: index.meta file |
@return: index.meta file |
""" |
""" |
tmp=OSAS_helpers.getMetaFile(self,path) |
server=xmlrpclib.Server(self.serverUrl) |
|
tmp=server.getMetaFile(path) |
#zLOG.LOG("EE",zLOG.INFO,type(tmp)) |
#zLOG.LOG("EE",zLOG.INFO,type(tmp)) |
|
|
return tmp |
return tmp |