forked from Alexey/DAS_2024_1
Чистый неподкупный рабочий код 2-й лабораторной
This commit is contained in:
parent
8a96320fd5
commit
1213b5db3c
2
bogdanov_dmitry_lab_2/.gitignore
vendored
Normal file
2
bogdanov_dmitry_lab_2/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
data/
|
||||
result/
|
7
bogdanov_dmitry_lab_2/app-1/Dockerfile
Normal file
7
bogdanov_dmitry_lab_2/app-1/Dockerfile
Normal file
@ -0,0 +1,7 @@
|
||||
FROM python:latest
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY app.py /app/
|
||||
|
||||
CMD ["python", "app.py"]
|
22
bogdanov_dmitry_lab_2/app-1/app.py
Normal file
22
bogdanov_dmitry_lab_2/app-1/app.py
Normal file
@ -0,0 +1,22 @@
|
||||
import os
|
||||
|
||||
# Variant 2
|
||||
def solve(dir_files, dir_result, filename_result):
|
||||
filenames = os.listdir(dir_files)
|
||||
result = ''
|
||||
for filename in filenames:
|
||||
filepath = os.path.join(dir_files, filename)
|
||||
file = open(filepath, "r")
|
||||
result += f"{file.readline()}"
|
||||
file.close()
|
||||
|
||||
if not os.path.exists(dir_result):
|
||||
os.makedirs(dir_result)
|
||||
if os.listdir(dir_result):
|
||||
return
|
||||
result_file = open(os.path.join(dir_result, filename_result), "w")
|
||||
result_file.write(result)
|
||||
result_file.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
solve('/var/data', '/var/result', 'data.txt')
|
7
bogdanov_dmitry_lab_2/app-2/Dockerfile
Normal file
7
bogdanov_dmitry_lab_2/app-2/Dockerfile
Normal file
@ -0,0 +1,7 @@
|
||||
FROM python:latest
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY app.py /app/
|
||||
|
||||
CMD ["python", "app.py"]
|
15
bogdanov_dmitry_lab_2/app-2/app.py
Normal file
15
bogdanov_dmitry_lab_2/app-2/app.py
Normal file
@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
# Variant 1
|
||||
def solve(dir_input, dir_result, filename_result):
|
||||
file_input = open(os.path.join(dir_input, 'data.txt'))
|
||||
|
||||
inputs = [int(line) for line in file_input.readlines()]
|
||||
if inputs:
|
||||
result = max(inputs) ** 2
|
||||
file_result = open(os.path.join(dir_result, filename_result), "w")
|
||||
file_result.write(str(result))
|
||||
file_result.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
solve("/var/result", '/var/result', 'result.txt')
|
7
bogdanov_dmitry_lab_2/app-generator/Dockerfile
Normal file
7
bogdanov_dmitry_lab_2/app-generator/Dockerfile
Normal file
@ -0,0 +1,7 @@
|
||||
FROM python:latest
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY generator.py /app/
|
||||
|
||||
CMD ["python", "generate_files.py"]
|
26
bogdanov_dmitry_lab_2/app-generator/generator.py
Normal file
26
bogdanov_dmitry_lab_2/app-generator/generator.py
Normal file
@ -0,0 +1,26 @@
|
||||
import os
|
||||
import random as rnd
|
||||
import string
|
||||
|
||||
|
||||
def generate_filename(l):
|
||||
return ''.join(rnd.choices(string.ascii_lowercase + string.digits, k=l)) + '.txt'
|
||||
|
||||
def generate_files(dir, num_files, num_lines):
|
||||
if not os.path.exists(dir):
|
||||
os.makedirs(dir)
|
||||
|
||||
if os.listdir(dir):
|
||||
return
|
||||
|
||||
for i in range(num_files):
|
||||
filename = generate_filename(20)
|
||||
filepath = os.path.join(dir, filename)
|
||||
|
||||
file = open(filepath, "w")
|
||||
for j in range(num_lines):
|
||||
file.write(f"{rnd.randint(-1000, 1000)}\n")
|
||||
file.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
generate_files('/var/data', 50, 50)
|
24
bogdanov_dmitry_lab_2/docker-compose.yaml
Normal file
24
bogdanov_dmitry_lab_2/docker-compose.yaml
Normal file
@ -0,0 +1,24 @@
|
||||
services:
|
||||
generator:
|
||||
build:
|
||||
context: ./app-generator
|
||||
volumes:
|
||||
- ./data:/var/data
|
||||
entrypoint: python generator.py
|
||||
|
||||
app1:
|
||||
build:
|
||||
context: ./app-1
|
||||
volumes:
|
||||
- ./data:/var/data
|
||||
- ./result:/var/result
|
||||
depends_on:
|
||||
- generator
|
||||
|
||||
app2:
|
||||
build:
|
||||
context: ./app-2
|
||||
volumes:
|
||||
- ./result:/var/result
|
||||
depends_on:
|
||||
- app1
|
Loading…
Reference in New Issue
Block a user