Created
February 26, 2018 06:57
-
-
Save s-jcs/e12b6cd5d1602d4854e5abd92c444307 to your computer and use it in GitHub Desktop.
print level db key and values (msgpack to unpack binary)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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