-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_shutil.make_archive.py
63 lines (41 loc) · 1.88 KB
/
file_shutil.make_archive.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
62
63
import shutil
from pathlib import Path
from random import randint, choice, choices
MESSAGE = "Hello, Привіт"
def get_random_filename():
random_value = '()+,-0123456789;=@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz' \
'{}~абвгдеєжзиіїйклмнопрстуфхцчшщьюяАБВГДЕЄЖЗИІЇЙКЛМНОПРСТУФХЦЧШЩЬЮЯ'
return ''.join(choices(random_value, k=8))
def generate_text_files(path):
documents = ('DOC', 'DOCX', 'TXT', 'PDF', 'XLSX', 'PPTX')
with open(path / f"{get_random_filename()}.{choice(documents).lower()}", "wb") as f:
f.write(MESSAGE.encode())
def generate_archive_files(path):
archive = ('ZIP', 'GZTAR', 'TAR')
shutil.make_archive(f"{path}/{get_random_filename()}", f'{choice(archive).lower()}', path)
def generate_folders(path):
folder_name = ['temp', 'folder', 'dir', 'tmp', 'OMG', 'is_it_true', 'no_way', 'find_it']
folder_path = Path(
f"{path}/" + '/'.join(choices(folder_name, weights=[10, 10, 1, 1, 1, 1, 1, 1], k=randint(5, len(folder_name)))))
folder_path.mkdir(parents=True, exist_ok=True)
def generate_folder_forest(path):
for i in range(0, randint(2, 5)):
generate_folders(path)
def generate_random_files(path):
for i in range(3, randint(5, 7)):
function_list = [generate_text_files, generate_archive_files]
choice(function_list)(path)
def parse_folder_recursion(path):
for elements in path.iterdir():
if elements.is_dir():
generate_random_files(path)
parse_folder_recursion(elements)
def exist_parent_folder(path):
path.mkdir(parents=True, exist_ok=True)
def file_generator(path):
exist_parent_folder(path)
generate_folder_forest(path)
parse_folder_recursion(path)
if __name__ == '__main__':
parent_folder_path = Path("Temp")
file_generator(parent_folder_path)