Home | Trees | Indices | Help |
---|
|
1 2 3 import Ganga.Utility.logging 4 logger = Ganga.Utility.logging.getLogger() 5 6 # add display default values for the box 7 from RegistrySlice import config 8 config.addOption('box_columns', 9 ("id","type","name","application"), 10 'list of job attributes to be printed in separate columns') 11 12 config.addOption('box_columns_width', 13 {'id': 5, 'type':20, 'name':40, 'application':15}, 14 'width of each column') 15 16 config.addOption('box_columns_functions', 17 {'application': "lambda obj: obj.application._name"}, 18 'optional converter functions') 19 20 config.addOption('box_columns_show_empty', 21 ['id'], 22 'with exception of columns mentioned here, hide all values which evaluate to logical false (so 0,"",[],...)') 23 24 from Ganga.Core import GangaException 31 32 from Ganga.GPIDev.Base.Objects import GangaObject 33 from Ganga.GPIDev.Schema import Schema, Version, SimpleItem 34 from Ganga.GPIDev.Lib.GangaList.GangaList import makeGangaList 3537 """Internal object to store names""" 38 _schema = Schema(Version(1,0), {"name": SimpleItem(defvalue="",copyable=1,doc='the name of this object',typelist=["str"])}) 39 _name = "BoxMetadataObject" 40 _category = "internal" 41 _enable_plugin = True 42 _hidden = 143 44 from Ganga.Core.GangaRepository.Registry import Registry, RegistryKeyError117 118 from RegistrySlice import RegistrySlice 119 from Ganga.Core.GangaRepository import getRegistry47 nobj = self.metadata[self.find(obj)] 48 obj._getWriteAccess() 49 nobj._getWriteAccess() 50 nobj.name = name 51 nobj._setDirty() 52 obj._setDirty()53 5860 nobj = self.metadata[self.find(obj)] 61 super(BoxRegistry,self)._remove(obj,auto_removed) 62 self.metadata._remove(nobj,auto_removed)6365 cached_values = ['status','id','name'] 66 c = {} 67 for cv in cached_values: 68 if cv in obj._data: 69 c[cv] = obj._data[cv] 70 slice = BoxRegistrySlice("tmp") 71 for dpv in slice._display_columns: 72 c["display:"+dpv] = slice._get_display_value(obj, dpv) 73 return c74 75 # Methods for the "box" proxy (but not for slice proxies)77 if type(obj_id) == str: 78 return self[self._getIDByName(obj_id)] 79 elif type(obj_id) == int: 80 return self[obj_id] 81 else: 82 obj = _unwrap(obj_id) 83 return self[self.find(obj)]8486 obj = _unwrap(obj) 87 if isinstance(obj,list): 88 obj = makeGangaList(obj) 89 if not isinstance(obj,GangaObject): 90 raise BoxTypeError("The Box can only contain Ganga Objects (i.e. Applications, Datasets or Backends). Check that the object is first in box.add(obj,'name')") 91 obj = obj.clone() 92 nobj = BoxMetadataObject() 93 nobj.name = name 94 self._add(obj) 95 self.metadata._add(nobj,self.find(obj)) 96 nobj._setDirty() 97 obj._setDirty()98 101 104106 slice = BoxRegistrySlice(self.name) 107 slice.objects = self 108 proxy = BoxRegistrySliceProxy(slice) 109 proxy.add = self.proxy_add 110 proxy.rename = self.proxy_rename 111 proxy.remove = self.proxy_remove 112 return proxy113156 157 158 from RegistrySliceProxy import RegistrySliceProxy, _wrap, _unwrap122 super(BoxRegistrySlice,self).__init__(name,display_prefix="box") 123 self._display_columns_functions["id"] = lambda obj : obj._getRegistry().find(obj) 124 self._display_columns_functions["type"] = lambda obj : obj._name 125 self._display_columns_functions["name"] = lambda obj : obj._getRegistry()._getName(obj) 126 from Ganga.Utility.ColourText import Foreground, Background, Effects 127 fg = Foreground() 128 fx = Effects() 129 bg = Background() 130 self.fx = fx 131 self.status_colours = { 'default' : fx.normal, 132 'backends' : fg.orange, 133 'applications': fg.green, 134 'jobs' : fg.blue} 135 self._proxyClass = BoxRegistrySliceProxy136 137 140142 if isinstance(id,str): 143 matches = [] 144 for o in self.objects: 145 if o._getRegistry()._getName(o) == id: 146 return o 147 matches.append(o) 148 if len(matches) == 1: 149 return matches[0] 150 elif len(matches) > 1: 151 raise RegistryKeyError("Multiple objects with name '%s' found in the box - use IDs!" % id) 152 else: 153 raise RegistryKeyError("No object with name '%s' found in the box!" % id) 154 else: 155 return super(BoxRegistrySlice,self).__getitem__(id)160 """This object is a list of objects in the box 161 """189163 """ Access individual object. Examples: 164 box(10) : get object with id 10 or raise exception if it does not exist. 165 """ 166 return _wrap(self._impl.__call__(x))167169 """ Get an item by positional index. Examples: 170 box[-1] : get last object, 171 box[0] : get first object, 172 box[1] : get second object. 173 """ 174 return _wrap(self._impl.__getitem__(x))175177 """ Get a slice. Examples: 178 box[2:] : get first two objects, 179 box[:-10] : get last 10 objects. 180 """ 181 return _wrap(self._impl.__getslice__(i1,i2))182
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon Jun 25 10:35:37 2012 | http://epydoc.sourceforge.net |