1: import os
2: import os.path
3: import stat
4: import OSAS_helpers
5: import bz2
6: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
7: from Globals import InitializeClass,package_home
8: from OFS.SimpleItem import SimpleItem
9:
10:
11:
12:
13: class OSAS_storeOnlineServer(SimpleItem):
14: """Server for store Online system"""
15:
16:
17: meta_type="OSAS_server"
18:
19:
20: def findIndexMeta(self,realPath=""):
21: """finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file
22: @keyword path: default ist "", Pfad auf das Object
23: @return: None falls kein index.meta existiert sonst Pfad auf das index.meta
24: """
25:
26: #suche index.meta
27: while (not os.path.exists(os.path.join(realPath,'index.meta'))) and (not ((realPath=="") or (realPath=="/"))):
28: realPath=os.path.split(realPath)[0]
29:
30: if realPath=='' or realPath=='/':
31: if os.path.exists(os.path.join(realPath,'index.meta')):
32: return (os.path.join(realPath,'index.meta'))
33: else:
34: return None
35: else:
36: return os.path.join(realPath,'index.meta')
37:
38: def findIndexMetaWithStats(self,path=""):
39: """finde Rueckwaerts im Baum von Pfad ausgehend, dass erste index.meta file
40: @keyword path: default ist "", Pfad auf das Object
41: @return: None falls kein index.meta existiert sonst Tupel (Pfad auf das index.meta,stats(indexMeta)
42: """
43:
44: indexMeta=self.findIndexMeta(path)
45: if indexMeta:
46: return (indexMeta,self.getStat(indexMeta))
47: else:
48: return (None,[])
49:
50:
51: def getStat(self,path=""):
52: """Gibt stat von path aus
53: @keyword path: default ist "", Pfad
54: @return: stat[path]"""
55:
56: if not os.path.exists(path):
57: #return None,"(ERROR) path %s does not exist."%path
58: return None
59: else:
60: return [x for x in os.stat(path)]
61:
62:
63:
64:
65: def listdir(self,path=""):
66: """list dir"""
67: return os.listdir(path)
68:
69: def isdir(self,path=""):
70: """list dir"""
71: return os.path.isdir(path)
72:
73: def isfile(self,path=""):
74: """list dir"""
75: return os.path.isfile(path)
76:
77:
78:
79: def getFile(self,path):
80: """getFile"""
81:
82: if not os.path.exists(path):
83: return None
84:
85: f=file(path,'r')
86:
87: ret=f.read()
88:
89: f.close()
90:
91: return ret
92:
93: def getAllIndexMetasOfSubDirs(self,path):
94: """get all index Metas"""
95: ret={}
96: if os.path.exists(path+"/index.meta"):
97: ret["."]=file(path+"/index.meta","r").read()
98: for dir in os.listdir(path):
99: fileType=OSAS_helpers.checkOSASFileType(os.path.join(path,dir))
100: if os.path.exists(os.path.join(path,dir,"index.meta")):
101: ret[dir]=('OSAS_dir',file(os.path.join(path,dir,"index.meta"),"r").read())
102: else:
103: ret[dir]=(fileType,None)
104: return return bz2.compress(ret)
105:
106:
107:
108: def manage_addOSAS_storeOnlineServerForm(self):
109: """interface for adding the OSAS_storeOnline"""
110: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addStoreOnlineServer.zpt')).__of__(self)
111: return pt()
112:
113: def manage_addOSAS_storeOnlineServer(self,id,RESPONSE=None):
114: """add the OSAS_storeOnline
115: @param id: id
116: """
117: newObj=OSAS_storeOnlineServer(id)
118: self._setObject(id,newObj)
119: if RESPONSE is not None:
120: RESPONSE.redirect('manage_main')
121:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>