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

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