コード例 #1
0
    def mimic_connections(self,fr,to,name,argstocopy=(0,1,3)):
        from_input = self.get_node(*fr)
        if from_input:
            input_name = from_input.get_name()

            input_connections = from_input.get_meta('master')
            if input_connections and input_connections.is_string() and input_connections.as_string():
                input_connections_parsed = logic.parse_termlist(input_connections.as_string())
                output_connections = []

                if input_connections_parsed:
                    for input_conn in input_connections_parsed:
                        upstream_addr,upstream_path = paths.breakid_list(input_conn.args[2])
                        upstream_root = self.tools.get_root(upstream_addr)
                        if upstream_root:
                            upstream_node = upstream_root
                            for n in upstream_path[:-1]:
                                c = upstream_node.get_node(n)
                                if c:
                                    upstream_node = c
                            for c in upstream_node.iter():
                                if name == c.get_name():
                                    conn = logic.make_term('conn',input_conn.args[0] if 0 in argstocopy else None,input_conn.args[1] if 1 in argstocopy else None,c.id(),input_conn.args[3] if 3 in argstocopy else None)
                                    output_connections.append(conn)

                    if len(output_connections):
                        conn_txt = logic.render_termlist(output_connections)
                        c = self.ensure_node(*to)
                        c.set_meta_string('master', conn_txt)
                        print 'connected',name,'for',c.id(),'from',conn_txt
コード例 #2
0
ファイル: upgrade_v0.py プロジェクト: tylerwood/EigenD
def convert_metadata(metanode):
    metadata = {}
    children = map(ord,metanode.list_children())

    adjectives = get_string(metanode,4)
    nouns = get_string(metanode,8)
    ordinal = get_number(metanode,7)
    fuzzy = get_string(metanode,12)
    relation = get_string(metanode,11)
    control = get_string(metanode,21)
    notify = get_string(metanode,22)
    master = get_string(metanode,2)
    pronoun = get_string(metanode,15)
    icon = get_string(metanode,16)

    words = adjectives.split()+nouns.split()
    notify = logic.render_termlist(logic.parse_clause(notify or '[]'))

    if words: metadata['name'] = ' '.join(words)
    if ordinal is not None: metadata['ordinal'] = ordinal
    if fuzzy: metadata['fuzzy'] = fuzzy
    if control: metadata['control'] = control
    if notify: metadata['notify'] = notify
    if master: metadata['master'] = master
    if pronoun: metadata['pronoun'] = pronoun
    if icon: metadata['icon'] = icon

    if metanode.enum_children(5)==6:
        private = get_tree(metanode.get_child(6))
        set_tree(metanode,private)
    else:
        metanode.erase()

    return metadata
コード例 #3
0
    def attach(self, *args):
        c = []
        for i, a in enumerate(args):
            (id, ch) = a.args
            c.append(logic.make_term('conn', i, self.__key.index, id, ch))

        self[1].set_connections(logic.render_termlist(c))
コード例 #4
0
ファイル: language_plg.py プロジェクト: shamharoth/EigenD
 def rpc_create_action(self,arg):
     action_term = logic.parse_term(arg)
     result = deferred.create_action(self,action_term)
     yield result
     if not result.status():
         yield async.Coroutine.failure(*result.args(),**result.kwds())
     action = logic.render_termlist(result.args()[0])
     yield async.Coroutine.success(action)
コード例 #5
0
ファイル: upgrade_agentd.py プロジェクト: tylerwood/EigenD
    def upgrade_1_0_1_to_1_0_2(self, tools, address):
        # assign canonical ordinals to agents

        n2 = tools.get_root(address).get_node(2)
        old_plugins = logic.parse_termlist(
            n2.get_data().as_dict_lookup('agents').as_string())
        plugs_by_type = {}

        for old_term in old_plugins:
            (paddress, plugin, pversion, pcversion) = old_term.args
            pmeta = tools.get_root(paddress).get_data()
            pname = pmeta.as_dict_lookup('name')
            pordinal = pmeta.as_dict_lookup('ordinal')

            if not pname.is_string() or not pname.as_string():
                pname = plugin
            else:
                pname = pname.as_string()

            pname = pname.split()
            try:
                pname.remove('agent')
            except:
                pass
            pname = '_'.join(pname)

            if not pordinal.is_long() or not pordinal.as_long():
                pordinal = 0
            else:
                pordinal = pordinal.as_long()

            plugs_by_type.setdefault(plugin, []).append(
                [paddress, plugin, pversion, pcversion, pname, pordinal, 0])

        plugins = []

        for (ptype, plist) in plugs_by_type.iteritems():
            ords_used = set()
            max_ord = 0

            for p in plist:
                if ptype == p[4] and p[5] and p[5] not in ords_used:
                    p[6] = p[5]
                    ords_used.add(p[5])
                    max_ord = max(max_ord, p[5])

            for p in plist:
                if not p[6]:
                    max_ord += 1
                    p[6] = max_ord

                new_term = logic.make_term('a', p[0], p[1], p[2], p[3], p[6])
                plugins.append(new_term)

        n2.set_data(
            piw.dictset(piw.dictnull(0), 'agents',
                        piw.makestring(logic.render_termlist(plugins), 0)))
コード例 #6
0
ファイル: language_plg.py プロジェクト: shamharoth/EigenD
    def rpc_lexicon(self,arg):
        l = self.database.get_lexicon()
        t = l.get_timestamp()
        d = [ x for x in l.lexicon_iter() ]
        nd = len(d)
        i = int(arg)

        if i<0 or i>=nd:
            return async.success('%s:%d:' % (t,nd))

        d = d[i:i+100]
        ds = logic.render_termlist([logic.make_term(e,m,c) for (e,(m,c)) in d])
        return '%s:%d:%s' % (t,nd,ds)
コード例 #7
0
 def move_connection(self,old_id,new_id):
     print self.id(),'replacing',old_id,'with',new_id
     conn = self.get_meta('master')
     if conn and conn.is_string() and conn.as_string():
         conn_parsed = logic.parse_termlist(conn.as_string())
         conn_replaced = []
         for c in conn_parsed:
             if c.args[2] == old_id:
                 conn_replaced.append(logic.make_term(c.pred,c.args[0],c.args[1],new_id,c.args[3]))
             else:
                 conn_replaced.append(c)
         conn_new = logic.render_termlist(conn_replaced)
         self.set_meta_string('master',conn_new)
         print self.id(),'replaced',conn,'with',conn_new
コード例 #8
0
ファイル: upgrade_agentd.py プロジェクト: tylerwood/EigenD
    def upgrade_1_0_0_to_1_0_1(self, tools, address):
        plugins = []
        n2 = tools.get_root(address).get_node(2)
        for n in n2.iter(extension=253, exclude=[254, 255]):
            n3 = n.get_node(255)
            old_term = logic.parse_term(n3.get_data().as_string())
            (address, plugin, version, cversion) = old_term.args
            ncversion = tools.newcversion(address)
            nversion = tools.newrversion(address)
            nplugin = tools.canonical_name(address)
            new_term = logic.make_term('a', address, nplugin, nversion,
                                       ncversion)
            plugins.append(new_term)

        n2.erase_children()
        n2.set_data(
            piw.dictset(piw.dictnull(0), 'agents',
                        piw.makestring(logic.render_termlist(plugins), 0)))
コード例 #9
0
ファイル: upgrade_agentd.py プロジェクト: tylerwood/EigenD
def upgrade_plugins_v1(tools, address):
    n2 = tools.get_root(address).get_node(2)
    old_plugins = logic.parse_termlist(
        n2.get_data().as_dict_lookup('agents').as_string())
    new_plugins = []

    for old_term in old_plugins:
        (address, plugin, version, cversion, ordinal) = old_term.args
        ncversion = tools.newcversion(address)
        nversion = tools.newrversion(address)
        nplugin = tools.canonical_name(address)
        new_term = logic.make_term(old_term.pred, address, nplugin, nversion,
                                   ncversion, ordinal)
        new_plugins.append(new_term)

    n2.set_data(
        piw.dictset(piw.dictnull(0), 'agents',
                    piw.makestring(logic.render_termlist(new_plugins), 0)))
コード例 #10
0
ファイル: upgrade_tools_v0.py プロジェクト: tylerwood/EigenD
    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))
コード例 #11
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))
コード例 #12
0
ファイル: container.py プロジェクト: tylerwood/EigenD
 def __set_termlist(self):
     self.__container.set_property_string(
         self.__tag, logic.render_termlist(self.__nodes.keys()))
コード例 #13
0
 def rpc_listinstances(self, arg):
     i = self.listinstances()
     return logic.render_termlist(i)