Beispiel #1
0
    def __listener(self, veto, key, new_value):
        if veto:
            return False

        if key != self.__tag:
            return

        if new_value is None or not new_value.is_string():
            new_terms = set([])
        else:
            new_terms = set(logic.parse_clauselist(new_value.as_string()))

        discards = {}
        nodes = {}

        for (v, s) in self.__nodes.iteritems():
            if v in new_terms:
                new_terms.remove(v)
                nodes[v] = s
            else:
                discards[v] = s

        self.__nodes = None

        while discards:
            (v, s) = discards.popitem()
            self.__retracted(v, s)
            v = None
            s = None

        for v in new_terms:
            s = self.__asserted(v)
            nodes[v] = s

        self.__nodes = nodes
Beispiel #2
0
def __getsig(snap,cache,agent):
    address = agent.get_address()
    root = agent.get_root()

    if agent.get_type()!=0 or not root.get_data().is_dict():
        return None

    node = Node(root,address,())
    srcs = set()
    agent_name = __getname(snap,cache,address)

    for atom in node.iter_tree():
        meta = atom.get_data()
        name = atom.get_name()

        if not meta.is_dict() or not name:
            continue

        conn = meta.as_dict_lookup('master')
        if not conn.is_string():
            continue

        pathstr = '.'.join([str(p) for p in atom.path])
        conn_term = logic.parse_clauselist(conn.as_string())
        for c in conn_term:
            src = c.args[2]
            srcs.add('%s: %s' % (pathstr,__getname(snap,cache,src)))

    l = list(srcs)
    l.sort()

    return agent_name+' '+' '.join(l)
Beispiel #3
0
 def rpc_cancel_action(self,arg):
     action = logic.parse_clauselist(arg)
     result = deferred.cancel_action(self,action)
     yield result
     if not result.status():
         yield async.Coroutine.failure(*result.args(),**result.kwds())
     yield async.Coroutine.success()
Beispiel #4
0
    def property_change(self, key, new_value, delegate):
        if key != self.__tag:
            return

        if new_value is None or not new_value.is_string():
            new_terms = []
        else:
            new_terms = logic.parse_clauselist(new_value.as_string())

        discards = {}
        nodes = {}

        new_terms = set([self.__canonicalise(v) for v in new_terms])

        for (v, s) in self.__nodes.iteritems():
            if v in new_terms:
                new_terms.remove(v)
                nodes[v] = s
            else:
                discards[v] = s

        self.__nodes = None

        while discards:
            (v, s) = discards.popitem()
            self.__retracted(v, s, False)
            v = None
            s = None

        for v in new_terms:
            s = self.__asserted(v, delegate)
            nodes[v] = s

        self.__nodes = nodes
Beispiel #5
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 #6
0
 def __build_ccache_atom(self, atom):
     tgt = atom.id()
     conn = atom.get_node(255, 2)
     if conn is None: return
     conn_term = logic.parse_clauselist(conn.get_string_default(''))
     for c in conn_term:
         src = c.args[2]
         self.__ccache.setdefault(src, []).append(tgt)
Beispiel #7
0
 def get_instances(self, id):
     print 'Backend - get_instances: id=', id
     ords = set([])
     r = rpc.invoke_rpc(self.__database.to_usable_id(id), 'listinstances',
                        '')
     yield r
     if not r.status():
         yield async .Coroutine.failure('get_instances failed')
     result = r.args()[0]
     if result != 'None':
         ordinals = logic.parse_clauselist(result)
         for o in ordinals:
             ords.add(str(o))
         self.__frontend.instances_updated(ords)
     yield async .Coroutine.success()
Beispiel #8
0
def __getdot(snap, cache, agent):
    address = agent.get_address()
    root = agent.get_root()

    if agent.get_type() != 0 or not root.get_data().is_string():
        return []

    node = Node(root, address, ())
    dot = []
    agent_name = __getfullname(snap, cache, address)

    dot_node = '"%s" [ label="%s" ]' % (address, agent_name)
    dot.append(dot_node)

    for atom in node.walk():
        tgt = atom.id()
        name = atom.get_node(255, 8)
        pathstr = '.'.join([str(p) for p in atom.path])

        if not name:
            continue

        name = name.get_data()
        if not name.is_string() or not name.as_string():
            name = 'talker'

        conn = atom.get_node(255, 2)

        if not conn:
            continue

        if not conn.get_data().is_string():
            continue

        conn_term = logic.parse_clauselist(conn.get_string())
        for c in conn_term:
            src = c.args[2]
            (src_addr, src_name) = __getportname(snap, src)
            edge = '"%s"  -> "%s" [label = "%s->%s"]' % (src_addr, address,
                                                         src_name, name)
            dot.append(edge)

    return dot
Beispiel #9
0
    def __substitute_connection(self, tgt, old_id, new_id):
        (s, p) = paths.breakid_list(tgt)
        root = self.root(s)
        atom = root.get_node(*p)
        if atom is None: return
        conn = atom.get_node(255, 2)
        if conn is None: return
        old_conn = logic.parse_clauselist(conn.get_string_default(''))
        new_conn = []

        for c in old_conn:
            if c.args[2] == old_id:
                new_conn.append(
                    logic.make_term(c.pred, c.args[0], c.args[1], new_id,
                                    c.args[3]))
            else:
                new_conn.append(c)

        conn.set_string(logic.render_termlist(new_conn))
Beispiel #10
0
 def phase2_1_0_4(self, tools, address):
     print 'upgrading host', address
     root = tools.get_root(address)
     key_input = root.get_node(6, 3)
     print 'disconnecting key input', key_input.id()
     conn = key_input.get_master()
     if not conn: return
     for c in conn:
         print 'connection', c
         upstream_addr, upstream_path = paths.breakid_list(c)
         upstream_root = tools.get_root(upstream_addr)
         if not upstream_root: continue
         upstream = upstream_root.get_node(*upstream_path)
         upstream_slaves = logic.parse_clauselist(
             upstream.get_meta_string('slave'))
         print 'old upstream slaves', upstream_slaves
         upstream_slaves.remove(key_input.id())
         print 'new upstream slaves', upstream_slaves
         upstream.set_meta_string('slave',
                                  logic.render_termlist(upstream_slaves))
Beispiel #11
0
def __getsig(snap, cache, agent):
    address = agent.get_address()
    root = agent.get_root()

    if agent.get_type() != 0 or not root.get_data().is_string():
        return None

    node = Node(root, address, ())
    srcs = set()
    agent_name = __getname(snap, cache, address)

    for atom in node.walk():
        tgt = atom.id()
        name = atom.get_node(255, 8)
        pathstr = '.'.join([str(p) for p in atom.path])

        if not name:
            continue

        name = name.get_data()
        if not name.is_string() or not name.as_string():
            continue

        conn = atom.get_node(255, 2)

        if not conn:
            continue

        if not conn.get_data().is_string():
            continue

        conn_term = logic.parse_clauselist(conn.get_string())
        for c in conn_term:
            src = c.args[2]
            srcs.add('%s: %s' % (pathstr, __getname(snap, cache, src)))

    l = list(srcs)
    l.sort()

    return agent_name + ' ' + ' '.join(l)