def main(args): db = getattr(datastore, '{}_db'.format(args.db))() if args.prefix: prefix_from = args.prefix prefix_to = next_key(args.prefix) it = db.range(prefix_from, prefix_to, include_value=False) else: it = db.iterkeys() # assumes normalized keys with : as separator def get_next(): k = it.next() if k.endswith(':'): logger.warning("Key with `:` suffix: {!r}".format(k)) k = k.rstrip(':') if k.startswith(':'): logger.warning("Key with `:` prefix: {!r}".format(k)) k = k.lstrip(':') bits = k.rpartition(':') #logger.debug(bits) return bits[0], bits[2] try: head, tail = get_next() except StopIteration: print "Empty database" return if not head: # root key head = tail path = [head] count = [1] while True: try: head, tail = get_next() except StopIteration: while path: print '{:10}\t{}'.format(count.pop(), path.pop()) break if head == path[-1]: count[-1] += 1 elif path[-1] in head: path.append(head) count.append(1) else: while path: prev = path.pop() prev_count = count.pop() print '{:10}\t{}'.format(prev_count, prev) if not path: break if path[-1] in head: path.append(head) count.append(1) if not path: path.append(head) count.append(1)
def main(args): db = getattr(datastore, '{}_db'.format(args.db))() if args.command == 'get': for key in args.keys: print json.dumps(db.get(key)) elif args.command == 'list': for key in args.keys: for key in db.range(key, next_key(key), include_value=False): print key elif args.command == 'list_values': for key in args.keys: for key, value in db.range(key, next_key(key)): print json.dumps(value) elif args.command == 'shell': from IPython import embed; embed()
def main(args): db = getattr(datastore, '{}_db'.format(args.db))() if args.command == 'get': for key in args.keys: print json.dumps(db.get(key)) elif args.command == 'list': for key in args.keys: for key in db.range(key, next_key(key), include_value=False): print key elif args.command == 'list_values': for key in args.keys: for key, value in db.range(key, next_key(key)): print json.dumps(value) elif args.command == 'shell': from IPython import embed embed()
def main(args): # index corpus db = datastore.corpus_db() if args.prefix: items = db.range(args.prefix, next_key(args.prefix)) elif args.from_classified: items = get_classified_items(args.from_classified, db) else: items = db.range() count = search.index(items, 'corpus', create=args.create) print "Indexed {} documents".format(count)
def load_keys(fromkey, offset, limit): tokey = next_key(fromkey) db = datastore.corpus_db() it = db.range(fromkey, tokey) return [v for k, v in itertools.islice(it, offset, offset + limit)]
def load_keys(fromkey, offset, limit): tokey = next_key(fromkey) db = datastore.corpus_db() it = db.range(fromkey, tokey) return [v for k,v in itertools.islice(it, offset, offset + limit)]