|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
| 3 | +import base64 |
| 4 | +import random |
| 5 | +import string |
3 | 6 | import yaml
|
4 | 7 |
|
5 |
| -infile = "bz1866117-stub.yaml" |
6 |
| -outfile = "bz1866117-out.yaml" |
7 |
| -rootdir = "/var/srv" |
8 |
| -source = "data:text/plain;charset=utf-8;base64,aGVsbG8gd29ybGQK" |
| 8 | +def b64string(instring): |
| 9 | + b64b_string = base64.b64encode(instring.encode('ascii')) |
| 10 | + return b64b_string.decode('ascii') |
9 | 11 |
|
10 |
| -files = [] |
11 |
| -for i in range(0,100): |
12 |
| - filepath = rootdir + 'hello-world' + str(i) + '.txt' |
13 |
| - e = {'contents': {'source': source}, 'filesystem': 'root', 'path': filepath} |
14 |
| - files.append(e) |
| 12 | +def main(): |
| 13 | + infile = "bz1866117-stub.yaml" |
| 14 | + outfile = "bz1866117-out.yaml" |
| 15 | + rootdir = "/var/srv/" |
| 16 | + sourceb = "data:text/plain;charset=utf-8;base64," |
15 | 17 |
|
16 |
| -with open(infile) as fin: |
17 |
| - data = yaml.load(fin, Loader=yaml.FullLoader) |
18 |
| - data['spec']['config']['storage']['files'] = files |
| 18 | + files = [] |
| 19 | + chars = string.ascii_uppercase + string.ascii_lowercase + string.digits |
19 | 20 |
|
20 |
| -with open(outfile, 'w') as fout: |
21 |
| - d = yaml.dump(data, fout) |
| 21 | + for _ in range(0, 100): |
| 22 | + # generate random filename under rootdir |
| 23 | + filepath = rootdir + ''.join(random.choices(chars, k=12)) |
| 24 | + # generate random file contents that are b64 encoded |
| 25 | + rand_chars = ''.join(random.choices(chars, k=100)) |
| 26 | + full_source = sourceb + b64string(rand_chars) |
| 27 | + # build the dict for the file entry and add to files list |
| 28 | + filedef = {'contents': {'source': full_source}, 'filesystem': 'root', 'path': filepath} |
| 29 | + files.append(filedef) |
| 30 | + |
| 31 | + with open(infile) as fin: |
| 32 | + data = yaml.load(fin, Loader=yaml.FullLoader) |
| 33 | + data['spec']['config']['storage']['files'] = files |
| 34 | + |
| 35 | + with open(outfile, 'w') as fout: |
| 36 | + yaml.dump(data, fout) |
| 37 | + |
| 38 | +if __name__ == "__main__": |
| 39 | + main() |
0 commit comments