1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import string
26 import datetime
27 import time
28
29 from omero.rtypes import *
30 from omero.model import ImageI, DatasetI, ProjectI
31
32 from webclient.controller import BaseController
33
35
36 shares = None
37 shSize = None
38 ownShares = None
39 oshSize = 0
40 memberShares = None
41 mshSize = 0
42
43 share = None
44 imageInShare = None
45 imgSize = 0
46 membersInShare = None
47
48 comments = None
49 cmSize = None
50
51 - def __init__(self, conn, conn_share=None, share_id=None, **kw):
52 BaseController.__init__(self, conn)
53 if conn_share is None:
54 if share_id is not None:
55 self.share = self.conn.getShare(share_id)
56 if self.share is None:
57 raise AttributeError("We are sorry, but that share either does not exist, or if it does, you have not been invited to see it. Contact the user you think might own this share for more information.")
58 if self.share._obj is None:
59 raise AttributeError("We are sorry, but that share either does not exist, or if it does, you have not been invited to see it. Contact the user you think might own this share for more information.")
60 if self.share is not None and not self.share.active and not self.share.isOwned():
61 raise AttributeError("%s is not active and cannot be visible. Please contact the user you think might own this share for more information." % self.share.getShareType())
62 else:
63 self.conn_share = conn_share
64 self.share = self.conn.getShare(share_id)
65 if self.share is not None and not self.share.active and not self.share.isOwned:
66 raise AttributeError("%s is not active and cannot be visible. Please contact the user you think might own this share for more information." % self.share.getShareType())
67 if self.share is None:
68 raise AttributeError("We are sorry, but that share either does not exist, or if it does, you have not been invited to see it. Contact the user you think might own this share for more information.")
69 if self.share._obj is None:
70 raise AttributeError("We are sorry, but that share either does not exist, or if it does, you have not been invited to see it. Contact the user you think might own this share for more information.")
71
72 - def createShare(self, host, blitz_id, image, message, members, enable, expiration=None):
73
74
75 expiration_date = None
76 if expiration is not None:
77 d1 = datetime.datetime(*(time.strptime((expiration+" 23:59:59"), "%Y-%m-%d %H:%M:%S")[0:6]))
78 expiration_date = long(time.mktime(d1.timetuple())+1e-6*d1.microsecond)*1000
79 ms = [str(m) for m in members]
80
81 self.conn.createShare(host, int(blitz_id), image, message, ms, enable, expiration_date)
82
83 - def createDiscussion(self, host, blitz_id, message, members, enable, expiration=None):
84
85
86 expiration_date = None
87 if expiration is not None:
88 d1 = datetime.datetime(*(time.strptime((expiration+" 23:59:59"), "%Y-%m-%d %H:%M:%S")[0:6]))
89 expiration_date = rtime(long(time.mktime(d1.timetuple())+1e-6*d1.microsecond)*1000)
90 ms = [long(m) for m in members]
91
92 self.conn.createShare(host, int(blitz_id), [], message, ms, enable, expiration_date)
93
95
96
97 expiration_date = None
98 if expiration is not None:
99 d1 = datetime.datetime(*(time.strptime((expiration+" 23:59:59"), "%Y-%m-%d %H:%M:%S")[0:6]))
100 expiration_date = long(time.mktime(d1.timetuple())+1e-6*d1.microsecond)*1000
101
102 old_groups = [m._obj for m in self.conn.getAllMembers(self.share.id)]
103 new_groups = [e._obj for e in self.conn.getObjects("Experimenter", members)]
104
105 add_mem = list()
106 rm_mem = list()
107
108
109 for ogr in old_groups:
110 flag = False
111 for ngr in new_groups:
112 if ngr.id.val == ogr.id.val:
113 flag = True
114 if not flag:
115 rm_mem.append(ogr)
116
117
118 for ngr in new_groups:
119 flag = False
120 for ogr in old_groups:
121 if ogr.id.val == ngr.id.val:
122 flag = True
123 if not flag:
124 add_mem.append(ngr)
125
126 self.conn.updateShareOrDiscussion(host, int(blitz_id), self.share.id, message, add_mem, rm_mem, enable, expiration_date)
127
130
147
152
155
158
161
163 try:
164 if self.conn_share._shareId is not None:
165 content = self.conn_share.getContents(self.conn_share._shareId)
166 else:
167 raise AttributeError('Share was not activated.')
168 except:
169 raise AttributeError('Share was not activated.')
170 self.imageInShare = list()
171
172 for ex in content:
173 if isinstance(ex._obj, omero.model.ImageI):
174 self.imageInShare.append(ex)
175
176 self.imgSize = len(self.imageInShare)
177
179 content = self.conn.getContents(self.share.id)
180
181 self.imageInShare = list()
182
183 for ex in content:
184 if isinstance(ex._obj, omero.model.ImageI):
185 self.imageInShare.append(ex)
186
187 self.imgSize = len(self.imageInShare)
188