File:  [Repository] / OSA_system2 / OSAS_server.py
Revision 1.10: download - view: text, annotated - select for diffs - revision graph
Mon Feb 14 18:15:16 2005 UTC (19 years, 3 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
minor

    1: import os
    2: import os.path
    3: import stat
    4: import OSAS_helpers
    5: import xmlrpclib
    6: import bz2
    7: import base64
    8: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
    9: from Globals import InitializeClass,package_home
   10: from OFS.SimpleItem import SimpleItem
   11: 
   12: def encodeRPC(string):
   13:     return base64.encodestring(bz2.compress(string))
   14: 
   15: 
   16: class OSAS_storeOnlineServer(SimpleItem):
   17:     """Server for store Online system"""
   18:     
   19:     
   20:     meta_type="OSAS_server"
   21: 
   22:   
   23:     def findIndexMeta(self,realPath=""):
   24:         """finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file
   25:         @keyword path: default ist "", Pfad auf das Object
   26:         @return: None falls kein index.meta existiert sonst Pfad auf das index.meta
   27:         """
   28:         
   29:         #suche index.meta
   30:         while (not os.path.exists(os.path.join(realPath,'index.meta'))) and (not ((realPath=="") or (realPath=="/"))):
   31:             realPath=os.path.split(realPath)[0]
   32:             
   33:         if realPath=='' or realPath=='/':
   34:             if os.path.exists(os.path.join(realPath,'index.meta')):
   35:                 return (os.path.join(realPath,'index.meta'))
   36:             else:
   37:                 return None
   38:         else:
   39:             return os.path.join(realPath,'index.meta')
   40: 
   41:     def findIndexMetaWithStats(self,path=""):
   42:         """finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file
   43:         @keyword path: default ist "", Pfad auf das Object
   44:         @return: None falls kein index.meta existiert sonst Tupel (Pfad auf das index.meta,stats(indexMeta)
   45:         """
   46: 
   47:         indexMeta=self.findIndexMeta(path)
   48:         if indexMeta:
   49:             return (indexMeta,self.getStat(indexMeta))
   50:         else:
   51:             return (None,[])
   52: 
   53: 
   54:     def getStat(self,path=""):
   55:         """Gibt stat von path aus
   56:         @keyword path: default ist "", Pfad
   57:         @return: stat[path]"""
   58: 
   59:         if not os.path.exists(path):
   60:             #return None,"(ERROR) path %s does not exist."%path
   61:             return None
   62:         else:
   63:             return [x for x in os.stat(path)]
   64:             
   65:             
   66:             
   67: 
   68:     def listdir(self,path=""):
   69:         """list dir"""
   70:         return os.listdir(path)
   71: 
   72:     def isdir(self,path=""):
   73:         """list dir"""
   74:         return os.path.isdir(path)
   75: 
   76:     def isfile(self,path=""):
   77:         """list dir"""
   78:         return os.path.isfile(path)
   79: 
   80: 
   81: 
   82:     def getFile(self,path):
   83:         """getFile"""
   84: 
   85:         if not os.path.exists(path):
   86:             return None
   87: 
   88:         f=file(path,'r')
   89:         
   90:         ret=f.read()
   91: 
   92:         f.close()
   93:         
   94:         return ret
   95: 
   96:     def getAllIndexMetasOfSubDirs(self,path):
   97:         """get all index Metas"""
   98:         ret={}
   99:         if os.path.exists(path+"/index.meta"):
  100:             compressed=encodeRPC(file(path+"/index.meta","r").read())
  101:             ret["."]=('OSAS_dir',compressed)
  102:         for dir in os.listdir(path):
  103:             fileType=OSAS_helpers.checkOSASFileType(os.path.join(path,dir))
  104:             if os.path.exists(os.path.join(path,dir,"index.meta")):
  105:                 compressed=encodeRPC(file(os.path.join(path,dir,"index.meta"),"r").read())
  106:                 ret[dir]=('OSAS_dir',compressed)
  107:             else:
  108:                 ret[dir]=(fileType,None)
  109:         return ret
  110: 
  111:                               
  112:         
  113: def manage_addOSAS_storeOnlineServerForm(self):
  114:     """interface for adding the OSAS_storeOnline"""
  115:     pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addStoreOnlineServer.zpt')).__of__(self)
  116:     return pt()
  117: 
  118: def manage_addOSAS_storeOnlineServer(self,id,RESPONSE=None):
  119:     """add the OSAS_storeOnline
  120:     @param id: id
  121:     """
  122:     newObj=OSAS_storeOnlineServer(id)
  123:     self._setObject(id,newObj)
  124:     if RESPONSE is not None:
  125:         RESPONSE.redirect('manage_main')
  126: 

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