Beispiel #1
0
    def verb2_3_name(self, subject, thing, value):
        """
        name([],global_name,role(None,[concrete]),role(to,[abstract]))
        """

        words = action.abstract_wordlist(value)
        thing = action.concrete_object(thing)
        ordinal = None

        try:
            ordinal = int(words[-1])
            words = words[:-1]
        except:
            pass

        print 'set type name of ', thing, ' to ', words, ordinal

        proxy = self.database.find_item(thing)
        if not proxy:
            return async .failure('internal error: no proxy')

        def co():
            yield interpreter.RpcAdapter(
                proxy.invoke_rpc('set_names', ' '.join(words)))
            if ordinal is not None:
                yield interpreter.RpcAdapter(
                    proxy.invoke_rpc('set_ordinal', str(ordinal)))
            else:
                yield interpreter.RpcAdapter(
                    proxy.invoke_rpc('clear_ordinal', ''))

        return async .Coroutine(co(), interpreter.rpcerrorhandler)
Beispiel #2
0
    def verb2_19_unconnect_from(self, subject, t, f):
        """
        connect([un],global_unconnect_from,role(None,[concrete]),role(from,[concrete,singular]))
        """
        f = self.database.to_database_id(action.concrete_object(f))
        for o in action.concrete_objects(t):
            t2 = self.database.to_database_id(o)
            print 'un connect', t2, 'from', f
            tproxy = self.database.find_item(t2)
            objs = self.database.search_any_key(
                'W', T('unconnect_from_list', t2, f, V('W')))

            for (s, m) in objs:
                sproxy = self.database.find_item(s)
                cnxs = logic.parse_clauselist(sproxy.get_master())
                for cnx in cnxs:
                    if logic.is_pred_arity(cnx, 'conn',
                                           5) and self.database.to_database_id(
                                               cnx.args[2]) == m:
                        print 'disconnect', cnx, 'from', s
                        yield interpreter.RpcAdapter(
                            sproxy.invoke_rpc('disconnect',
                                              logic.render_term(cnx)))

        yield async .Coroutine.success()
Beispiel #3
0
 def verb2_21_statemgr(self, subject, sm):
     """
     use([],None,role(None,[concrete,proto(setupmanager),singular]))
     """
     sm = action.concrete_object(sm)
     self.agent.set_statemgr(sm)
     print 'using', sm, 'for checkpointing'
Beispiel #4
0
 def __ctluncreate(self, subj, c):
     a = action.concrete_object(c)
     for (i, p) in self.iter_subsys_items():
         if p.id() == a:
             self.__state[2].retract_state(lambda v, s: v == str(i))
             return action.removed_return(a)
     return async .failure('not found')
Beispiel #5
0
 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)
Beispiel #6
0
    def __save_inst(self,subject,arg,name):
        id = action.concrete_object(arg)
        name = action.abstract_string(name)
        rig = self.__instances.find(lambda v,i: v==id)

        if rig is None:
            return async.failure('not a rig')

        return rig.save(name)
Beispiel #7
0
 def __rigcreateverb(self, subject, plugin, rig):
     rig = action.concrete_object(rig)
     plugin = action.abstract_string(plugin)
     result = rpc.invoke_rpc(rig, "createagent", plugin)
     yield result
     if result.status():
         yield async .Coroutine.success(logic.parse_clause(
             result.args()[0]))
     yield async .Coroutine.failure(*result.args())
Beispiel #8
0
    def __uncreate_tap(self, subject, tap):
        subject = action.concrete_object(tap)
        print 'Delay, un create tap ', subject

        for k, v in self[7].iteritems():
            if v.id() == subject:
                self[7][k].destroy_tap()
                del self[7][k]
                return
Beispiel #9
0
    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))
Beispiel #10
0
    def __control(self, s, t):
        t = action.concrete_object(t)
        r = self.database.search_any_key('OL', T('find_controls', t, V('OL')))

        for target, ctl in r:
            tag = ':'.join((target, ctl))
            i = self[4].find_hole()
            c = Connector(self, i, tag)
            p = self.database.find_item(target)
            self[4][i] = c
            yield c.opened
            cs = logic.render_term(logic.make_term('ctl', c.id(), None))
            yield interpreter.RpcAdapter(p.invoke_rpc('control', cs))

        yield async .Coroutine.success()
Beispiel #11
0
    def verb2_10_associate(self, subject, part, whole):
        """
        associate([],global_associate,role(None,[or([concrete],[virtual]),singular]),role(to,[concrete,singular]))
        """
        part = action.arg_objects(part)[0]
        whole = action.concrete_object(whole)
        rel = 'join(%s,role(to,[instance(~self)]))' % part

        proxy = self.database.find_item(whole)
        if not proxy:
            return async .failure('internal error: no proxy')

        def co():
            yield interpreter.RpcAdapter(proxy.invoke_rpc('add_relation', rel))

        return async .Coroutine(co(), interpreter.rpcerrorhandler)
Beispiel #12
0
    def __controlwith(self, s, t, k):
        k = int(action.abstract_string(k))
        if self[4].has_key(k):
            yield async .Coroutine.failure('key already defined')

        t = action.concrete_object(t)
        p = self.database.find_item(t)
        ctl = p.domain().hint('control')
        if not ctl:
            yield async .Coroutine.failure('%s cannot be controlled' % t)

        c = Connector(self, k, ':'.join((t, ctl[0])))
        self[4][k] = c

        yield c.opened
        cs = logic.render_term(logic.make_term('ctl', c.id(), None))
        yield interpreter.RpcAdapter(p.invoke_rpc('control', cs))
        yield async .Coroutine.success()
Beispiel #13
0
    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))
Beispiel #14
0
    def __upgrade_sampler(self, subject, target, script):
        target = action.concrete_object(target)
        script = action.abstract_string(script)

        script = script.lower().replace(' ', '_')
        filename = resource.find_resource('upgrade_manager',
                                          'script_%s' % script)

        if not filename:
            return async .failure('upgrade script %s not defined' % script)

        interp = self.__interp.get_data().as_string()

        if not paths.valid_id(interp):
            return async .failure('no agent manager specified and no default')

        text = file(filename, 'r').read().replace('%target%', target)

        print 'upgrade on', target, 'with', script, 'using', interp
        return self.__runner(text, interp)
Beispiel #15
0
    def verb2_20_connect(self, subject, src, dst, dst_chan, src_chan):
        """
        connect([],global_connect,role(None,[or([concrete],[composite([descriptor])])]),role(to,[concrete,singular]),option(into,[mass([channel])]),option(from,[abstract]))
        """

        if dst_chan is not None:
            dst_chan = int(action.mass_quantity(dst_chan))

        if src_chan is not None:
            src_chan = action.abstract_string(src_chan)
            src_match = re.match('^channel\s+([\d\.]+)$', src_chan,
                                 re.IGNORECASE)
            if src_match:
                src_chan = src_match.group(1)
            else:
                yield async .Coroutine.failure("%s is not valid" % src_chan)

        to_descriptor = (action.concrete_object(dst), None)
        to_descriptor = self.database.to_database_term(to_descriptor)

        for ff in action.arg_objects(src):
            if action.is_concrete(ff):
                from_descriptors = [(action.crack_concrete(ff), None)]
            else:
                from_descriptors = action.crack_composite(
                    ff, action.crack_descriptor)

            from_descriptors = self.database.to_database_term(from_descriptors)

            r = plumber.plumber(self.database,
                                to_descriptor,
                                from_descriptors,
                                dst_chan=dst_chan,
                                src_chan=src_chan)
            yield r
            if not r.status():
                yield async .Coroutine.failure(*r.args(), **r.kwds())

        yield async .Coroutine.success()
Beispiel #16
0
    def verb2_5_number(self, subject, thing, value):
        """
        number([],global_number,role(None,[concrete,singular]),role(to,[abstract]))
        """

        value = action.abstract_string(value)
        thing = action.concrete_object(thing)

        try:
            value = int(value)
        except:
            return async .failure('internal error: non numeric ordinal')

        print 'set ordinal of ', thing, ' to ', value

        proxy = self.database.find_item(thing)
        if not proxy:
            return async .failure('internal error: no proxy')

        def co():
            yield interpreter.RpcAdapter(
                proxy.invoke_rpc('set_ordinal', str(value)))

        return async .Coroutine(co(), interpreter.rpcerrorhandler)
Beispiel #17
0
 def __add_widget(self, subject, dummy, target):
     target = action.concrete_object(target)
     self.widgets.create_widget(target)
Beispiel #18
0
 def crack_voice(self,voice):
     if action.is_concrete(voice[0]):
         o = action.concrete_object(voice)
         (a,p) = paths.breakid_list(o)
         return p[1]
     return int(action.abstract_string(voice))
Beispiel #19
0
 def __usesched(self,subject,sched):
     sched = action.concrete_object(sched)
     self.__scheduler.set_address(sched)
     self.get_private().set_data(piw.makestring(sched,0))
Beispiel #20
0
    def __create_tmpl(self,subject,name,arg):

        name = action.abstract_string(name)

        agentd = self.__agentd.get_data().as_string()
        if arg is not None:
            agentd = action.concrete_object(arg)

        if not paths.valid_id(agentd):
            yield async.Coroutine.failure('no agent manager specified and no default')

        print 'loading',name,'onto',agentd

        file = resource.find_resource(resource.instrument_dir,name)
        if not file or not os.path.exists(file):
            yield async.Coroutine.failure('no rig %s' % name)

        db = state.open_database(file,False)
        agnts = []
        map = state.create_mapping(True)
        ret = []
#        sscount=0
        ssid=''
        ssaddress=''
        
        for s,n,a in self.__agentlist(db.get_trunk()):
            x = a.get_address()

            if self.__issubsystem(s):
                #xa=getssid(sscount,ssid)  
                #sscount=sscount+1
                xa=self.__getssid(x,ssid)
                ssaddress='/'+(str(x).split('/')[1])
            elif self.__isrig(s):
                xa = guid.address('rig')
                self.__instances.assert_state(xa)
                ssid=xa
                ssaddress=''
#                sscount=0
            else:
                c = self.__create_agent(s,agentd)
                yield c

                if not c.status():
                    yield async.Coroutine.failure(*c.args())

                xa = c.args()[0]
                ssid=xa
                ssaddress=''
#                sscount=0

            map.add('|rig-%s%s-rig|'%(x,ssaddress),xa)
            print 'map','|rig-%s%s-rig|'%(x,ssaddress),xa

            if x == '0':
                ret.append(action.created_return(xa))
            elif not self.__issubsystem(s):
                ret.append(action.initialise_return(xa))
            
            print x,'->',s,xa

            agnts.append((xa,n))

        start = time.time()
        agg = async.Aggregate(progress=lambda agg,a,b: self.__status(start,agg,a,b))

        for i,(a,n) in enumerate(agnts):
            c = Controller(a)
            r = c.doload(n,map)
            agg.add(c,r)

        print 'loading'
        agg.enable()
        self.__bucket.append(agg)
        yield agg
        print 'loaded',agg
        self.__bucket.remove(agg)

        yield async.Coroutine.success(tuple(ret))
Beispiel #21
0
 def __use(self,sub,arg):
     arg = action.concrete_object(arg)
     self.__agentd.set_data(piw.makestring(arg,0))
Beispiel #22
0
 def __unadd(self,subject,agent):
     id = action.concrete_object(agent)
     self.__do_unadd(id)
Beispiel #23
0
 def __del_widget(self, subject, dummy, target):
     target = action.concrete_object(target)
     self.widgets.destroy_widget(target)