import os import os.path import stat import OSAS_helpers import bz2 from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Globals import InitializeClass,package_home from OFS.SimpleItem import SimpleItem class OSAS_storeOnlineServer(SimpleItem): """Server for store Online system""" meta_type="OSAS_server" def findIndexMeta(self,realPath=""): """finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file @keyword path: default ist "", Pfad auf das Object @return: None falls kein index.meta existiert sonst Pfad auf das index.meta """ #suche index.meta while (not os.path.exists(os.path.join(realPath,'index.meta'))) and (not ((realPath=="") or (realPath=="/"))): realPath=os.path.split(realPath)[0] if realPath=='' or realPath=='/': if os.path.exists(os.path.join(realPath,'index.meta')): return (os.path.join(realPath,'index.meta')) else: return None else: return os.path.join(realPath,'index.meta') def findIndexMetaWithStats(self,path=""): """finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file @keyword path: default ist "", Pfad auf das Object @return: None falls kein index.meta existiert sonst Tupel (Pfad auf das index.meta,stats(indexMeta) """ indexMeta=self.findIndexMeta(path) if indexMeta: return (indexMeta,self.getStat(indexMeta)) else: return (None,[]) def getStat(self,path=""): """Gibt stat von path aus @keyword path: default ist "", Pfad @return: stat[path]""" if not os.path.exists(path): #return None,"(ERROR) path %s does not exist."%path return None else: return [x for x in os.stat(path)] def listdir(self,path=""): """list dir""" return os.listdir(path) def isdir(self,path=""): """list dir""" return os.path.isdir(path) def isfile(self,path=""): """list dir""" return os.path.isfile(path) def getFile(self,path): """getFile""" if not os.path.exists(path): return None f=file(path,'r') ret=f.read() f.close() return ret def getAllIndexMetasOfSubDirs(self,path): """get all index Metas""" ret={} if os.path.exists(path+"/index.meta"): ret["."]=file(path+"/index.meta","r").read() for dir in os.listdir(path): fileType=OSAS_helpers.checkOSASFileType(os.path.join(path,dir)) if os.path.exists(os.path.join(path,dir,"index.meta")): ret[dir]=('OSAS_dir',file(os.path.join(path,dir,"index.meta"),"r").read()) else: ret[dir]=(fileType,None) return return bz2.compress(ret) def manage_addOSAS_storeOnlineServerForm(self): """interface for adding the OSAS_storeOnline""" pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addStoreOnlineServer.zpt')).__of__(self) return pt() def manage_addOSAS_storeOnlineServer(self,id,RESPONSE=None): """add the OSAS_storeOnline @param id: id """ newObj=OSAS_storeOnlineServer(id) self._setObject(id,newObj) if RESPONSE is not None: RESPONSE.redirect('manage_main')