def _set(attrs, opts): force = opts['FORCE'] flags = opts['FLAGS'] obj, attrs, id = _attr_prep(attrs, opts) adict, alist = arg_attrs(attrs) if id is None: obj.set_many(alist, flags, force) else: obj.set_many(id, alist, flags, force)
def usrloc(command, uri, contact=None, *args, **opts): ad, al = arg_attrs(args) table = opts['UL_TABLE'] q = float(ad.get('q', 1)) expires = ad.get('expires') if expires is not None: expires = int(expires) flags = ad.get('flags') if flags is not None: flags = int(flags) # LB hack if opts['SER_URI'][:4] == 'http': ur = Uri(opts['DB_URI']) curi = ur.canonize(uri) del(ur) if opts['SER_URI'][-1:] != '/': opts['SER_URI'] = opts['SER_URI'] + '/' opts['SER_URI'] = opts['SER_URI'] + 'sip:' + curi cmd = CMD.get(command) if cmd == CMD_ADD: if contact is None: raise Error (ENOARG, 'contact') u = Usrloc_ctl(opts['DB_URI'], any_rpc(opts)) u.add(uri, contact, table, expires, q, flags) elif cmd == CMD_RM: u = Usrloc_ctl(opts['DB_URI'], any_rpc(opts)) u.rm(uri, contact, table) elif cmd == CMD_SHOW: cols, numeric, limit, rsep, lsep, astab = show_opts(opts) u = Usrloc_ctl(opts['DB_URI'], any_rpc(opts)) ret = u.show(uri, table) if type(ret) == dict: # FIX: Is this a bug in usrloc SER code? ret = [ret] ret = [ (str(i['contact']), str(i['expires']), str(i['q'])) for i in ret ] desc = (('contact',), ('expires',), ('q',)) tabprint(ret, desc, rsep, lsep, astab) else: raise Error (EINVAL, command)