File:  [Repository] / OSA_system2 / OSAS_server.py
Revision 1.13: download - view: text, annotated - select for diffs - revision graph
Mon Mar 7 19:33:42 2005 UTC (19 years, 3 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
new handlers

    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:     def getImages(self,path):
   23:         """hack"""
   24:         imageEnding=['.gif','.jpg','.jpeg','.png','.tiff','.tif']
   25: 
   26:         dirs=os.listdir(path)
   27:         ret=[]
   28: 
   29:         for dir in dirs:
   30: 
   31:             if os.path.isdir(os.path.join(path,dir)):
   32:                 
   33:                 for subdir in os.listdir(os.path.join(path,dir)):
   34:                     if os.path.splitext(subdir)[1].lower() in imageEnding:
   35:                         ret.append(os.path.join(dir,subdir))
   36:             else:
   37:                 if os.path.splitext(dir)[1] in imageEnding:
   38:                         ret.append(os.path.join(dir))
   39:         return ret
   40:     
   41: 
   42:     def getMovies(self,path):
   43:         """hack"""
   44:         movieEnding=['.dv','.mov','.mp4']
   45:         dirs=os.listdir(path)
   46:         ret=[]
   47:         for dir in dirs:
   48:             if os.path.isdir(os.path.join(path,dir)):
   49:                 for subdir in os.listdir(os.path.join(path,dir)):
   50:                     if os.path.splitext(subdir)[1].lower() in movieEnding:
   51:                         ret.append(os.path.join(dir,subdir))
   52:             else:
   53:                 if os.path.splitext(dir)[1] in movieEnding:
   54:                         ret.append(os.path.join(dir))
   55:         return ret
   56:     
   57:        
   58:     def findIndexMeta(self,realPath=""):
   59:         """finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file
   60:         @keyword path: default ist "", Pfad auf das Object
   61:         @return: None falls kein index.meta existiert sonst Pfad auf das index.meta
   62:         """
   63:         
   64:         #suche index.meta
   65:         while (not os.path.exists(os.path.join(realPath,'index.meta'))) and (not ((realPath=="") or (realPath=="/"))):
   66:             realPath=os.path.split(realPath)[0]
   67:             
   68:         if realPath=='' or realPath=='/':
   69:             if os.path.exists(os.path.join(realPath,'index.meta')):
   70:                 return (os.path.join(realPath,'index.meta'))
   71:             else:
   72:                 return None
   73:         else:
   74:             return os.path.join(realPath,'index.meta')
   75: 
   76:     def findIndexMetaWithStats(self,path=""):
   77:         """finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file
   78:         @keyword path: default ist "", Pfad auf das Object
   79:         @return: None falls kein index.meta existiert sonst Tupel (Pfad auf das index.meta,stats(indexMeta)
   80:         """
   81: 
   82:         indexMeta=self.findIndexMeta(path)
   83:         if indexMeta:
   84:             return (indexMeta,self.getStat(indexMeta))
   85:         else:
   86:             return (None,[])
   87: 
   88: 
   89:     def getStat(self,path=""):
   90:         """Gibt stat von path aus
   91:         @keyword path: default ist "", Pfad
   92:         @return: stat[path]"""
   93: 
   94:         if not os.path.exists(path):
   95:             #return None,"(ERROR) path %s does not exist."%path
   96:             return None
   97:         else:
   98:             return [x for x in os.stat(path)]
   99:             
  100:             
  101:             
  102: 
  103:     def listdir(self,path=""):
  104:         """list dir"""
  105:         return os.listdir(path)
  106: 
  107:     def isdir(self,path=""):
  108:         """list dir"""
  109:         return os.path.isdir(path)
  110: 
  111:     def isfile(self,path=""):
  112:         """list dir"""
  113:         return os.path.isfile(path)
  114: 
  115: 
  116: 
  117:     def getFile(self,path):
  118:         """getFile"""
  119: 
  120:         if not os.path.exists(path):
  121:             return None
  122: 
  123:         f=file(path,'r')
  124:         
  125:         ret=f.read()
  126: 
  127:         f.close()
  128:         
  129:         return ret
  130: 
  131:     def getAllIndexMetasOfSubDirs(self,path):
  132:         """get all index Metas"""
  133:         ret={}
  134:         if os.path.exists(path+"/index.meta"):
  135:             compressed=encodeRPC(file(path+"/index.meta","r").read())
  136:             ret["."]=('OSAS_dir',compressed)
  137:         for dir in os.listdir(path):
  138:             fileType=OSAS_helpers.checkOSASFileType(os.path.join(path,dir))
  139:             if os.path.exists(os.path.join(path,dir,"index.meta")):
  140:                 compressed=encodeRPC(file(os.path.join(path,dir,"index.meta"),"r").read())
  141:                 ret[dir]=('OSAS_dir',compressed)
  142:             else:
  143:                 ret[dir]=(fileType,None)
  144:         return ret
  145: 
  146:     def writeMetaDataFile(self,path,metadata):
  147:         """writefiletoserver"""
  148:         try:
  149:             fh=file(path,"w")
  150:             fh.write(metadata)
  151:             fh.close
  152:             return True
  153:         except:
  154:             return False
  155:     
  156:         
  157: def manage_addOSAS_storeOnlineServerForm(self):
  158:     """interface for adding the OSAS_storeOnline"""
  159:     pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addStoreOnlineServer.zpt')).__of__(self)
  160:     return pt()
  161: 
  162: def manage_addOSAS_storeOnlineServer(self,id,RESPONSE=None):
  163:     """add the OSAS_storeOnline
  164:     @param id: id
  165:     """
  166:     newObj=OSAS_storeOnlineServer(id)
  167:     self._setObject(id,newObj)
  168:     if RESPONSE is not None:
  169:         RESPONSE.redirect('manage_main')
  170: 

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