Skip to content
Merged
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
20 changes: 0 additions & 20 deletions Makefile

This file was deleted.

6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,3 @@ coverage run -m pytest
coverage report
coverage html
```

## Sphinx

```sh
sphinx-quickstart
```
31 changes: 0 additions & 31 deletions conf.py

This file was deleted.

29 changes: 0 additions & 29 deletions index.rst

This file was deleted.

35 changes: 0 additions & 35 deletions make.bat

This file was deleted.

11 changes: 0 additions & 11 deletions modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
# -*- coding: utf-8 -*-
# @Proyect: Personal
# @Author: Adrian Epifanio
# @File: __init__.py
# @Author: Adrian Epifanio
# @Date: 2025-03-28 17:17:52
# @Email: adrianepi@gmail.com
# @GitHub: https://github.com/AdrianEpi
# @Last Modified by: Adrian Epifanio
# @Last Modified time: 2025-03-28 17:17:52
# @Description: ...
4 changes: 2 additions & 2 deletions modules/datetime/date.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
# @Proyect: Python
# @Proyect: Python Modules
# @Author: Adrian Epifanio
# @File: date.py
# @Author: Adrian Epifanio
# @Date: 2025-03-28 17:08:06
# @Email: adrianepi@gmail.com
# @GitHub: https://github.com/AdrianEpi
# @Last Modified by: Adrian Epifanio
# @Last Modified time: 2025-03-28 17:26:05
# @Last Modified time: 2025-03-29 09:46:34
# @Description: This file describes a Date class


Expand Down
4 changes: 2 additions & 2 deletions modules/errors/error_handler.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
# @Proyect: Personal
# @Proyect: Python Modules
# @Author: Adrian Epifanio
# @File: error_handler.py
# @Author: Adrian Epifanio
# @Date: 2025-03-28 17:08:45
# @Email: adrianepi@gmail.com
# @GitHub: https://github.com/AdrianEpi
# @Last Modified by: Adrian Epifanio
# @Last Modified time: 2025-03-29 08:25:00
# @Last Modified time: 2025-03-29 09:46:13
# @Description: This file describes an ErrorHandler


Expand Down
File renamed without changes.
178 changes: 178 additions & 0 deletions modules/filesystem/dir_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# -*- coding: utf-8 -*-
# @Proyect: Python Modules
# @Author: Adrian Epifanio
# @File: dir_manager.py
# @Author: Adrian Epifanio
# @Date: 2025-03-29 09:37:27
# @Email: adrianepi@gmail.com
# @GitHub: https://github.com/AdrianEpi
# @Last Modified by: Adrian Epifanio
# @Last Modified time: 2025-03-29 10:24:16
# @Description: This file describes a directory manager. Contains all
# the necessary methods to work with directories in the OS.

import os
import shutil

class DirManager:
"""
This class describes a directory manager for the OS.
"""

@staticmethod
def list_dirs(path: str) -> list:
"""
List all the directories in the given path

:param path: The path
:type path: str

:returns: List with the directories names
:rtype: list
"""
try:
return [name for name in os.listdir(path) if os.path.isdir(os.path.join(path, name))]
except FileNotFoundError:
return f"Error: The directory '{path}' does not exist."
except PermissionError:
return f"Error: Permission denied for accessing '{path}'."


@staticmethod
def list_files(path: str, extension = None) -> list:
"""
List all the files in the given path with the given extension, it gets
all the files with all the extension if no extension is provided.

:param path: The path
:type path: str
:param extension: The extension
:type extension: str

:returns: List of files
:rtype: list
"""
try:
if extension:
return [name for name in os.listdir(path) if os.path.isfile(os.path.join(path, name)) and name.endswith(extension)]
else:
return [name for name in os.listdir(path) if os.path.isfile(os.path.join(path, name))]
except FileNotFoundError:
return f"Error: The directory '{path}' does not exist."
except PermissionError:
return f"Error: Permission denied for accessing '{path}'."


@staticmethod
def list_all_files_recursive(path: str, extension = None) -> list:
"""
List all files in the given dir and in all the subdirs of that directory

:param path: The path
:type path: str
:param extension: The extension
:type extension: str

:returns: The list of files
:rtype: list
"""
files = DirManager.list_files(path, extension)
dirs = DirManager.list_dirs(path)
for d in dirs:
files += DirManager.list_all_files_recursive(path=os.path.join(path, d), extension=extension)
return files


@staticmethod
def dir_exist(path: str) -> bool:
"""
Checks if a dir exists or not

:param path: The file name
:type path: str

:returns: True if the dir exists, false otherwise
:rtype: bool
"""
return os.path.isdir(path)


@staticmethod
def create_dir(path=''):
"""
Creates a dir.

:param path: The path
:type path: str
"""
try:
os.makedirs(path)
except Exception as e:
return f"Error while creating dir '{path}': {e}"


@staticmethod
def create_dir_hierarchy(data: list, path: str) -> list:
"""
Creates a dir hierarchy recursively.. If a data element is a list, then
that full list of dirs will be created under the previous data element or
each of the previous data elements in case this was a list. Each of the
elements in data will be a father of all the next elements of type list in
data.
Example [A, B, C]
∟ A
∟ B
∟ C
Example [[A, B], X, Y, Z]:
A
∟ X
∟ Y
∟ Z
B
∟ X
∟ Y
∟ Z
:param data: The the hierarchy list of directory names.
:type data: list
:param path: The path
:type path: str

:returns: List with the created paths
:rtype: list
"""
path_list = []
for i in range(0, len(data), 1):
if type(data[i]) == list:
path_l = DirManager.create_dir_hierarchy(data = data[i], path = path)
for j in path_l:
DirManager.create_dir_hierarchy(data = data[i + 1:], path = j)
break
elif DirManager.dir_exist(path):
new_path = path + '/' + data[i]
if(not DirManager.dir_exist(new_path)):
DirManager.create_dir(path = new_path)
path_list.append(new_path)
return path_list


@staticmethod
def delete_dir(path: str):
"""
Deletes a dir and all the content in it

:param path: The path
:type path: str
"""
if DirManager.dir_exist(path):
shutil.rmtree(path)


@staticmethod
def get_current_dir() -> str:
"""
Gets the current dir.

:returns: The current dir.
:rtype: str
"""
return os.getcwd() + '/'
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-
# @Proyect: Personal
# @Proyect: Python Modules
# @Author: Adrian Epifanio
# @File: file_manager.py
# @Author: Adrian Epifanio
# @Date: 2025-03-29 08:04:19
# @Email: adrianepi@gmail.com
# @GitHub: https://github.com/AdrianEpi
# @Last Modified by: Adrian Epifanio
# @Last Modified time: 2025-03-29 09:12:34
# @Last Modified time: 2025-03-29 09:45:52
# @Description: This file describes a file manager. Contains all
# the necessary methods to work with files and directories.
# the necessary methods to work with files.


import os
Expand All @@ -19,7 +19,7 @@
class FileManager:
"""
This class describes a file manager, it cotains all the static methods
needed to work with files, folders and directories.
needed to work with files.
"""


Expand Down
File renamed without changes.
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
pytest>=8.3.5 # Testing
coverage>=7.7.1 # Coverage
sphinx>=8.1.3 # Documentation
sphinx-rtd-theme>=3.0.2 # Github Pages Documentation

-r modules/datetime/requirements.txt
-r modules/files/requirements.txt
-r modules/filesystem/requirements.txt
-r modules/errors/requirements.txt
Loading