Skip to content

Instantly share code, notes, and snippets.

@bskim45
Created November 7, 2015 19:28
Show Gist options
  • Save bskim45/9d16b892f3dac76322b4 to your computer and use it in GitHub Desktop.
Save bskim45/9d16b892f3dac76322b4 to your computer and use it in GitHub Desktop.
gensort Partition Generator
# -*- coding: UTF-8 -*-
import argparse
import os
import shlex
import subprocess
import sys
def main(argv):
chunks = 0
block_size = 1000000
command = ""
path = os.path.dirname(os.path.abspath(__file__))
if sys.platform.startswith('win'):
command = os.path.join(path, "gensort.exe") + " -a -b%d %d partition%d"
elif sys.platform.startswith('linux'):
command = os.path.join(path, "gensort") + " -a -b%d %d partition%d"
parser = argparse.ArgumentParser(description='Generates partitions')
parser.add_argument('chunks', type=int, help='# of chunks')
parser.add_argument('-b', '--block', type=int, help='Block size (default:1000000)', default=block_size)
args = parser.parse_args()
chunks = args.chunks
block_size = args.block
print '%d chunks, block size %d' % (chunks, block_size)
for i in range(0, chunks):
cmd = command % (i * block_size, block_size, i + 1)
if sys.platform.startswith('win'):
cmd = cmd.encode('string_escape').replace("\\", r"\\")
print cmd
args = shlex.split(cmd)
p = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=False)
for line in p.stdout.readlines():
print line,
retval = p.wait()
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment