Пример #1
0
    def postupgrade(self, tools, address):
        print 'eigend postupgrade'

        if tools.major_version() != 1:
            return

        n2 = tools.get_root(address).get_node(2)
        old_plugins = logic.parse_termlist(
            n2.get_data().as_dict_lookup('agents').as_string())
        good_plugins = set()
        good_plugins.add(guid.split(address)[0])

        for old_term in old_plugins:
            good_address = old_term.args[0]
            good_plugins.add(guid.split(good_address)[0])

        for actual_address in tools.get_agents():
            actual_guid, guid_tail = guid.split(actual_address)
            if actual_guid not in good_plugins and guid_tail != 'rig':
                a = tools.get_agent(actual_address)
                if a and a.get_type() == 0:
                    tools.delete_agent(actual_address)
                    print 'pruned bad agent', actual_address

        return upgrade_plugins_v1(tools, address)
Пример #2
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
Пример #3
0
    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)))
Пример #4
0
    def get_master(self):
        conn = self.get_meta('master')
        if conn and conn.is_string() and conn.as_string():
            try:
                conn_parsed = logic.parse_termlist(conn.as_string())
                return [c.args[2] for c in conn_parsed]
            except:
                pass

        return []
Пример #5
0
 def get_master_control(self, id, mid):
     proxy = self.__database.find_item(id)
     if (not proxy == None):
         master = proxy.get_master()
         terms = logic.parse_termlist(master or '')
         for t in terms:
             if logic.is_pred_arity(t, 'conn', 5, 5):
                 #                    print '******',t.args[3]
                 if t.args[2] == mid:
                     #print 'ctrl for',id,'=',t.args[4]
                     if (not t.args[4] == None):
                         return t.args[4]
     return ''
Пример #6
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
Пример #7
0
    def get_ordinals_used(self, agentType):
        print 'Backend - get_ordinals_used'

        r = rpc.invoke_rpc(self.__database.to_usable_id('<eigend1>'),
                           'listmodules', '')
        yield r
        if not r.status():
            yield async .Coroutine.failure('get_ordinals_used failed')
        result = r.args()[0]
        if result != 'None':

            terms = logic.parse_termlist(result)
            for t in terms:
                if t.args[0] == agentType:
                    print "ordinals used=", t.args[2]
        yield async .Coroutine.success()
Пример #8
0
    def __load_vocab(self):
        print 'loading vocabulary'
        self.__lexicon = pibelcanto.lexicon.lexicon.copy()
        self.__reverse = pibelcanto.lexicon.reverse_lexicon.copy()

        newlex = {}
        newrev = {}
        timestamp = ''
        lexsize = 0

        while True:
            r = self.invoke_rpc('lexicon', str(lexsize))
            yield r

            if not r.status():
                yield async .Coroutine.failure('cannot load lexicon')

            (t, l, x) = r.args()[0].split(':')

            if timestamp and t != timestamp:
                lexsize = 0
                newlex = {}
                newrev = {}
                timestamp = t
                continue

            words = logic.parse_termlist(x)

            if not words:
                break

            for w in words:
                newlex[w.pred] = w.args
                newrev[w.args[0]] = (w.pred, w.args[1])

            lexsize = len(newlex)

            if lexsize >= l:
                break

        print 'loaded vocabulary'
        for (e, (m, c)) in newlex.iteritems():
            print '%s -> %s %s' % (e, m, c)

        self.__lexicon.update(newlex)
        self.__reverse.update(newrev)
Пример #9
0
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
    def get_agents(self):
        print 'Backend - get_agents'
        names = set([])
        r = rpc.invoke_rpc(self.__database.to_usable_id('<eigend1>'),
                           'listmodules', '')
        yield r
        if not r.status():
            yield async .Coroutine.failure('get_agents failed')
        result = r.args()[0]
        if result != 'None':

            #        print "get_agents: result=",result
            terms = logic.parse_termlist(result)
            for t in terms:
                r = t.args[0]
                r = r + ","
                ords = t.args[2]
                for o in ords:
                    r = r + str(o)
                    r = r + ','
                names.add(r)
            self.__frontend.agents_updated(names)
        yield async .Coroutine.success(names)