From 6ce78e60ada7ddf7eed9c0d016692a70c8f44efc Mon Sep 17 00:00:00 2001 From: maksim Date: Mon, 23 Sep 2024 16:00:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D0=B8=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8E=20=D1=84?= =?UTF-8?q?=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kashin_maxim_lab_2/docker-compose.yml | 2 +- kashin_maxim_lab_2/program_0/main.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) 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("Скрипт на создание файлов выполнен.")