File:  [Repository] / OSA_system2 / OSAS_server.py
Revision 1.6: download - view: text, annotated - select for diffs - revision graph
Fri Feb 11 20:06:57 2005 UTC (19 years, 4 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
server optimization in progress

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

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