Skip to content

Instantly share code, notes, and snippets.

@s-jcs
Created February 26, 2018 06:57
Show Gist options
  • Save s-jcs/e12b6cd5d1602d4854e5abd92c444307 to your computer and use it in GitHub Desktop.
Save s-jcs/e12b6cd5d1602d4854e5abd92c444307 to your computer and use it in GitHub Desktop.
print level db key and values (msgpack to unpack binary)
import os
import sys
import plyvel
import msgpack
def p():
db_name = str(input('db name (Ex. candidates): '))
db_root = str(input('root directory (Ex. ./dbs/foobar/stg/): '))
print_limit = int(input('print limit (0 is all): '))
db_path = None
for root, dirs, files in os.walk(db_root, topdown=False):
for name in dirs:
if db_name in os.path.join(root, name):
db_path = os.path.join(root, name)
if db_path is None:
print('db not found!')
sys.exit()
db = plyvel.DB(db_path)
i = 0
for k, v in db:
print(k)
print(msgpack.unpackb(v))
i = i + 1
if print_limit is not 0 and i >= print_limit:
sys.exit()
if __name__ == '__main__':
p()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment