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