From 266c9a6dd8618b7df282b71a7feddc2d00c29b6b Mon Sep 17 00:00:00 2001 From: Alexandra Date: Mon, 20 Sep 2021 13:47:06 +0300 Subject: [PATCH 1/3] HW_7 --- T7_1.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 T7_1.py diff --git a/T7_1.py b/T7_1.py new file mode 100644 index 0000000..0cede6c --- /dev/null +++ b/T7_1.py @@ -0,0 +1,9 @@ +import os + +project_list = ['settings', 'mainapp', 'adminapp', 'authapp'] +for name in project_list: + dir_path = os.path.join('my_project', name) + if not os.path.exists(dir_path): + os.makedirs(dir_path) + else: + print(f'Папка с именем {name} уже существует') From 798bb153cd15ff7ce4f7407d4cf174696c5153cb Mon Sep 17 00:00:00 2001 From: Alexandra Date: Mon, 20 Sep 2021 13:48:07 +0300 Subject: [PATCH 2/3] HW_7 --- T7_3.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 T7_3.py diff --git a/T7_3.py b/T7_3.py new file mode 100644 index 0000000..8b71c8b --- /dev/null +++ b/T7_3.py @@ -0,0 +1,7 @@ +import yaml +from pprint import pprint + +with open('config.yaml') as f: + templates = yaml.safe_load(f) + +print(templates) \ No newline at end of file From a30f1bab270b2c1cce4b0bb481b871d7d7a28856 Mon Sep 17 00:00:00 2001 From: Alexandra Date: Thu, 23 Sep 2021 12:33:28 +0300 Subject: [PATCH 3/3] HW_7 --- T7_3.py | 16 +++++++++++----- T7_4.py | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 T7_4.py diff --git a/T7_3.py b/T7_3.py index 8b71c8b..1df1795 100644 --- a/T7_3.py +++ b/T7_3.py @@ -1,7 +1,13 @@ -import yaml -from pprint import pprint +from os import path, walk, listdir +import shutil -with open('config.yaml') as f: - templates = yaml.safe_load(f) +project_name = 'my_project' -print(templates) \ No newline at end of file +try: + for root, dirs, files in walk(project_name): + print(root, dirs, files) + if 'templates' in dirs and root != project_name: + for el in listdir(path.join(root, 'templates')): + shutil.copytree(path.join(root, 'templates', el), path.join(project_name, 'templates', el)) +except FileExistsError: + print('Шаболоны уже собраны в папку Templates') diff --git a/T7_4.py b/T7_4.py new file mode 100644 index 0000000..b6bd5e4 --- /dev/null +++ b/T7_4.py @@ -0,0 +1,24 @@ +import os +from collections import defaultdict + +import django + +root_dir = django.__path__[0] +django_files = defaultdict(int) +size_list_new = [] +for root, dirs, files in os.walk(root_dir): + for file in files: + if os.stat(os.path.join(root, file)).st_size < 100: + size_list_new.append('100') + elif 100 <= os.stat(os.path.join(root, file)).st_size < 1000: + size_list_new.append('1000') + elif 1000 <= os.stat(os.path.join(root, file)).st_size < 10000: + size_list_new.append('10000') + else: + size_list_new.append('100000') + +for el in size_list_new: + django_files[el] += 1 + +for key, value in sorted(django_files.items()): + print(f'{key}: {value}') \ No newline at end of file