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
|
#!/usr/bin/env python
import shutil
import os
from argparse import ArgumentParser
from test_controller.utils import mkdir_p, payload
def _create_blob(path, data):
if not os.path.isfile(path):
with open(path, 'w') as f:
f.write(data)
def create_blobs(target_dir, amount, size):
data = payload(size * 1000)
for i in xrange(amount):
basedir = os.path.join(target_dir, '%d/default/0/0/0' % i)
mkdir_p(basedir)
_create_blob(os.path.join(basedir, '0'), data)
def delete_blobs(target_dir):
if not os.path.isdir(target_dir):
return
for f in os.listdir(target_dir):
if f.isdigit():
directory = os.path.join(target_dir, f)
shutil.rmtree(directory)
def parse_args():
parser = ArgumentParser()
parser.add_argument(
'target_dir',
help='The target directory where templates will be written to.')
parser.add_argument(
'--amount', default=1000, type=int,
help='The amount of users to create blobs to.')
parser.add_argument(
'--size', default=1000, type=int,
help='The size of each template in KB.')
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
create_blobs(args.target_dir, args.amount, args.size * 1000)
|