File:  [Repository] / OSA_system2 / OSAS_server.py
Revision 1.21: download - view: text, annotated - select for diffs - revision graph
Wed Jan 31 14:30:29 2007 UTC (17 years, 5 months ago) by dwinter
Branches: MAIN
CVS tags: HEAD
zlog ersetzt durch logging

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

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