Diff for /OSA_system2/OSAS_browser.py between versions 1.1 and 1.2

version 1.1, 2004/11/29 09:48:07 version 1.2, 2004/12/23 08:30:55
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
   
 class OSAS_storeOnline(SimpleItem):  class OSAS_storeOnline(SimpleItem):
     """Webfrontend für das Storagesystem      """Webfrontend für das Storagesystem
Line 31  class OSAS_storeOnline(SimpleItem): Line 32  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 40  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.
           """
   
           indexMeta=self.findIndexMeta(path)
           
           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:]
   
               
           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=""
   
           
               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,'')
   
   
           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)
           return OSAS_helpers.getMetaInfoFromXML(path,xmlInfos)
                   
         
   
     def readObjectsFromPath(self,path=""):      def readObjectsFromPath(self,path=""):
Line 46  class OSAS_storeOnline(SimpleItem): Line 170  class OSAS_storeOnline(SimpleItem):
          - to do: files aus metadaten           - 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 181  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)
   
Line 72  class OSAS_storeOnline(SimpleItem): Line 198  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 206  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, viewer 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 viewer in self.ZopeFind(self.aq_parent,obj_metatypes=['OSAS_ViewerObject__neu'],search_sub=1):
Line 93  class OSAS_storeOnline(SimpleItem): Line 224  class OSAS_storeOnline(SimpleItem):
                                               
                   
     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 256  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 298  class OSAS_storeOnline(SimpleItem):
   
     def getMetaFile(self,path):      def getMetaFile(self,path):
         """Lese Metafile ein"""          """Lese Metafile ein"""
         return OSAS_helpers.getMetaFile(path)          return OSAS_helpers.getMetaFile(self,path)
   
 InitializeClass(OSAS_storeOnline)  InitializeClass(OSAS_storeOnline)
           

Removed from v.1.1  
changed lines
  Added in v.1.2


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