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