Diff for /OSA_system2/OSAS_server.py between versions 1.2 and 1.13

version 1.2, 2005/02/10 20:23:24 version 1.13, 2005/03/07 19:33:42
Line 1 Line 1
 import os  import os
 import os.path  import os.path
 import stat  import stat
   import OSAS_helpers
   import xmlrpclib
   import bz2
   import base64
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile  from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from Globals import InitializeClass,package_home  from Globals import InitializeClass,package_home
 from OFS.SimpleItem import SimpleItem  from OFS.SimpleItem import SimpleItem
 import xml.dom.minidom  
 import OSAS_helpers  
 from OSAS_helpers import *  
   
 class OSAS_storeOnlineServer(SimpleItem):  def encodeRPC(string):
     """Server for store Online system"""      return base64.encodestring(bz2.compress(string))
           
     _v_metaFiles={} #chache fuer indexMeta  
     meta_type="OSAS_server"  
     def getSubDirsFromIndexMeta(self,path):  
                   
         """Gebe alle path untergeordenten Objekte aus  class OSAS_storeOnlineServer(SimpleItem):
         @param path: optional, default ist "", Pfad auf das Object relativ zum rootFolderName      """Server for store Online system"""
         @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={}  
         #server=xmlrpclib.Server(self.serverUrl)  
         indexMeta,stats=self.findIndexMetaWithStats(path)#findex index.meta zu path.  
   
         if not indexMeta:  
             return ret  
   
         realPath=os.path.split(indexMeta)[0]      meta_type="OSAS_server"
         path=path.replace(realPath,"")  
         if path and (path[0]==os.sep): #falls am Anfang os.sep steht lösche dieses.  
             path=path[1:]  
   
       def getImages(self,path):
           """hack"""
           imageEnding=['.gif','.jpg','.jpeg','.png','.tiff','.tif']
   
           dirs=os.listdir(path)
           ret=[]
   
         #teste ob schon im cache          for dir in dirs:
                   
         if self._v_metaFiles.has_key(path) and (self._v_metaFiles[path][0]==stats[stat.ST_MTIME]):              if os.path.isdir(os.path.join(path,dir)):
             return self._v_metaFiles[path][1]  
   
         try:                  for subdir in os.listdir(os.path.join(path,dir)):
             dom=xml.dom.minidom.parse(indexMeta)                      if os.path.splitext(subdir)[1].lower() in imageEnding:
         except:                          ret.append(os.path.join(dir,subdir))
             zLOG.LOG("OSAS_browser (getSubDirsFromIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta)              else:
                   if os.path.splitext(dir)[1] in imageEnding:
                           ret.append(os.path.join(dir))
             return ret              return ret
   
         dirs=[]  
         dirs=dom.getElementsByTagName('dir')+dom.getElementsByTagName('file')  
           
       def getMovies(self,path):
           """hack"""
           movieEnding=['.dv','.mov','.mp4']
           dirs=os.listdir(path)
           ret=[]
         for dir in dirs:          for dir in dirs:
             pathes=dir.getElementsByTagName('path')              if os.path.isdir(os.path.join(path,dir)):
             if pathes:                  for subdir in os.listdir(os.path.join(path,dir)):
                 pathX=OSAS_helpers.getText(pathes[0].childNodes)                      if os.path.splitext(subdir)[1].lower() in movieEnding:
             else:                          ret.append(os.path.join(dir,subdir))
                 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:                  else:
                     fileType="OSAS_file_archive"                  if os.path.splitext(dir)[1] in movieEnding:
                           ret.append(os.path.join(dir))
                 object=os.path.join(realPath,pathX,name)  
                 ret[object.encode('utf-8')]=(fileType,'')  
   
         self._v_metaFiles[path]=(stats[stat.ST_MTIME],ret) # speicher im chache  
         
         return ret          return ret
   
                   
     
     def findIndexMeta(self,realPath=""):      def findIndexMeta(self,realPath=""):
         """finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file          """finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file
         @keyword path: default ist "", Pfad auf das Object          @keyword path: default ist "", Pfad auf das Object
Line 125  class OSAS_storeOnlineServer(SimpleItem) Line 104  class OSAS_storeOnlineServer(SimpleItem)
         """list dir"""          """list dir"""
         return os.listdir(path)          return os.listdir(path)
   
       def isdir(self,path=""):
           """list dir"""
           return os.path.isdir(path)
   
     def getMetaFile(self,path):      def isfile(self,path=""):
         """get index.meta and translate it to HTML"""          """list dir"""
         html=[]          return os.path.isfile(path)
                   
         if not os.path.exists(path+"/index.meta"):  
                               
               return self.getMetaInfoFromIndexMeta(path)  
               #return "NO_METADATA"  
         else:  
                         
            f = os.popen("cat "+path+"/index.meta","r")      def getFile(self,path):
            lines = f.read()          """getFile"""
                         
            dom = xml.dom.minidom.parseString(lines)          if not os.path.exists(path):
            try:              return None
                name=getText(dom.getElementsByTagName("name")[0].childNodes)  
            except:  
                name="NOT_DEFINED!!!"  
            try:  
                creator=getText(dom.getElementsByTagName("creator")[0].childNodes)  
            except:  
                creator="NOT_DEFINED!!!"  
   
            try:  
                creation_date=getText(dom.getElementsByTagName("archive-creation-date")[0].childNodes)  
            except:  
                creation_date="NOT_DEFINED!!!"  
   
            try:  
                description=getText(dom.getElementsByTagName("description")[0].childNodes)  
            except:  
                description="NOT_DEFINED!!!"  
   
            try:  
             type=getText(dom.getElementsByTagName("content-type")[0].childNodes)   
            except:  
             type=""  
            if type=="scanned document":  
                     html="<h3>Document: "+name+"</h3>"  
            elif type=="folder":  
                     html="<h3>Folder: "+name+"</h3>"  
            else:  
                     html="<h3>Document: "+name+"</h3>"  
   
            html=html+"<p><i>created by: "+creator+" at: "+creation_date+"</i></p>"           f=file(path,'r')
            html=html+"<h4>Description</h4><p>"+description+"</p>"  
            try:  
             bib = dom.getElementsByTagName("meta")[0].getElementsByTagName("bib")[0]  
             if bib.attributes.has_key('type'):  
               html=html+"<h4>Info ("+bib.attributes['type'].value+")</h4>"  
             else:  
               html=html+"<h4>Info</h4>"  
             html=html+getBib(bib.childNodes)  
   
            except:          ret=f.read()
             """none"""  
   
     #        html=html.encode('utf-8','replace')+getBib(bib.childNodes).encode('utf-8','replace')          f.close()
   
            return html  
   
           return ret
   
     def getMetaInfoFromIndexMeta(self,path):      def getAllIndexMetasOfSubDirs(self,path):
         """metadaten zu path als html aus dem index.meta file zu path (meta tag im file bzw. dir container)          """get all index Metas"""
         @param path: Pfad auf das Object relativ zum rootFolderName          ret={}
         @return: metadata als html          if os.path.exists(path+"/index.meta"):
         """              compressed=encodeRPC(file(path+"/index.meta","r").read())
         xmlInfos=self.findEntryInIndexMeta(path)              ret["."]=('OSAS_dir',compressed)
         if xmlInfos:          for dir in os.listdir(path):
             return OSAS_helpers.getMetaInfoFromXML(path,xmlInfos)              fileType=OSAS_helpers.checkOSASFileType(os.path.join(path,dir))
               if os.path.exists(os.path.join(path,dir,"index.meta")):
                   compressed=encodeRPC(file(os.path.join(path,dir,"index.meta"),"r").read())
                   ret[dir]=('OSAS_dir',compressed)
         else:          else:
             return ""                  ret[dir]=(fileType,None)
              return ret
     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(path)  
   
       def writeMetaDataFile(self,path,metadata):
           """writefiletoserver"""
         try:          try:
             dom=xml.dom.minidom.parse(indexMeta)              fh=file(path,"w")
               fh.write(metadata)
               fh.close
               return True
         except:          except:
             zLOG.LOG("OSAS_browser (findEntryInIndexMeta)",zLOG.ERROR,"Cannot parse: %s"%indexMeta)              return False
         #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 manage_addOSAS_storeOnlineServerForm(self):  def manage_addOSAS_storeOnlineServerForm(self):

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


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