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