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()))