Annotation of OSA_system2/OSAS_browser.py, revision 1.1
1.1 ! dwinter 1: """ Classes for displaying, browsing and organizing the archive
! 2: """
! 3:
! 4:
! 5: import OSAS_helpers
! 6: from AccessControl import ClassSecurityInfo
! 7: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
! 8: from OFS.Folder import Folder
! 9: from OFS.SimpleItem import SimpleItem
! 10: from Globals import InitializeClass,package_home
! 11: import zLOG
! 12: import os
! 13: import os.path
! 14: import stat
! 15:
! 16: class OSAS_storeOnline(SimpleItem):
! 17: """Webfrontend für das Storagesystem
! 18: liefert Browserumgebung
! 19: """
! 20: meta_type="OSAS_StoreOnline__neu"
! 21:
! 22: security=ClassSecurityInfo()
! 23:
! 24: _v_fileSystem={} #chache fuer filesystem
! 25:
! 26: def __init__(self,id):
! 27: """initialize a new instance"""
! 28: self.id = id
! 29:
! 30:
! 31:
! 32: security.declareProtected('View','index_html')
! 33: def index_html(self):
! 34: """main view either standard template or storeOnline_index.html in tree"""
! 35: if hasattr(self,'storeOnline_index.html'):
! 36: return getattr(self,'storeOnline_index.html')()
! 37: else:
! 38: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','storeOnline_index_html.zpt')).__of__(self)
! 39: return pt()
! 40:
! 41:
! 42:
! 43:
! 44: def readObjectsFromPath(self,path=""):
! 45: """Liest files aus dem path und speichert im cache _v_filesystem.
! 46: - to do: files aus metadaten
! 47:
! 48: @param path : path relativ zum root folder des Storagesystems
! 49: """
! 50:
! 51: realPath=os.path.normpath(os.path.join(self.rootFolderName,path))
! 52: metaData=self.testmd #test
! 53:
! 54: if realPath.find(self.rootFolderName) <0: #versuch auf Pfad unterhalb des Rootfolder zuzugreifen
! 55: return {}
! 56:
! 57:
! 58: if not os.path.exists(realPath):
! 59: return None,"(ERROR) path %s does not exist."%path
! 60:
! 61: stats=os.stat(realPath)
! 62:
! 63: # teste ob schon im cache
! 64: #if self._v_fileSystem.has_key(realPath) and (self._v_fileSystem[realPath][0]==stats[stat.ST_MTIME]):
! 65:
! 66: # return self._v_fileSystem[realPath][1]
! 67:
! 68: dir=os.listdir(realPath)
! 69: ret={}
! 70: for filename in dir:
! 71: object=os.path.join(realPath,filename)
! 72: fileType=OSAS_helpers.checkOSASFileType(object)
! 73:
! 74: if fileType:
! 75: ret[object]=(fileType,metaData.getDisplayFieldsAsStr(object))
! 76:
! 77: self._v_fileSystem[realPath]=(stats[stat.ST_MTIME],ret) # speicher im chache
! 78:
! 79: return ret
! 80:
! 81: def giveHandlers(self,path,type):
! 82: """teste ob für diese Typ, viewer definiert sind"""
! 83: ret=[]
! 84:
! 85: for viewer in self.ZopeFind(self.aq_parent,obj_metatypes=['OSAS_ViewerObject__neu'],search_sub=1):
! 86: if type in viewer[1].objectTypes:
! 87: path=path.replace(getattr(viewer[1],'ignorePath',''),'')
! 88: url=viewer[1].prefix%path
! 89: text=viewer[1].title
! 90: string="""<a target="_blank" href="%s">%s</a>"""%(url,text)
! 91: ret.append(string)
! 92: return ret
! 93:
! 94:
! 95: def generateTree(self,path=""):
! 96: """erzeuge navigations elemente"""
! 97: objects=self.readObjectsFromPath(path)
! 98: def sortLow(x,y):
! 99: return cmp(x.lower(),y.lower())
! 100:
! 101: ret=[]
! 102:
! 103: objectSorted=objects.keys()
! 104: objectSorted.sort(sortLow)
! 105: for object in objectSorted:
! 106: handler=self.giveHandlers(object,objects[object][0])
! 107: if objects[object][0]=="OSAS_dir":
! 108:
! 109: string="""<a href="?path=%s">%s</a>"""%(object,os.path.split(object)[1])
! 110:
! 111: ret.append((string,handler,objects[object][1]))
! 112: else:
! 113: ret.append((os.path.split(object)[1],handler,objects[object][1]))
! 114:
! 115:
! 116: return ret
! 117:
! 118:
! 119: def path_to_link(self,pathTmp=""):
! 120: """generates navigation bar for viewfiles"""
! 121:
! 122: path=os.path.normpath(os.path.join(self.rootFolderName,pathTmp))
! 123:
! 124: URL=self.absolute_url()
! 125: string=""
! 126:
! 127: tmppath=os.path.dirname(path)
! 128: i=0
! 129: pathes=[[path, os.path.basename(path)]]
! 130:
! 131: while not (len(tmppath)==1):
! 132:
! 133: i=i+1
! 134: if i>20: break
! 135:
! 136: pathes.append([tmppath, os.path.basename(tmppath)])
! 137: tmppath=os.path.dirname(tmppath)
! 138:
! 139: while i>=0:
! 140: if pathes[i][0].find(self.rootFolderName) <0: #versuch auf Pfad unterhalb des Rootfolder zuzugreifen
! 141: string=string+"<a>"+pathes[i][1]+"</a>/"
! 142: else:
! 143: string=string+"<a href="+URL+"?path="+pathes[i][0]+">"+pathes[i][1]+"</a>/"
! 144:
! 145: i=i-1
! 146: return string
! 147:
! 148: def getMetaFile(self,path):
! 149: """Lese Metafile ein"""
! 150: return OSAS_helpers.getMetaFile(path)
! 151:
! 152: InitializeClass(OSAS_storeOnline)
! 153:
! 154: def manage_addOSAS_storeOnlineForm(self):
! 155: """interface for adding the OSAS_root"""
! 156: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addStoreOnline.zpt')).__of__(self)
! 157: return pt()
! 158:
! 159: def manage_addOSAS_storeOnline(self,id,RESPONSE=None):
! 160: """add the OSAS_root"""
! 161: newObj=OSAS_storeOnline(id)
! 162: self._setObject(id,newObj)
! 163: if RESPONSE is not None:
! 164: RESPONSE.redirect('manage_main')
! 165:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>