Skip to content

Commit

Permalink
add shebang line so the script can be run with ./bson_splitter.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansb committed Nov 5, 2013
1 parent 5e44f65 commit 3d24bb8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions tools/bson_splitter.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/env python2
import sys
import struct
import pymongo
Expand All @@ -12,8 +13,8 @@ def main(argv):
def split_bson(path):
bsonfile_path = os.path.abspath(path)
splitsfile_out = os.path.join(os.path.dirname(bsonfile_path), "." + os.path.basename(bsonfile_path) + ".splits")
bsonfile = open(bsonfile_path,'r')
splitsfile = open(splitsfile_out,'w')
bsonfile = open(bsonfile_path, 'r')
splitsfile = open(splitsfile_out, 'w')

file_position = 0
cur_split_start = 0
Expand All @@ -25,19 +26,17 @@ def split_bson(path):
#print {"start":cur_split_start, "length": bsonfile.tell() - cur_split_start}
splitsfile.write(BSON.encode({"s":long(cur_split_start), "l": long(bsonfile.tell() - cur_split_start)}))
break
size = struct.unpack("<i", size_bits)[0] - 4 # BSON size byte includes itself
size = struct.unpack("<i", size_bits)[0] - 4 # BSON size byte includes itself
file_position += 4
if cur_split_size + 4 + size > SPLIT_SIZE:
#print {"start":cur_split_start, "length": bsonfile.tell() - 4 - cur_split_start}
splitsfile.write(BSON.encode({"s":long(cur_split_start), "l": long(bsonfile.tell() - 4 - cur_split_start)}))
cur_split_start = bsonfile.tell() - 4
cur_split_size = 0
else:
pass

bsonfile.seek(file_position + size)
file_position += size
cur_split_size += 4 + size

if __name__ == '__main__':
main(sys.argv[1:])

0 comments on commit 3d24bb8

Please sign in to comment.