+def cmd_list(argv):
+ try:
+ opts, argv = getopt(argv, '', [])
+ except GetoptError:
+ return 1
+ if argv:
+ return 1
+ c = Crypto(C.KeyFile(keyfile, C.KOPEN_READ)[tag])
+ db = CMDB(dbfile)
+ if not user:
+ gen = db.select('SELECT DISTINCT id FROM attrset')
+ else:
+ gen = db.select('''SELECT DISTINCT attrset.id
+ FROM attrset, attr ON attrset.attr = attr.id
+ WHERE attr.key = 'user' AND attr.value = ?''',
+ [user])
+ for id, in gen:
+ a = AttrMultiMap(db, id)
+ print '%s %s%s' % \
+ (token(c, id),
+ a.get('addr', '<no-address>')[0],
+ (not user and ' [%s]' % a.get('user', ['<no-user>'])[0] or ''))
+ show(db, a)
+commands['list'] = \
+ (cmd_list, '', """
+List the user's tokens and information about them.""")
+