File:  [Repository] / OSA_system2 / OSAS_server.py
Revision 1.16: download - view: text, annotated - select for diffs - revision graph
Mon Oct 10 18:11:11 2005 UTC (18 years, 7 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
untabified

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

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