diff --git a/kashin_maxim_lab_2/docker-compose.yml b/kashin_maxim_lab_2/docker-compose.yml index 9b96362..29dc4c0 100644 --- a/kashin_maxim_lab_2/docker-compose.yml +++ b/kashin_maxim_lab_2/docker-compose.yml @@ -4,4 +4,4 @@ services: build: context: ./program_0 volumes: - - ./data:/var/data \ No newline at end of file + - ./var/data:/data \ No newline at end of file diff --git a/kashin_maxim_lab_2/program_0/main.py b/kashin_maxim_lab_2/program_0/main.py index 76490ab..9bc8417 100644 --- a/kashin_maxim_lab_2/program_0/main.py +++ b/kashin_maxim_lab_2/program_0/main.py @@ -1,11 +1,12 @@ import random import os -folder_path = './kashin_maxim_lab_2/var/data' +folder_path = '/data' def creat_folder(): if not os.path.exists(folder_path): os.makedirs(folder_path) + print(f"Папка `{folder_path}` создана!") else: print(f"Папка `{folder_path}` уже существует!") @@ -15,23 +16,29 @@ def delete_files_in_folder(): try: if os.path.isfile(file_path): os.remove(file_path) + print(f"Файл `{file_path}` удален.") except Exception as e: print(f'Ошибка при удалении файла {file_path}. {e}') def creat_file(): for i in range(random.randrange(10, 20)): file = open(f'{folder_path}/file_{i}.txt', 'w+') + print(f"Создан файл: {folder_path}/file_{i}.txt") for i in range(random.randrange(10, 50)): file.write(f'{create_lines()} \n') file.close() def create_lines(): - lines = [i for i in range(random.randrange(1, 50),random.randrange(50, 100),random.randrange(1, 10))] + lines = [i for i in range(random.randrange(1, 50), random.randrange(50, 100), random.randrange(1, 10))] return lines if os.path.exists(folder_path): + print(f"Папка `{folder_path}` существует, удаляем старые файлы...") delete_files_in_folder() creat_file() else: + print(f"Папка `{folder_path}` не существует, создаем...") creat_folder() - creat_file() \ No newline at end of file + creat_file() + +print("Скрипт на создание файлов выполнен.")