def __add(self,subject,agent): id = action.concrete_object(agent) if self.__state.find(lambda v,s: s==id): print id,'already in',self.id() return print 'adding',id, 'to',self.id() rpc.invoke_rpc(id,'notify_delete',logic.render_term(self.id())) self.__state.assert_state(id)
def destroy(self): # remove this widget from the targets controllers address = self.get_property_string('target-id') myrid = paths.to_relative(self.id(), scope=paths.id2scope(address)) cs = logic.render_term( logic.make_term('conn', None, None, myrid, None, 'ctl')) if address != '': rpc.invoke_rpc(address, 'disconnect', cs)
def __do_icon(self,a,b,c,d): print 'icon_manager:__do_icon',a,b,c,d (type,thing) = action.crack_ideal(action.arg_objects(d)[0]) print 'crack', type,thing iconstring=self[2].getIconString(thing) id=action.concrete_object(c) print 'set the icon string on ',id, 'to',iconstring rpc.invoke_rpc(id,'set_icon',logic.render_term(iconstring))
def __create_agent(self,signature,agentd): r = rpc.invoke_rpc(agentd,'create',signature) yield r if not r.status(): yield async.Coroutine.failure(*r.args()) yield async.Coroutine.success(r.args()[0])
def setup(self,address,name): self.set_property_long('ref-count',1) self.set_property_string('target-name',name) self.set_property_string('target-id',address) cs = logic.render_term(logic.make_term('ctl',self.id(),None)) if address!='': return rpc.invoke_rpc(address,'control',cs) else: return False
def setup(self, address, name): myrid = paths.to_relative(self.id(), scope=paths.id2scope(address)) self.set_property_long('ref-count', 1) self.set_property_string('target-name', name) self.set_property_string('target-id', address) cs = logic.render_term( logic.make_term('conn', None, None, myrid, None, 'ctl')) if address != '': return rpc.invoke_rpc(address, 'connect', cs) else: return False
def doload(self,node,map): yield self.add_sync() diff = self.get_diff(node,map).render() spl = [] while diff: s = diff[:10240] diff = diff[len(s):] spl.append(s) for (i,s) in enumerate(spl): r = rpc.invoke_rpc(self.__address,'loadstate','%d:%d:%s' % (i,len(spl),s)) yield r yield async.Coroutine.success()
def __uncreate_inst(self,subject,arg): id = action.concrete_object(arg) agentd = self.__agentd.get_data().as_string() rig = self.__instances.find(lambda v,i: v==id) rv = [id] if rig is None: yield async.Coroutine.failure('not a rig') f = async.Aggregate() for a in rig.iteragents(): f.add(a,rpc.invoke_rpc(agentd,'destroy',a)) rv.append(a) f.enable() yield f self.__instances.retract_state(lambda v,i: v==id) yield async.Coroutine.success(action.removed_return(*rv))
def __get_rig_agents(self,id): all=[] rr=rpc.invoke_rpc(id,'agents',self.id()) yield rr if not rr.status(): yield async.Coroutine.failure('rpc error') if rr.args()[0]: agnts=logic.parse_clause(rr.args()[0]) all.extend(agnts) for aa in agnts: if isrig(aa): r=self.__get_rig_agents(aa) yield r if not r.status(): yield async.Coroutine.failure('error getting agents in rig') all.extend(r.args()[0]) yield async.Coroutine.success(all)
def coroutine(): inv = rpc.invoke_rpc(id, name, arg, opts.timeout) yield inv yield async .Coroutine.completion(inv.status(), inv.args()[0])
def save(self,name): dir = resource.user_resource_dir(resource.instrument_dir) file = os.path.join(dir,name) if os.path.exists(file): os.unlink(file) agg = async.Aggregate() map = state.create_mapping(True) ctl = [] ssctl=[] id =self.id() all=[id] for a in self.iterall(): all.append(a) if isrig(a): rr=self.__get_rig_agents(a) yield rr if not rr.status(): yield async.Coroutine.failure('error getting agents in rig') rigall=rr.args()[0] all.extend(rigall) subs={} for a in all: r=rpc.invoke_rpc(a,'subsystems',logic.render_term(self.id())) yield r if not r.status(): yield async.Coroutine.failure('rpc error') if r.args()[0]: ss=logic.parse_clause(r.args()[0]) print 'subsystems of %s' %a,ss subs[a]=ss for i,a in enumerate(all): c = Controller(a) ctl.append(c) agg.add(c,c.add_sync()) map.add(a,'|rig-%d-rig|' % i) print 'adding to map',a,'|rig-%d-rig|' % i if a in subs: for s in subs[a]: ss=getssid(s,a) c = Controller(ss) #ctl.append(c) agg.add(c,c.add_sync()) ssname=self.__getssname(ss) ssctl.append((c,str(i) +'/'+ ssname)) map.add(ss,'|rig-%d/%s-rig|' % (i,ssname)) print 'adding to map',ss,'|rig-%d/%s-rig|' % (i,ssname) agg.enable() yield agg db = state.open_database(file,True) snap = db.get_trunk() for i,c in enumerate(ctl): a = snap.get_agent_address(0,str(i),True) c.save_template(a.get_root(),map) a.set_checkpoint() for c,name in ssctl: a = snap.get_agent_address(0,name,True) c.save_template(a.get_root(),map) a.set_checkpoint() snap.save(0,'') db.flush() db.close() yield async.Coroutine.success(action.nosync_return())
def destroy(self): # remove this widget from the targets controllers cs = logic.render_term(logic.make_term('ctl',self.id(),None)) address = self.get_property_string('target-id') if address!='': rpc.invoke_rpc(address,'uncontrol',cs)