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