Package Ganga :: Package GPIDev :: Package Lib :: Package Registry :: Module RegistrySliceProxy
[hide private]
[frames] | no frames]

Source Code for Module Ganga.GPIDev.Lib.Registry.RegistrySliceProxy

 1   
2 -class RegistrySliceProxy(object):
3 """This object is an access list to registry slices""" 4
5 - def __init__(self,_impl):
6 self.__dict__['_impl'] = _impl
7
8 - def ids(self,minid=None,maxid=None):
9 """ Return a list of ids of all objects. 10 """ 11 return self._impl.ids(minid,maxid)
12
13 - def clean(self,confirm=False,force=False):
14 """ Cleans this registry completely. 15 Returns True on success, False on failure""" 16 return self._impl.clean(confirm,force)
17
18 - def incomplete_ids(self):
19 try: 20 return self._impl.objects._incomplete_objects 21 except Exception, x: 22 return []
23
24 - def __iter__(self):
25 """ Looping. Example: 26 for j in jobs: 27 print j.id 28 """ 29 class Iterator: 30 def __init__(self,reg): 31 self.it = reg._impl.__iter__()
32 def __iter__(self): return self 33 def next(self): 34 return _wrap(self.it.next())
35 return Iterator(self) 36
37 - def __contains__(self,j):
38 return self._impl.__contains__(j._impl)
39
40 - def __len__(self):
41 return self._impl.__len__()
42
43 - def select(self,minid=None,maxid=None,**attrs):
44 """ Select a subset of objects. Examples for jobs: 45 jobs.select(10): select jobs with ids higher or equal to 10; 46 jobs.select(10,20) select jobs with ids in 10,20 range (inclusive); 47 jobs.select(status='new') select all jobs with new status; 48 jobs.select(name='some') select all jobs with some name; 49 jobs.select(application='Executable') select all jobs with Executable application; 50 jobs.select(backend='Local') select all jobs with Local backend. 51 """ 52 unwrap_attrs = {} 53 for a in attrs: 54 unwrap_attrs[a] = _unwrap(attrs[a]) 55 return self.__class__(self._impl.select(minid,maxid,**unwrap_attrs))
56
57 - def _display(self,interactive=0):
58 return self._impl._display(interactive)
59 60 __str__ = _display 61 62 63 # wrap Proxy around a ganga object (or a list of ganga objects) 64 # leave all others unchanged 65 from Ganga.GPIDev.Base.Proxy import GPIProxyObjectFactory 66 from Ganga.GPIDev.Base.Objects import GangaObject 67 from RegistrySlice import RegistrySlice
68 -def _wrap(obj):
69 if isinstance(obj,GangaObject): 70 return GPIProxyObjectFactory(obj) 71 if isinstance(obj,RegistrySlice): 72 return obj._proxyClass(obj) 73 if type(obj) == list: 74 return map(GPIProxyObjectFactory,obj) 75 return obj
76 77 # strip Proxy and get into the ganga object implementation
78 -def _unwrap(obj):
79 try: 80 return obj._impl 81 except AttributeError: 82 return obj
83