Exemplo n.º 1
0
def convert_atom(atom,extra={},ext=253):
    metadata = extra.copy()
    children = map(ord,atom.list_children())

    if 254 in children:
        children.remove(254)

    if 255 in children:
        children.remove(255)
        metanode = atom.get_child(255)
        metadata.update(convert_metadata(metanode))

    if 253 in children:
        children.remove(253)
        convert_list(atom.get_child(253))

    data = piw.dictnull(0)
    for (k,v) in metadata.iteritems():
        if isinstance(v,str):
            data = piw.dictset(data,k,piw.makestring(v,0))
        elif isinstance(v,int):
            data = piw.dictset(data,k,piw.makelong(v,0))
        elif isinstance(v,bool):
            data = piw.dictset(data,k,piw.makebool(v,0))

    atom.set_data(data)

    for c in children:
        convert_atom(atom.get_child(c))
Exemplo n.º 2
0
    def set_name(self,name):
        name = name.split()
        ordinal = None

        try:
            if len(name)>0:
                ordinal=int(name[-1])
                name = name[:-1]
        except:
            pass

        name = ' '.join(name)

        d = self.get_data()

        if d.is_null():
            d = piw.dictnull(0)

        if d.is_dict():
            if name:
                d = piw.dictset(d,'name',piw.makestring(name,0))
            else:
                d = piw.dictdel(d,'name')
            if ordinal:
                d = piw.dictset(d,'ordinal',piw.makelong(ordinal,0))
            else:
                d = piw.dictdel(d,'ordinal')

        self.set_data(d)
Exemplo n.º 3
0
def makedict(items, ts):
    d = piw.dictnull(ts)
    if type(items) == dict:
        for (k, v) in items.iteritems():
            d = piw.dictset(d, k, v)
    elif type(items) == list:
        for e in items:
            d = piw.dictset(d, e[0], e[1])
    return d
Exemplo n.º 4
0
    def upgrade_1_0_0_to_1_0_1(self,tools,address):
        keys = tools.get_root(address).get_node(3)
        for k in keys.iter(exclude=(254,255)):
            ko = k.path[-1]
            km = k.get_data()
            km = piw.dictset(km,'name',piw.makestring('key',0))
            km = piw.dictset(km,'ordinal',piw.makelong(ko,0))
            k.set_data(km)

            for e in k.iter(exclude=(254,255)):
                eo = e.path[-1]
                em = e.get_data()
                et = e.ensure_node(255).get_data()
                em = piw.dictset(em,'name',piw.makestring('action',0))
                em = piw.dictset(em,'ordinal',piw.makelong(ko,0))
                em = piw.dictset(em,'help',et if et.is_string() else piw.makestring('',0))
                e.set_data(em)
                e.erase_child(255)
Exemplo n.º 5
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)))
Exemplo n.º 6
0
    def set_meta(self,key,value):
        m = self.get_data()

        if m.is_null():
            m = piw.dictnull(0)

        if m.is_dict():
            m = piw.dictset(m,key,value)
            self.set_data(m)

        if key == 'master' and self.tools:
            self.tools.invalidate_connections()
Exemplo n.º 7
0
    def do_upgrade(self):
        for (k, (oldsig, m)) in self.__mapping.iteritems():
            if self.get_root(k):
                if oldsig.as_dict_lookup("subsystem").is_null():
                    if not self.call_phase(m, k, 0):
                        print 'upgrade v1 phase 0 failed', k
                        return False

        for (k, (oldsig, m)) in self.__mapping.iteritems():
            if self.get_root(k):
                if oldsig.as_dict_lookup("subsystem").is_null():
                    if not self.call_phase(m, k, 1):
                        print 'upgrade v1 phase 1 failed', k
                        return False

        for (k, (oldsig, m)) in self.__mapping.iteritems():
            if self.get_root(k):
                if oldsig.as_dict_lookup("subsystem").is_null():
                    if not self.call_phase(m, k, 2):
                        print 'upgrade v1 phase 2 failed', k
                        return False

        for (k, (oldsig, m)) in self.__mapping.iteritems():
            if self.get_root(k):
                if oldsig.as_dict_lookup("subsystem").is_null():
                    if not self.call_phase(m, k, 3):
                        print 'upgrade v1 phase 3 failed', k
                        return False

            root = self.get_root(k)
            if root:
                oldsig = piw.dictset(oldsig, 'version',
                                     piw.makestring(m.version, 0))
                oldsig = piw.dictset(oldsig, 'cversion',
                                     piw.makestring(m.cversion, 0))
                oldsig = piw.dictset(oldsig, 'plugin',
                                     piw.makestring(m.name, 0))
                root.set_data(oldsig)

        return True
Exemplo n.º 8
0
    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)))
Exemplo n.º 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)))
Exemplo n.º 10
0
    def set_property(self,
                     key,
                     value,
                     allow_veto=False,
                     notify=True,
                     delegate=None):
        if key == 'ordinal':
            if value == self.get_property('cordinal'):
                value = None

        if key == 'name':
            if value == self.get_property('cname'):
                value = None

        if allow_veto:
            if self.property_veto(key, value):
                return

            for lr in self.__listeners[:]:
                l = lr
                if l is not None:
                    if l.property_veto(key, value):
                        return

        old_value = node.Server.get_data(self)

        if value is None:
            d = piw.dictdel(old_value, key)
        else:
            d = piw.dictset(old_value, key, value)

        node.Server.set_data(self, d)

        if notify:
            self.property_change(key, value, delegate)
            for lr in self.__listeners[:]:
                l = lr
                if l is not None:
                    l.property_change(key, value, delegate)
Exemplo n.º 11
0
    def set_property(self, key, value, allow_veto=False):
        if allow_veto:
            if self.property_veto(key, value):
                return

            for lr in self.__listeners[:]:
                l = lr
                if l is not None:
                    if l(True, key, value):
                        return

        if value is None:
            d = piw.dictdel(self.get_meta_data(), key)
        else:
            d = piw.dictset(self.get_meta_data(), key, value)

        old_value = self.get_meta_data().as_dict_lookup(key)
        self.set_meta_data(d)
        self.property_change(key, value)

        for lr in self.__listeners[:]:
            l = lr
            if l is not None:
                l(False, key, value)
Exemplo n.º 12
0
def makedict(items,ts):
    d = piw.dictnull(ts)
    for (k,v) in items.iteritems():
        d = piw.dictset(d,k,v)
    return d