Skip to content

Commit e8c852d

Browse files
committed
bz1866117.py: clean up script according to pylint
1 parent f1ae771 commit e8c852d

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

MachineConfigs/bz1866117.py

+32-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
#!/usr/bin/env python
22

3+
import base64
4+
import random
5+
import string
36
import yaml
47

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')
911

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,"
1517

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
1920

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

Comments
 (0)