Package omeroweb :: Package webadmin :: Package controller :: Module drivespace
[hide private]
[frames] | no frames]

Source Code for Module omeroweb.webadmin.controller.drivespace

  1  #!/usr/bin/env python 
  2  #  
  3  #  
  4  #  
  5  # Copyright (c) 2008 University of Dundee.  
  6  #  
  7  # This program is free software: you can redistribute it and/or modify 
  8  # it under the terms of the GNU Affero General Public License as 
  9  # published by the Free Software Foundation, either version 3 of the 
 10  # License, or (at your option) any later version. 
 11  #  
 12  # This program is distributed in the hope that it will be useful, 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 15  # GNU Affero General Public License for more details. 
 16  #  
 17  # You should have received a copy of the GNU Affero General Public License 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 19  #  
 20  # Author: Aleksandra Tarkowska <A(dot)Tarkowska(at)dundee(dot)ac(dot)uk>, 2008. 
 21  #  
 22  # Version: 1.0 
 23  # 
 24   
 25  from webadmin.controller import BaseController 
 26   
 27  import omero 
 28   
29 -class BaseDriveSpace(BaseController):
30 31 freeSpace = None 32 usedSpace = None 33 topTen = None 34
35 - def __init__(self, conn):
36 BaseController.__init__(self, conn) 37 self.freeSpace = self.conn.getFreeSpace() 38 self.experimenters = list(self.conn.getObjects("Experimenter"))
39
40 -def _bytes_per_pixel(pixel_type):
41 if pixel_type == "int8" or pixel_type == "uint8": 42 return 1 43 elif pixel_type == "int16" or pixel_type == "uint16": 44 return 2 45 elif pixel_type == "int32" or pixel_type == "uint32" or pixel_type == "float": 46 return 4 47 elif pixel_type == "double": 48 return 8; 49 else: 50 raise AttributeError("Unknown pixel type: %s" % (pixel_type))
51
52 -def _usage_map_helper(pixels_list, pixels_originalFiles_list, exps):
53 tt = dict() 54 for p in pixels_list: 55 oid = p.details.owner.id.val 56 p_size = p.sizeX.val * p.sizeY.val * p.sizeZ.val * p.sizeC.val * p.sizeT.val 57 p_size = p_size*_bytes_per_pixel(p.pixelsType.value.val) 58 if tt.has_key(oid): 59 tt[oid]['data']+=p_size 60 else: 61 tt[oid] = dict() 62 tt[oid]['label']=exps[oid] 63 tt[oid]['data']=p_size 64 65 for pof in pixels_originalFiles_list: 66 oid = pof.details.owner.id.val 67 p_size = pof.parent.size.val 68 if tt.has_key(oid): 69 tt[oid]['data']+=p_size 70 71 return tt #sorted(tt.iteritems(), key=lambda (k,v):(v,k), reverse=True)
72
73 -def usersData(conn, offset=0):
74 loading = False 75 usage_map = dict() 76 exps = dict() 77 for e in list(conn.getObjects("Experimenter")): 78 exps[e.id] = e.getFullName() 79 80 PAGE_SIZE = 1000 81 offset = long(offset) 82 83 ctx = dict() 84 if conn.isAdmin(): 85 ctx['omero.group'] = '-1' 86 else: 87 ctx['omero.group'] = str(conn.getEventContext().groupId) 88 89 p = omero.sys.ParametersI() 90 p.page(offset, PAGE_SIZE) 91 pixels_list = conn.getQueryService().findAllByQuery( 92 "select p from Pixels as p join fetch p.pixelsType " \ 93 "order by p.id", p, ctx) 94 95 # archived files 96 if len(pixels_list) > 0: 97 pids = omero.rtypes.rlist([p.id for p in pixels_list]) 98 p2 = omero.sys.ParametersI() 99 p2.add("pids", pids) 100 pixels_originalFiles_list = conn.getQueryService().findAllByQuery( 101 "select m from PixelsOriginalFileMap as m join fetch m.parent " \ 102 "where m.child.id in (:pids)", p2, ctx) 103 104 count = len(pixels_list) 105 usage_map = _usage_map_helper(pixels_list, pixels_originalFiles_list, exps) 106 107 count = len(pixels_list) 108 offset += count 109 110 if count == PAGE_SIZE: 111 loading = True 112 113 return {'loading':loading, 'offset':offset, 'usage':usage_map}
114