Skip to content

Instantly share code, notes, and snippets.

@Virako
Last active August 29, 2015 14:03
Show Gist options
  • Save Virako/8ece4ee590e472f5b49a to your computer and use it in GitHub Desktop.
Save Virako/8ece4ee590e472f5b49a to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import argparse
import os
import random
import string
from hashlib import sha512
from time import time
def rand_name(size=None):
if not size:
size = random.randint(5, 15)
name = ''
for x in xrange(size):
name += random.choice(string.hexdigits)
return name
def create_folder(directory):
new_dir = os.path.join(directory, rand_name())
if not os.path.exists(new_dir):
os.makedirs(new_dir)
return new_dir
else:
create_folder(directory)
def random_cad(size=1024):
cad = ''
for i in xrange(size / 4):
cad_aux = sha512(rand_name()).hexdigest()
for c in xrange(len(cad_aux) / 4):
cad += sha512(cad[c:c+8]).hexdigest()
return cad
def create_file(path, size):
if (size <= 0):
return False
filename = rand_name()
if not os.path.exists(filename):
with open(os.path.join(path, filename), 'w') as f:
for i in xrange(size):
f.write(random_cad())
return True
else:
create_file(directory, size, enc)
def main(parser):
if parser.seed is not None:
seed = parser.seed
else:
seed = random.randint(0, 1000000000)
random.seed(seed)
if parser.ndir is not None:
ndir = parser.ndir
else:
ndir = random.randint(0, 50000)
if parser.deep is not None:
deep = parser.deep
else:
deep = random.randint(0, 100)
#if parser.distribute_folder is not None:
# distribute_folder = parser.distribute_folder
#else:
# distribute_folder = random.randint(0, 100)
if parser.nfile:
nfile = parser.nfile
else:
nfile = random.randint(1, 10000000)
if parser.size:
size = parser.size
else:
size = random.randint(1, 5000)
if parser.distribute_files is not None:
distribute_files = parser.distribute_files
else:
distribute_files = random.randint(0, 100)
if parser.distribute_size is not None:
distribute_size = parser.distribute_size
else:
distribute_size = random.randint(0, 100)
if parser.path:
path = os.path.abspath(parser.path)
if not os.path.exists(path):
os.makedirs(path)
else:
path = os.getcwd()
print "Using seed %d: " % seed
list_dir = []
list_dir.append([path, ndir])
ini = time()
create_file(path, size)
print "Tiempo en generar x", time() - ini
print "Generate %d folders with %d of deep." % (ndir, deep)
while ndir > 0:
new_dir = create_folder(list_dir[0][0])
ndir -= 1
current_ndir = list_dir[0][1] - 1
if (current_ndir == 0):
del list_dir[0]
else:
ndir_deep = current_ndir * deep / 100
ndir_path = current_ndir - ndir_deep
if (ndir_deep > 0):
list_dir.append([new_dir, ndir_deep])
if (ndir_path > 0):
list_dir[0][1] = ndir_path
else:
del list_dir[0]
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Wgeneration option. ')
parser.add_argument('--seed', type=int, action='store', help='Seed. ')
parser.add_argument('--ndir', type=int, action='store',
help='Number of directories for create. ')
parser.add_argument('--deep', type=int, action='store',
help='Percent for distribute deep.')
#parser.add_argument('--distribute_folder', type=int, action='store',
# help='Percent for distribute folder.')
parser.add_argument('--nfile', type=int, action='store',
help='Number of files for create. ')
parser.add_argument('--size', type=int, action='store',
help='Total size of files (MB) ')
parser.add_argument('--distribute_files', type=int, action='store',
help='Percent for distribute files. ')
parser.add_argument('--distribute_size', type=int, action='store',
help='Percent to distribute size of files. ')
parser.add_argument('--path', action='store', help='Path to generate. ')
#parser.add_argument('--version', action='version', version=__version__)
results = parser.parse_args()
main(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment