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)
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))
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)))
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
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()
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)))
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)))
def __init__(self, init=None, domain=None, policy=None, transient=False, rtransient=False, names=None, protocols=None, ordinal=None, fuzzy=None, creator=None, wrecker=None, pronoun=None, icon=None, container=None, ideals=None, bignode=False, dynlist=False, vocab=None): self.__listeners = [] self.__connection_scope = None ex = const.ext_node if bignode else None node.Server.__init__(self, creator=creator, wrecker=wrecker, rtransient=rtransient, extension=ex, dynlist=dynlist) node.Server.set_data(self, piw.dictnull(0)) p = policy if p is not None: dom = domain if init is None: value = dom.default() if dom is not None else None else: value = init else: if not domain: p = null_policy() dom = null_domain() else: p = readonly_policy() dom = domain if init is None: value = dom.default() else: value = init self.__policy = p(self, dom, value, transient) self.set_readwrite() fullname = names or '' if fullname: self.set_property_string('cname', fullname, notify=False) if pronoun is not None: self.set_property_string('pronoun', ' '.join(namelist), notify=False) if fuzzy is not None: self.set_property_string('fuzzy', fuzzy, notify=False) if ordinal is not None: self.set_property_long('cordinal', ordinal, notify=False) if icon is not None: ideal = files.get_ideal(logic.make_expansion('~self'), 'pkg_res:%s' % icon, files.PkgResourceFile(icon), True) self.set_property_string('icon', ideal, notify=False) if ideals is not None: self.set_property_string('ideals', ideals, notify=False) user_p = protocols or '' policy_p = self.__policy.protocols user_p = set(user_p.split()) policy_p = set(policy_p.split()) combined_p = user_p.union(policy_p) effective_p = " ".join(combined_p) self.set_property_string('protocols', effective_p, notify=False) self.set_internal(const.data_node, self.__policy.data_node()) self.__container = None if container: if isinstance(container, tuple): (n, l, c) = container else: (n, l, c) = (container, 'agent', VerbContainer()) c.add_atom(l, self.__create_action, self.__destroy_action, self.__isclocked, self.__status_action) self.__container = c self.__label = l self.__verblist = {} if n is not None: self[n] = c if vocab: self.set_vocab(vocab)
def makedict(items,ts): d = piw.dictnull(ts) for (k,v) in items.iteritems(): d = piw.dictset(d,k,v) return d
def __init__(self, init=None, domain=None, policy=None, transient=False, rtransient=False, names=None, protocols=None, ordinal=None, fuzzy=None, creator=None, wrecker=None, pronoun=None, icon=None, container=None, ideals=None, bignode=False, dynlist=False): self.__listeners = [] ex = const.ext_node if bignode else None node.Server.__init__(self, creator=creator, wrecker=wrecker, rtransient=rtransient, extension=ex, dynlist=dynlist) self.set_meta_data(piw.dictnull(0)) p = policy if p is not None: dom = domain if init is None: value = dom.default() if dom is not None else None else: value = init else: if not domain: p = null_policy() dom = null_domain() else: p = readonly_policy() dom = domain if init is None: value = dom.default() else: value = init self.__policy = p(self, dom, value, transient) self.set_readwrite() fullname = names or '' if fullname: self.set_property_string('name', fullname) self.set_property_string('cname', fullname) if pronoun is not None: self.set_property_string('pronoun', ' '.join(namelist)) if fuzzy is not None: self.set_property_string('fuzzy', fuzzy) if ordinal is not None: self.set_property_long('ordinal', ordinal) self.set_property_long('cordinal', ordinal) if icon is not None: ideal = files.get_ideal(logic.make_expansion('~self'), 'pkg_res:%s' % icon, files.PkgResourceFile(icon), True) self.set_property_string('icon', ideal) if ideals is not None: self.set_property_string('ideals', ideals) user_p = protocols or '' policy_p = self.__policy.protocols if policy_p: if user_p: if fullname: fullname = fullname + ' ' + user_p else: fullname = user_p if 'input' not in fullname and 'output' not in fullname: user_p = user_p + ' ' + policy_p if 'explicit' not in fullname: user_p = user_p + ' explicit' if 'nostage' in policy_p and 'nostage' not in user_p: user_p = user_p + ' nostage' if user_p: self.set_property_string('protocols', user_p) self.set_internal(const.data_node, self.__policy.data_node()) self.__container = None if container: if isinstance(container, tuple): (n, l, c) = container else: (n, l, c) = (container, 'agent', VerbContainer()) c.add_atom(l, self.__create_action, self.__destroy_action, self.__isclocked, self.__status_action) self.__container = c self.__label = l self.__verblist = {} self.__modelist = {} if n is not None: self[n] = c