forked from PermanentOrg/sftp-qa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-files.py
executable file
·61 lines (47 loc) · 1.65 KB
/
create-files.py
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
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
import os
import random
import string
import argparse
QUANTITY = 1000
FILE_NAME_LENGTH = 10
FILE_SIZE = 1 # 1 Byte
ROOT_NAME = "1000-1B"
SPECIAL_FILES_ROOT = "test-tree/special-files/"
def random_string(length=FILE_NAME_LENGTH):
"Generate random string of specified length"
return "".join(random.choices(string.ascii_lowercase, k=length))
def parse_cli():
"""Prepare parser"""
parser = argparse.ArgumentParser(prog="create-files", description="Generate files")
parser.add_argument("--quantity", help="Number of files to be generated", type=int)
parser.add_argument("--size", help="Size of each file to be generated", type=int)
parser.add_argument("--root-name", help="Download zip files for testing")
return parser.parse_args()
def write_file(path, size):
"""Write file of {size} to {path}"""
with open(SPECIAL_FILES_ROOT + "/" + path, "wb") as out:
out.seek((size) - 1)
out.write(b"\0")
def check_path(path):
"""Make sure given path exists within special files directory"""
if not os.path.exists(SPECIAL_FILES_ROOT):
os.makedirs(SPECIAL_FILES_ROOT)
if not os.path.exists(SPECIAL_FILES_ROOT + "/" + path):
os.makedirs(SPECIAL_FILES_ROOT + "/" + path)
def main():
global QUANTITY
global FILE_SIZE
global ROOT_NAME
args = parse_cli()
if args.quantity:
QUANTITY = args.quantity
if args.size:
FILE_SIZE = args.size
if args.root_name:
ROOT_NAME = args.root_name
check_path(ROOT_NAME)
for _ in range(0, QUANTITY):
write_file(ROOT_NAME + "/" + random_string(), FILE_SIZE)
if __name__ == "__main__":
main()