Diff for /OSA_system2/OSAS_browser.py between versions 1.1.1.1 and 1.6

version 1.1.1.1, 2004/11/29 09:48:07 version 1.6, 2004/12/23 16:31:22
Line 12  import zLOG Line 12  import zLOG
 import os  import os
 import os.path  import os.path
 import stat  import stat
   import xml.dom.minidom
   from types import *
   
 class OSAS_storeOnline(SimpleItem):  class OSAS_storeOnline(SimpleItem):
     """Webfrontend für das Storagesystem      """Webfrontend für das Storagesystem
Line 22  class OSAS_storeOnline(SimpleItem): Line 24  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):
         """initialize a new instance"""          """initialize a new instance"""
Line 31  class OSAS_storeOnline(SimpleItem): Line 34  class OSAS_storeOnline(SimpleItem):
   
     security.declareProtected('View','index_html')      security.declareProtected('View','index_html')
     def index_html(self):      def index_html(self):
         """main view either standard template or storeOnline_index.html in tree"""          """main view either standard template zpt/storeOnline_index_html.zpt or storeOnline_index.html in tree"""
         if hasattr(self,'storeOnline_index.html'):          if hasattr(self,'storeOnline_index.html'):
             return getattr(self,'storeOnline_index.html')()              return getattr(self,'storeOnline_index.html')()
         else:          else:
Line 39  class OSAS_storeOnline(SimpleItem): Line 42  class OSAS_storeOnline(SimpleItem):
             return pt()              return pt()
   
   
       def findIndexMeta(self,path=""):
           """finde index_meta fuer diesen eventuell virtuellen Pfad
           @param path: optional, default ist "", Pfad auf das Object relativ zum rootFolderName
           @return: None falls kein index.meta existiert sonst Pfad auf das index.meta
           """
           realPath=os.path.normpath(os.path.join(self.rootFolderName,path))
           #suche index.meta
           while (not os.path.exists(os.path.join(realPath,'index.meta'))) and (not ((realPath=="") or (realPath=="/"))):
               realPath=os.path.split(realPath)[0]
           if realPath=='' or realPath=='/':
               return None
           else:
               return os.path.join(realPath,'index.meta')
   
       def findEntryInIndexMeta(self,path):
           """fragm xml zum path
           @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)
           if not indexMeta:
               return None
           realPath=os.path.split(indexMeta)[0]
           path=os.path.normpath(os.path.join(self.rootFolderName,path))
           
           dom=xml.dom.minidom.parse(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.
           """
           ret={}
           indexMeta=self.findIndexMeta(path)
           if not indexMeta:
               return ret
           realPath=os.path.split(indexMeta)[0]
           path=path.replace(realPath,"")
           if path and (path[0]==os.sep):
               path=path[1:]
   
           stats=os.stat(indexMeta)
   
           #teste ob schon im cache
           if self._v_metaFiles.has_key(path) and (self._v_metaFiles[path][0]==stats[stat.ST_MTIME]):
               #print "cache",path
               return self._v_metaFiles[path][1]
   
           dom=xml.dom.minidom.parse(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
           @param path: optional, default ist "", 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=""):      def readObjectsFromPath(self,path=""):
         """Liest files aus dem path und speichert im cache _v_filesystem.          """Liest files aus dem path und speichert im cache _v_filesystem.
          - to do: files aus metadaten  
   
         @param path : path relativ zum root folder des Storagesystems          @param path : path relativ zum root folder des Storagesystems
           @return: directory der Form [pfad zum Objekt] -> (fileType,metadatum als String)
         """          """
                                                 
         realPath=os.path.normpath(os.path.join(self.rootFolderName,path))          realPath=os.path.normpath(os.path.join(self.rootFolderName,path))
Line 56  class OSAS_storeOnline(SimpleItem): Line 191  class OSAS_storeOnline(SimpleItem):
                           
                   
         if not os.path.exists(realPath):          if not os.path.exists(realPath):
             return None,"(ERROR) path %s does not exist."%path              #return None,"(ERROR) path %s does not exist."%path
               return None
   
         stats=os.stat(realPath)          stats=os.stat(realPath)
   
         # 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=os.listdir(realPath)
         ret={}          ret={}
Line 72  class OSAS_storeOnline(SimpleItem): Line 208  class OSAS_storeOnline(SimpleItem):
             fileType=OSAS_helpers.checkOSASFileType(object)              fileType=OSAS_helpers.checkOSASFileType(object)
                           
             if fileType:              if fileType:
                   
                 ret[object]=(fileType,metaData.getDisplayFieldsAsStr(object))                  ret[object]=(fileType,metaData.getDisplayFieldsAsStr(object))
                           
         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 79  class OSAS_storeOnline(SimpleItem): Line 216  class OSAS_storeOnline(SimpleItem):
         return ret          return ret
   
     def giveHandlers(self,path,type):      def giveHandlers(self,path,type):
         """teste ob für diese Typ, viewer definiert sind"""          """teste ob fuer diesen Typ, handler definiert sind und gibt einen entsprechenden Link zurueck, der das Object mit diesem Handler ausfuehrt.
           @param path: Pfad auf das Objekt
           @param type: Typ des Objektes
           @return: (string) html-Fragment, link der das Objekt mit diesem Handler anzeigt.
           """
         ret=[]          ret=[]
                   
         for viewer in self.ZopeFind(self.aq_parent,obj_metatypes=['OSAS_ViewerObject__neu'],search_sub=1):          for handler in self.ZopeFind(self.aq_parent,obj_metatypes=['OSAS_HandlerObject__neu'],search_sub=1):
             if type in viewer[1].objectTypes:              if type in handler[1].objectTypes:
                 path=path.replace(getattr(viewer[1],'ignorePath',''),'')          try:
                 url=viewer[1].prefix%path                   path=path.replace(getattr(handler[1],'ignorePath',''),'')
                 text=viewer[1].title                  except:
              pass
                   url=handler[1].prefix%path
                   text=handler[1].title
                 string="""<a target="_blank" href="%s">%s</a>"""%(url,text)                  string="""<a target="_blank" href="%s">%s</a>"""%(url,text)
                 ret.append(string)                  ret.append(string)
         return ret          return ret
                                               
                   
     def generateTree(self,path=""):      def generateTree(self,path=""):
         """erzeuge navigations elemente"""          """erzeuge liest die Objekte aus die im Pfad gespeichert sind
           @param path: optional mit default='', Pfad relativ zu rootFolderName
           @return: List von Tripeln, (link_html,array of handlers,metainformationen) hierbei ist
           - (string) link_html ein html-Fragement, falls das Objekt vom Typ OSAS_dir ist, ist dies ein Link auf dieses Verzeichnis, sonst der Dateiname
           - (string) handler sind die Ergebnisse von giveHandlers fuer dieses Objekt
           - (string) metainformationen die Metainformationen zum Objekt als Ergebnis von readObjectsFromPath
           """
         objects=self.readObjectsFromPath(path)          objects=self.readObjectsFromPath(path)
           if not objects:
               objects={}
           im=self.getSubDirsFromIndexMeta(path)
           for key in im.keys():
               #virtuelle pfade hinzufuegen
               
               if not objects.has_key(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 109  class OSAS_storeOnline(SimpleItem): Line 269  class OSAS_storeOnline(SimpleItem):
                 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])
                                   
                 ret.append((string,handler,objects[object][1]))                  ret.append((string,handler,objects[object][1]))
               elif objects[object][0]=="OSAS_dir_archive":
                   string="""<a href="?path=%s">%s (A)</a>"""%(object,os.path.split(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 147  class OSAS_storeOnline(SimpleItem): Line 311  class OSAS_storeOnline(SimpleItem):
   
     def getMetaFile(self,path):      def getMetaFile(self,path):
         """Lese Metafile ein"""          """Lese Metafile ein"""
         return OSAS_helpers.getMetaFile(path)          tmp=OSAS_helpers.getMetaFile(self,path)
           #zLOG.LOG("EE",zLOG.INFO,type(tmp))
           
           return tmp
   
 InitializeClass(OSAS_storeOnline)  InitializeClass(OSAS_storeOnline)
           

Removed from v.1.1.1.1  
changed lines
  Added in v.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>