Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions 1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os


def check_or_make_folder(path):
if os.path.exists(path):
print(f'path alredy exists {path}')
else:
print(f'make folder {path}')
os.mkdir(path)


def make_tree_folders(soucre_di):
'''make folders from dict'''
for key, value in soucre_di.items():
check_or_make_folder(key)
for i in value:
path = os.path.join(key, i)
check_or_make_folder(path)


if __name__ == '__main__':
soucre_di = {'my_project': ['settings', 'mainapp', 'adminapp', 'authapp']}
make_tree_folders(soucre_di)
43 changes: 43 additions & 0 deletions 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os


def check_or_make_folder(path, is_file=False):
if os.path.exists(path):
print(f'path alredy exists {path}')
else:
print(f'make new folder {path}')
if is_file:
with open(os.path.join(path), 'w') as file:
file.write(' ')
else:
os.mkdir(path)


def make_tree_folders(source, path=False):
'''make folders from dict'''
if type(source) == str:
# print(f' in str block {source}, {type(source)}')
check_or_make_folder(os.path.join(path, source), is_file=True)
elif type(source) == list:
# print(f' in list block {source}, {type(source)}')
for i in source:
# print(i, type(i), path)
make_tree_folders(i, path)
elif type(source) == dict:
# print(f' in dict block {source}, {type(source)}')
for k, v in source.items():
new_path = os.path.join(path, k) if path else k
check_or_make_folder(new_path)
make_tree_folders(v, new_path)
else:
print(f'not correct value {source} type {type(source)}')


if __name__ == '__main__':
soucre_di = {
'my_project': [
{'settings': ['__init__.py', 'dev.py', 'prod.py']},
{'mainapp': [' __init__.py', 'models.py', 'views.py', {'templates': {'mainapp': ['base.html', 'index.html']}}]},
{'authapp': ['__init__.py', 'models.py', 'views.py', {'templates': {'authapp': ['base.html', 'index.html']}}]}
]}
make_tree_folders(soucre_di)
16 changes: 16 additions & 0 deletions 3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
import shutil

cwd = 'my_project/'
new_cwd = 'my_project/templates'
print(os.getcwd())

for root, dirs, files in os.walk(cwd):
for dir in dirs:
old_path = os.path.join(root, dir)
if old_path.endswith('templates'):
try:
shutil.copytree(old_path, new_cwd)
except FileExistsError:
new_cwd += '1'
shutil.copytree(old_path, new_cwd)
33 changes: 33 additions & 0 deletions 4_5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
from os import stat
import json


di_sizes = {100: (0, []), 1000: (0, []), 10000: (0, []), 100000: (0, [])}
dir_path = '/run/user/1000/gvfs/smb-share:server=keenetic-2254.local,share=server/Project/GeekBrains/homework/7/some_data'


def get_info_file(size):
'''get file stats'''
count, tp = di_sizes[size]
count += 1
tp.append(path.split('.')[-1])
tp = list(set(tp))
di_sizes[size] = (count, tp)


files = os.listdir(dir_path)
for file in files:
path = os.path.join(dir_path, file)
if 0 < stat(path).st_size < 100:
get_info_file(100)
elif 100 < stat(path).st_size < 1000:
get_info_file(1000)
elif 1000 < stat(path).st_size < 10000:
get_info_file(10000)
elif 10000 < stat(path).st_size < 100000:
get_info_file(100000)

print(di_sizes)
with open('summary.json', 'w') as file:
json.dump(di_sizes, file)
1 change: 1 addition & 0 deletions summary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"100": [0, []], "1000": [10, ["bin"]], "10000": [87, ["bin"]], "100000": [902, ["bin"]]}