def list(self, args): c = self.ctx.conn(args) groups = c.sf.getAdminService().lookupGroups() from omero.util.text import TableBuilder # Sort groups if args.sort_by_name: groups.sort(key=lambda x: x.name.val) elif args.sort_by_id: groups.sort(key=lambda x: x.id.val) if args.long: tb = TableBuilder("id", "name", "perms", "owner ids", "member ids") else: tb = TableBuilder("id", "name", "perms", "# of owners", "# of members") for group in groups: row = [group.id.val, group.name.val, str(group.details.permissions)] ownerids = self.getownerids(group) memberids = self.getmemberids(group) if args.long: row.append(",".join(sorted([str(x) for x in ownerids]))) row.append(",".join(sorted([str(x) for x in memberids]))) else: row.append(len(ownerids)) row.append(len(memberids)) tb.row(*tuple(row)) self.ctx.out(str(tb.build()))
def list(self, args): c = self.ctx.conn(args) users = c.sf.getAdminService().lookupExperimenters() from omero.util.text import TableBuilder tb = TableBuilder("id", "omeName", "firstName", "lastName", "email", "member of", "leader of") for user in users: row = [user.id.val, user.omeName.val, user.firstName.val, user.lastName.val] row.append(user.email and user.email.val or "") member_of = [] leader_of = [] for x in user.copyGroupExperimenterMap(): if not x: continue gid = str(x.parent.id.val) if x.owner.val: leader_of.append(gid) else: member_of.append(gid) if member_of: row.append(",".join(member_of)) else: row.append("") if leader_of: row.append(",".join(leader_of)) else: row.append("") tb.row(*tuple(row)) self.ctx.out(str(tb.build()))
def list(self, args): c = self.ctx.conn(args) iadmin = c.sf.getAdminService() from omero.rtypes import unwrap from omero.util.text import TableBuilder list_of_dn_user_maps = unwrap(iadmin.lookupLdapAuthExperimenters()) if list_of_dn_user_maps is None: return count = 0 tb = TableBuilder("#") if args.style: tb.set_style(args.style) tb.cols(["Id", "OmeName", "DN"]) for map in list_of_dn_user_maps: for dn, id in map.items(): try: exp = iadmin.getExperimenter(id) except: self.ctx.err("Bad experimenter: %s" % id) tb.row(count, *(id, exp.omeName.val, dn)) count += 1 self.ctx.out(str(tb.build()))
def list(self, args): c = self.ctx.conn(args) groups = c.sf.getAdminService().lookupGroups() from omero.util.text import TableBuilder # Sort groups if args.sort_by_name: groups.sort(key=lambda x: x.name.val) elif args.sort_by_id: groups.sort(key=lambda x: x.id.val) if args.long: tb = TableBuilder("id", "name", "perms", "owner ids", "member ids") else: tb = TableBuilder("id", "name", "perms", "# of owners", "# of members") for group in groups: row = [ group.id.val, group.name.val, str(group.details.permissions) ] ownerids = self.getownerids(group) memberids = self.getmemberids(group) if args.long: row.append(",".join(sorted([str(x) for x in ownerids]))) row.append(",".join(sorted([str(x) for x in memberids]))) else: row.append(len(ownerids)) row.append(len(memberids)) tb.row(*tuple(row)) self.ctx.out(str(tb.build()))
def list(self, args): c = self.ctx.conn(args) iadmin = c.sf.getAdminService() from omero.rtypes import unwrap from omero.util.text import TableBuilder list_of_dn_user_maps = unwrap(iadmin.lookupLdapAuthExperimenters()) if list_of_dn_user_maps is None: return count = 0 tb = TableBuilder("#") if args.style: tb.set_style(args.style) tb.cols(["Id", "OmeName", "DN"]) for map in list_of_dn_user_maps: for dn, id in list(map.items()): try: exp = iadmin.getExperimenter(id) except: self.ctx.err("Bad experimenter: %s" % id) tb.row(count, *(id, exp.omeName.val, dn)) count += 1 self.ctx.out(str(tb.build()))
def list(self, args): c = self.ctx.conn(args) iadmin = c.sf.getAdminService() import omero from omero.rtypes import unwrap from omero.util.text import TableBuilder try: list_of_dn_user_maps = unwrap(iadmin.lookupLdapAuthExperimenters()) if list_of_dn_user_maps is None: return count = 0 tb = TableBuilder("#") tb.cols(["Id", "OmeName", "DN"]) for map in list_of_dn_user_maps: for dn, id in map.items(): try: exp = iadmin.getExperimenter(id) except: self.ctx.err("Bad experimenter: %s" % id) tb.row(count, *(id, exp.omeName.val, dn)) count += 1 self.ctx.out(str(tb.build())) except omero.SecurityViolation, sv: self.ctx.die(131, "SecurityViolation: Must be an admin to lists DNs")
def list(self, args): c = self.ctx.conn(args) iadmin = c.sf.getAdminService() import omero from omero.rtypes import unwrap from omero.util.text import TableBuilder try: list_of_dn_user_maps = unwrap(iadmin.lookupLdapAuthExperimenters()) if list_of_dn_user_maps is None: return count = 0 tb = TableBuilder("#") tb.cols(["Id", "OmeName", "DN"]) for map in list_of_dn_user_maps: for dn, id in map.items(): try: exp = iadmin.getExperimenter(id) except: self.ctx.err("Bad experimenter: %s" % id) tb.row(count, *(id, exp.omeName.val, dn)) count += 1 self.ctx.out(str(tb.build())) except omero.SecurityViolation: self.ctx.die(131, "SecurityViolation: Must be an admin to lists DNs")
def _parse_scripts(self, scripts, msg): """ Parses a list of scripts to self.ctx.out """ from omero.util.text import TableBuilder tb = TableBuilder("id", msg) for x in scripts: tb.row(x.id.val, x.path.val + x.name.val) self.ctx.out(str(tb.build()))
def stat_screens(query): tb = TableBuilder("Screen") tb.cols(["ID", "Plates", "Wells", "Images", "Planes", "Bytes"]) plate_count = 0 well_count = 0 image_count = 0 plane_count = 0 byte_count = 0 for study, screens in sorted(studies().items()): for screen, plates_expected in screens.items(): params = ParametersI() params.addString("screen", screen) rv = unwrap(query.projection(( "select s.id, count(distinct p.id), " " count(distinct w.id), count(distinct i.id)," " sum(cast(pix.sizeZ as long) * pix.sizeT * pix.sizeC), " " sum(cast(pix.sizeZ as long) * pix.sizeT * pix.sizeC * " " pix.sizeX * pix.sizeY * 2) " "from Screen s " "left outer join s.plateLinks spl " "left outer join spl.child as p " "left outer join p.wells as w " "left outer join w.wellSamples as ws " "left outer join ws.image as i " "left outer join i.pixels as pix " "where s.name = :screen " "group by s.id"), params)) if not rv: tb.row(screen, "MISSING", "", "", "", "", "") else: for x in rv: plate_id, plates, wells, images, planes, bytes = x plate_count += plates well_count += wells image_count += images if planes: plane_count += planes if bytes: byte_count += bytes else: bytes = 0 if plates != len(plates_expected): plates = "%s of %s" % (plates, len(plates_expected)) tb.row(screen, plate_id, plates, wells, images, planes, filesizeformat(bytes)) tb.row("Total", "", plate_count, well_count, image_count, plane_count, filesizeformat(byte_count)) print str(tb.build())
def list(self, args): c = self.ctx.conn(args) a = c.sf.getAdminService() users = a.lookupExperimenters() roles = a.getSecurityRoles() user_group = roles.userGroupId sys_group = roles.systemGroupId from omero.util.text import TableBuilder tb = TableBuilder("id", "omeName", "firstName", "lastName", "email", \ "active", "admin", "member of", "leader of") users.sort(lambda a, b: cmp(a.id.val, b.id.val)) for user in users: row = [ user.id.val, user.omeName.val, user.firstName.val, user.lastName.val ] row.append(user.email and user.email.val or "") active = "" admin = "" member_of = [] leader_of = [] for x in user.copyGroupExperimenterMap(): if not x: continue gid = x.parent.id.val if user_group == gid: active = "Yes" elif sys_group == gid: admin = "Yes" elif x.owner.val: leader_of.append(str(gid)) else: member_of.append(str(gid)) row.append(active) row.append(admin) if member_of: row.append(",".join(member_of)) else: row.append("") if leader_of: row.append(",".join(leader_of)) else: row.append("") tb.row(*tuple(row)) self.ctx.out(str(tb.build()))
def list(self, args): c = self.ctx.conn(args) a = c.sf.getAdminService() users = a.lookupExperimenters() roles = a.getSecurityRoles() user_group = roles.userGroupId sys_group = roles.systemGroupId from omero.util.text import TableBuilder tb = TableBuilder("id", "omeName", "firstName", "lastName", "email", \ "active", "admin", "member of", "leader of") users.sort(lambda a,b: cmp(a.id.val, b.id.val)) for user in users: row = [user.id.val, user.omeName.val, user.firstName.val, user.lastName.val] row.append(user.email and user.email.val or "") active = "" admin = "" member_of = [] leader_of = [] for x in user.copyGroupExperimenterMap(): if not x: continue gid = x.parent.id.val if user_group == gid: active = "Yes" elif sys_group == gid: admin = "Yes" elif x.owner.val: leader_of.append(str(gid)) else: member_of.append(str(gid)) row.append(active) row.append(admin) if member_of: row.append(",".join(member_of)) else: row.append("") if leader_of: row.append(",".join(leader_of)) else: row.append("") tb.row(*tuple(row)) self.ctx.out(str(tb.build()))
def stat_screens(query): tb = TableBuilder("Container") tb.cols(["ID", "Set", "Wells", "Images", "Planes", "Bytes"]) plate_count = 0 well_count = 0 image_count = 0 plane_count = 0 byte_count = 0 for study, containers in sorted(studies().items()): for container, set_expected in sorted(containers.items()): params = ParametersI() params.addString("container", container) if "Plate" in set_expected: expected = set_expected["Plate"] rv = unwrap(query.projection(SPW_QUERY, params)) elif "Dataset" in set_expected: expected = set_expected["Dataset"] rv = unwrap(query.projection(PDI_QUERY, params)) else: raise Exception("unknown: %s" % set_expected.keys()) if not rv: tb.row(container, "MISSING", "", "", "", "", "") else: for x in rv: plate_id, plates, wells, images, planes, bytes = x plate_count += plates well_count += wells image_count += images if planes: plane_count += planes if bytes: byte_count += bytes else: bytes = 0 if plates != len(expected): plates = "%s of %s" % (plates, len(expected)) tb.row(container, plate_id, plates, wells, images, planes, filesizeformat(bytes)) tb.row("Total", "", plate_count, well_count, image_count, plane_count, filesizeformat(byte_count)) print str(tb.build())
def list(self, args): c = self.ctx.conn(args) groups = c.sf.getAdminService().lookupGroups() from omero.util.text import TableBuilder if args.long: tb = TableBuilder("id", "name", "perms", "owner ids", "member ids") else: tb = TableBuilder("id", "name", "perms", "# of owners", "# of members") for group in groups: row = [group.id.val, group.name.val, str(group.details.permissions)] if args.long: row.append(",".join(sorted([str(x.child.id.val) for x in group.copyGroupExperimenterMap() if x.owner.val]))) row.append(",".join(sorted([str(x.child.id.val) for x in group.copyGroupExperimenterMap() if not x.owner.val]))) else: row.append(len([x for x in group.copyGroupExperimenterMap() if x.owner.val])) row.append(len([x for x in group.copyGroupExperimenterMap() if not x.owner.val])) tb.row(*tuple(row)) self.ctx.out(str(tb.build()))
def list(self, args): c = self.ctx.conn(args) groups = c.sf.getAdminService().lookupGroups() from omero.util.text import TableBuilder if args.long: tb = TableBuilder("id", "name", "perms", "owner ids", "member ids") else: tb = TableBuilder("id", "name", "perms", "# of owners", "# of members") for group in groups: row = [ group.id.val, group.name.val, str(group.details.permissions) ] if args.long: row.append(",".join( sorted([ str(x.child.id.val) for x in group.copyGroupExperimenterMap() if x.owner.val ]))) row.append(",".join( sorted([ str(x.child.id.val) for x in group.copyGroupExperimenterMap() if not x.owner.val ]))) else: row.append( len([ x for x in group.copyGroupExperimenterMap() if x.owner.val ])) row.append( len([ x for x in group.copyGroupExperimenterMap() if not x.owner.val ])) tb.row(*tuple(row)) self.ctx.out(str(tb.build()))
def display(self, rv, cols=None, style=None, idsonly=False): import omero.all import omero.rtypes from omero.util.text import TableBuilder has_details = [] tb = TableBuilder("#") if style: tb.set_style(style) for idx, object_list in enumerate(rv): klass = "Null" id = "" values = {} # Handling for simple lookup if not idsonly and len(object_list) == 1 and \ isinstance(object_list[0], omero.rtypes.RObjectI): has_details.append(idx) o = object_list[0].val if o: tb.cols(["Class", "Id"]) klass = o.__class__.__name__ id = o.id.val for k, v in o.__dict__.items(): values[k] = self.unwrap(v) values = self.filter(values) tb.cols(values.keys()) tb.row(idx, klass, id, **values) # Handling for true projections else: indices = range(1, len(object_list) + 1) if cols is not None: tb.cols(cols) else: tb.cols(["Col%s" % x for x in indices]) values = tuple([self.unwrap(x) for x in object_list]) tb.row(idx, *values) self.ctx.out(str(tb.build())) return has_details
def display(self, rv, cols=None, style=None, idsonly=False): import omero.all import omero.rtypes from omero.util.text import TableBuilder has_details = [] tb = TableBuilder("#") if style: tb.set_style(style) for idx, object_list in enumerate(rv): klass = "Null" id = "" values = {} # Handling for simple lookup if not idsonly and len(object_list) == 1 and \ isinstance(object_list[0], omero.rtypes.RObjectI): has_details.append(idx) o = object_list[0].val if o: tb.cols(["Class", "Id"]) klass = o.__class__.__name__ id = o.id.val for k, v in list(o.__dict__.items()): values[k] = self.unwrap(v) values = self.filter(values) tb.cols(list(values.keys())) tb.row(idx, klass, id, **values) # Handling for true projections else: indices = list(range(1, len(object_list) + 1)) if cols is not None: tb.cols(cols) else: tb.cols(["Col%s" % x for x in indices]) values = tuple([self.unwrap(x) for x in object_list]) tb.row(idx, *values) self.ctx.out(str(tb.build())) return has_details
def stat_plates(query, screen, images=False): params = ParametersI() params.addString("screen", screen) obj = query.findByQuery(("select s from Screen s " "where s.name = :screen"), params) if not obj: raise Exception("unknown screen: %s" % screen) if images: q = ("select %s from Image i " "join i.wellSamples ws join ws.well w " "join w.plate p join p.screenLinks sl " "join sl.parent s where s.name = :screen") limit = 1000 found = 0 count = unwrap(query.projection(q % "count(distinct i.id)", params))[0][0] print >> stderr, count params.page(0, limit) q = q % "distinct i.id" q = "%s order by i.id" % q while count > 0: rv = unwrap(query.projection(q, params)) count -= len(rv) found += len(rv) params.page(found, limit) for x in rv: yield x[0] return plates = glob(join(screen, "plates", "*")) plates = map(basename, plates) tb = TableBuilder("Plate") tb.cols(["PID", "Wells", "Images"]) well_count = 0 image_count = 0 for plate in plates: params.addString("plate", plate) rv = unwrap( query.projection( ("select p.id, count(distinct w.id), count(distinct i.id)" " from Screen s " "left outer join s.plateLinks spl join spl.child as p " "left outer join p.wells as w " "left outer join w.wellSamples as ws " "left outer join ws.image as i " "where s.name = :screen and p.name = :plate " "group by p.id"), params)) if not rv: tb.row(plate, "MISSING", "", "") else: for x in rv: plate_id, wells, images = x well_count += wells image_count += images tb.row(plate, plate_id, wells, images) tb.row("Total", "", well_count, image_count) print str(tb.build())
def stat_plates(query, screen, images=False): params = ParametersI() params.addString("screen", screen) obj = query.findByQuery(( "select s from Screen s " "where s.name = :screen"), params) if not obj: raise Exception("unknown screen: %s" % screen) if images: q = ("select %s from Image i " "join i.wellSamples ws join ws.well w " "join w.plate p join p.screenLinks sl " "join sl.parent s where s.name = :screen") limit = 1000 found = 0 count = unwrap(query.projection( q % "count(distinct i.id)", params ))[0][0] print >>stderr, count params.page(0, limit) q = q % "distinct i.id" q = "%s order by i.id" % q while count > 0: rv = unwrap(query.projection(q, params)) count -= len(rv) found += len(rv) params.page(found, limit) for x in rv: yield x[0] return plates = glob(join(screen, "plates", "*")) plates = map(basename, plates) tb = TableBuilder("Plate") tb.cols(["PID", "Wells", "Images"]) well_count = 0 image_count = 0 for plate in plates: params.addString("plate", plate) rv = unwrap(query.projection(( "select p.id, count(distinct w.id), count(distinct i.id)" " from Screen s " "left outer join s.plateLinks spl join spl.child as p " "left outer join p.wells as w " "left outer join w.wellSamples as ws " "left outer join ws.image as i " "where s.name = :screen and p.name = :plate " "group by p.id"), params)) if not rv: tb.row(plate, "MISSING", "", "") else: for x in rv: plate_id, wells, images = x well_count += wells image_count += images tb.row(plate, plate_id, wells, images) tb.row("Total", "", well_count, image_count) print str(tb.build())
def processImages(conn, scriptParams): """ Process the script params to make a list of channel_offsets, then iterate through the images creating a new image from each with the specified channel offsets """ message = "" images, logMessage = script_utils.getObjects(conn, scriptParams) message += logMessage if not images: raise Exception("No images found") imageIds = sorted(set([i.getId() for i in images])) choice = scriptParams["Choice"] debug = bool(scriptParams.get("Debug", False)) globalmin = defaultdict(list) globalmax = defaultdict(list) tb = TableBuilder("Context", "Channel", "Min", "Max") statsInfos = dict() for iId in imageIds: statsInfo = calcStatsInfo(conn, iId, choice, debug) statsInfos[iId] = statsInfo for c, si in sorted(statsInfo.items()): c_min, c_max = si globalmin[c].append(c_min) globalmax[c].append(c_max) tb.row("Image:%s" % iId, c, c_min, c_max) tb.row("", "", "", "") for c in globalmin: c_min = globalmin[c] c_max = globalmax[c] tb.row("Total: outer ", c, min(c_min), max(c_max)) tb.row("Total: inner ", c, max(c_min), min(c_max)) tb.row("Total: average", c, int(avg(c_min)), int(avg(c_max))) if scriptParams["DryRun"]: print str(tb.build()) else: combine = scriptParams["Combine"] for iId in imageIds: img = conn.getObject("Image", iId) for c, ch in enumerate(img.getChannels(noRE=True)): si = ch.getStatsInfo() if si is None: si = StatsInfoI() action = "creating" else: si = si._obj action = "updating" if combine == "no": si.globalMin = rdouble(statsInfos[iId][c][0]) si.globalMax = rdouble(statsInfos[iId][c][1]) elif combine == "outer": si.globalMin = rdouble(min(globalmin[c])) si.globalMax = rdouble(max(globalmax[c])) elif combine == "inner": si.globalMin = rdouble(max(globalmin[c])) si.globalMax = rdouble(min(globalmax[c])) elif combine == "average": si.globalMin = rdouble(avg(globalmin[c])) si.globalMax = rdouble(avg(globalmax[c])) else: raise Exception("unknown combine: %s" % combine) if debug: print "Image:%s(c=%s) - %s StatsInfo(%s, %s)" % ( iId, c, action, si.globalMin.val, si.globalMax.val) ch._obj.statsInfo = si ch.save() count = sum(map(len, statsInfos.values())) message += "%s stats info object(s) processed" % count return message
def list(self, args): c = self.ctx.conn(args) a = c.sf.getAdminService() users = a.lookupExperimenters() roles = a.getSecurityRoles() user_group = roles.userGroupId sys_group = roles.systemGroupId from omero.util.text import TableBuilder if args.count: tb = TableBuilder("id", "login", "first name", "last name", "email", "active", "admin", "# group memberships", "# group ownerships") else: tb = TableBuilder("id", "login", "first name", "last name", "email", "active", "admin", "member of", "owner of") if args.style: tb.set_style(args.style) # Sort users if args.sort_by_login: users.sort(key=lambda x: x.omeName.val) elif args.sort_by_first_name: users.sort(key=lambda x: x.firstName.val) elif args.sort_by_last_name: users.sort(key=lambda x: x.lastName.val) elif args.sort_by_email: users.sort(key=lambda x: (x.email and x.email.val or "")) elif args.sort_by_id: users.sort(key=lambda x: x.id.val) for user in users: row = [ user.id.val, user.omeName.val, user.firstName.val, user.lastName.val ] row.append(user.email and user.email.val or "") active = "" admin = "" member_of = [] leader_of = [] for x in user.copyGroupExperimenterMap(): if not x: continue gid = x.parent.id.val if user_group == gid: active = "Yes" elif sys_group == gid: admin = "Yes" elif x.owner.val: leader_of.append(str(gid)) else: member_of.append(str(gid)) row.append(active) row.append(admin) if member_of: if args.count: row.append(len(member_of)) else: row.append(",".join(member_of)) else: row.append("") if leader_of: if args.count: row.append(len(leader_of)) else: row.append(",".join(leader_of)) else: row.append("") tb.row(*tuple(row)) self.ctx.out(str(tb.build()))
def _detailed_usage_report(self, req, rsp, status, args): """ Print a breakdown of disk usage in table form, including user, group and component information according to the args. """ from omero.util.text import TableBuilder sum_by = ("user", "group", "component") if args.sum_by is not None: sum_by = args.sum_by showCols = list(sum_by) showCols.extend(["size", "files"]) align = "l" * len(sum_by) align += "rr" tb = TableBuilder(*showCols) tb.set_align(align) if args.style: tb.set_style(args.style) subtotals = {} if "component" in sum_by: for userGroup in rsp.bytesUsedByReferer.keys(): for (element, size) in rsp.bytesUsedByReferer[userGroup].items(): files = rsp.fileCountByReferer[userGroup][element] keyList = [] if "user" in sum_by: keyList.append(userGroup.first) if "group" in sum_by: keyList.append(userGroup.second) keyList.append(element) key = tuple(keyList) if key in subtotals.keys(): subtotals[key][0] += size subtotals[key][1] += files else: subtotals[key] = [size, files] else: for userGroup in rsp.totalBytesUsed.keys(): size = rsp.totalBytesUsed[userGroup] files = rsp.totalFileCount[userGroup] keyList = [] if "user" in sum_by: keyList.append(userGroup.first) if "group" in sum_by: keyList.append(userGroup.second) key = tuple(keyList) if key in subtotals.keys(): subtotals[key][0] += size subtotals[key][1] += files else: subtotals[key] = [size, files] for key in subtotals.keys(): row = list(key) row.extend(subtotals[key]) tb.row(*tuple(row)) # Since an order in the response is not guaranteed if not sort keys # are specified then sort by the first column at least. if args.sort_by: keys = [] for col in args.sort_by: try: pos = showCols.index(col) keys.append(pos) except: pass else: keys = [0] tb.sort(cols=keys, reverse=args.reverse) # Format the size column after sorting. if args.units: col = tb.get_col("size") col = [self._to_units(val, args.units) for val in col] tb.replace_col("size", col) tb.replace_header("size", "size (%siB)" % args.units) elif args.human_readable: col = tb.get_col("size") col = [filesizeformat(val) for val in col] tb.replace_col("size", col) else: tb.replace_header("size", "size (bytes)") self.ctx.out(str(tb.build()))
def _detailed_usage_report(self, req, rsp, status, args): """ Print a breakdown of disk usage in table form, including user, group and component information according to the args. """ from omero.util.text import TableBuilder sum_by = ("user", "group", "component") if args.sum_by is not None: sum_by = args.sum_by showCols = list(sum_by) showCols.extend(["size", "files"]) align = 'l'*len(sum_by) align += 'rr' tb = TableBuilder(*showCols) tb.set_align(align) if args.style: tb.set_style(args.style) subtotals = {} if "component" in sum_by: for userGroup in rsp.bytesUsedByReferer.keys(): for (element, size) in rsp.bytesUsedByReferer[ userGroup].items(): files = rsp.fileCountByReferer[userGroup][element] keyList = [] if "user" in sum_by: keyList.append(userGroup.first) if "group" in sum_by: keyList.append(userGroup.second) keyList.append(element) key = tuple(keyList) if key in subtotals.keys(): subtotals[key][0] += size subtotals[key][1] += files else: subtotals[key] = [size, files] else: for userGroup in rsp.totalBytesUsed.keys(): size = rsp.totalBytesUsed[userGroup] files = rsp.totalFileCount[userGroup] keyList = [] if "user" in sum_by: keyList.append(userGroup.first) if "group" in sum_by: keyList.append(userGroup.second) key = tuple(keyList) if key in subtotals.keys(): subtotals[key][0] += size subtotals[key][1] += files else: subtotals[key] = [size, files] for key in subtotals.keys(): row = list(key) row.extend(subtotals[key]) tb.row(*tuple(row)) # Since an order in the response is not guaranteed if not sort keys # are specified then sort by the first column at least. if args.sort_by: keys = [] for col in args.sort_by: try: pos = showCols.index(col) keys.append(pos) except: pass else: keys = [0] tb.sort(cols=keys, reverse=args.reverse) # Format the size column after sorting. if args.units: col = tb.get_col("size") col = [self._to_units(val, args.units) for val in col] tb.replace_col("size", col) tb.replace_header("size", "size (%siB)" % args.units) elif args.human_readable: col = tb.get_col("size") col = [filesizeformat(val) for val in col] tb.replace_col("size", col) else: tb.replace_header("size", "size (bytes)") self.ctx.out(str(tb.build()))
def list(self, args): c = self.ctx.conn(args) a = c.sf.getAdminService() users = a.lookupExperimenters() roles = a.getSecurityRoles() user_group = roles.userGroupId sys_group = roles.systemGroupId from omero.util.text import TableBuilder if args.count: tb = TableBuilder("id", "login", "first name", "last name", "email", "active", "admin", "# group memberships", "# group ownerships") else: tb = TableBuilder("id", "login", "first name", "last name", "email", "active", "admin", "member of", "owner of") if args.style: tb.set_style(args.style) # Sort users if args.sort_by_login: users.sort(key=lambda x: x.omeName.val) elif args.sort_by_first_name: users.sort(key=lambda x: x.firstName.val) elif args.sort_by_last_name: users.sort(key=lambda x: x.lastName.val) elif args.sort_by_email: users.sort(key=lambda x: (x.email and x.email.val or "")) elif args.sort_by_id: users.sort(key=lambda x: x.id.val) for user in users: row = [user.id.val, user.omeName.val, user.firstName.val, user.lastName.val] row.append(user.email and user.email.val or "") active = "" admin = "" member_of = [] leader_of = [] for x in user.copyGroupExperimenterMap(): if not x: continue gid = x.parent.id.val if user_group == gid: active = "Yes" elif sys_group == gid: admin = "Yes" elif x.owner.val: leader_of.append(str(gid)) else: member_of.append(str(gid)) row.append(active) row.append(admin) if member_of: if args.count: row.append(len(member_of)) else: row.append(",".join(member_of)) else: row.append("") if leader_of: if args.count: row.append(len(leader_of)) else: row.append(",".join(leader_of)) else: row.append("") tb.row(*tuple(row)) self.ctx.out(str(tb.build()))