From b13182c80e7257d22b58d31944c7faca4ca2ef93 Mon Sep 17 00:00:00 2001 From: maksim Date: Mon, 23 Sep 2024 15:28:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC?= =?UTF-8?q?=D0=B0=20=D1=81=20Docker=20=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BF=D1=8C=D1=8E=D1=82=D0=B5=D1=80=D0=B5.=20=D0=A1=D0=BE?= =?UTF-8?q?=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=86=D0=B5=D1=81=D1=81=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kashin_maxim_lab_2/.gitignore | 1 + kashin_maxim_lab_2/docker-compose.yml | 7 +++++ kashin_maxim_lab_2/program_0/Dockerfile | 7 +++++ kashin_maxim_lab_2/program_0/main.py | 37 +++++++++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 kashin_maxim_lab_2/.gitignore create mode 100644 kashin_maxim_lab_2/docker-compose.yml create mode 100644 kashin_maxim_lab_2/program_0/Dockerfile create mode 100644 kashin_maxim_lab_2/program_0/main.py diff --git a/kashin_maxim_lab_2/.gitignore b/kashin_maxim_lab_2/.gitignore new file mode 100644 index 0000000..cef5ae5 --- /dev/null +++ b/kashin_maxim_lab_2/.gitignore @@ -0,0 +1 @@ +var/ \ No newline at end of file diff --git a/kashin_maxim_lab_2/docker-compose.yml b/kashin_maxim_lab_2/docker-compose.yml new file mode 100644 index 0000000..9b96362 --- /dev/null +++ b/kashin_maxim_lab_2/docker-compose.yml @@ -0,0 +1,7 @@ +services: + + program_0: + build: + context: ./program_0 + volumes: + - ./data:/var/data \ No newline at end of file diff --git a/kashin_maxim_lab_2/program_0/Dockerfile b/kashin_maxim_lab_2/program_0/Dockerfile new file mode 100644 index 0000000..bccadfc --- /dev/null +++ b/kashin_maxim_lab_2/program_0/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.12-slim + +WORKDIR /program_0 + +COPY main.py /program_0/ + +CMD ["python", "main.py"] \ 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 new file mode 100644 index 0000000..76490ab --- /dev/null +++ b/kashin_maxim_lab_2/program_0/main.py @@ -0,0 +1,37 @@ +import random +import os + +folder_path = './kashin_maxim_lab_2/var/data' + +def creat_folder(): + if not os.path.exists(folder_path): + os.makedirs(folder_path) + else: + print(f"Папка `{folder_path}` уже существует!") + +def delete_files_in_folder(): + for filename in os.listdir(folder_path): + file_path = os.path.join(folder_path, filename) + try: + if os.path.isfile(file_path): + os.remove(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+') + 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))] + return lines + +if os.path.exists(folder_path): + delete_files_in_folder() + creat_file() +else: + creat_folder() + creat_file() \ No newline at end of file