-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomdb2getrow
More file actions
executable file
·80 lines (68 loc) · 1.88 KB
/
comdb2getrow
File metadata and controls
executable file
·80 lines (68 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/opt/swt/bin/python
# Mohit Khullar
import sys
import bsddb
import os
import glob
import datetime
import threading
odh = 0
total_records = 0
noprint=0
if (len(sys.argv) == 1) :
print sys.argv[0], "<filename> key"
print "eg:", sys.argv[0], "'book1*.datas*' 53b1c45c0ee50000"
print ": ", sys.argv[0], "'book1*.datas*'"
print ": ", sys.argv[0], "'book1*.datas*' rowcount"
sys.exit()
if (len(sys.argv) == 3) :
if(sys.argv[2] == 'rowcount') :
del sys.argv[2]
noprint=1;
def is_ascii(s) :
return all(ord(c) < 128 for c in s)
def printRow(key,value):
global noprint
if(noprint) :
return
elif (is_ascii(value)) :
print "key ", key.encode('hex'), 'length: ', len(value), ' value: ', value, ' hex: ', value.encode('hex')
else :
print "key ", key.encode('hex'), 'length: ', len(value), ' hex value: ', value.encode('hex')
def decToHex(n):
return format(int(n, base=10),'x')
def parseDbFile(filename):
db = bsddb.btopen(filename, 'c')
records = 0
if (len(sys.argv) > 2) :
key = sys.argv[2]
new_key = 0
if (len(key) == 16 or len(key) > 24) :
new_key = key.decode('hex')
else :
new_key = decToHex(key).decode('hex')
if (db.has_key(new_key) == 1) :
a, b = db.set_location(new_key)
value = b[odh:]
if (len(a) > 0) :
print(filename)
printRow(a, value)
sys.exit()
else :
print(filename)
for a, b in db.iteritems():
value = b[odh:]
printRow(a, value)
records += 1
global total_records
total_records += records
db.close()
threads = []
for filename in glob.glob(sys.argv[1]):
parseDbFile(filename)
#thread = threading.Thread(target=parseDbFile, args=(filename,))
#thread.start()
#threads.append(thread)
for thread in threads :
thread.join()
print "total records", total_records