|
15 | 15 | You should have received a copy of the GNU General Public License
|
16 | 16 | along with this program. If not, see <https://www.gnu.org/licenses/>.
|
17 | 17 | """
|
| 18 | +import os |
18 | 19 | import re
|
| 20 | +import enum |
| 21 | +from pathlib import Path |
19 | 22 |
|
| 23 | +from .exceptions import FileNotFoundException |
| 24 | +from .exceptions import ObjectNotAFileException |
20 | 25 | from .exceptions import HashStrNotValidException
|
| 26 | +from .exceptions import MissingFilePermissionException |
21 | 27 | from .exceptions import HashAlgorithmNotSupportedException
|
22 | 28 |
|
23 | 29 | from .config import SUPPORTED_HASH_ALGOS
|
24 | 30 |
|
| 31 | +HashAlgoEnum = enum.Enum( |
| 32 | + "HashAlgoEnum", {key: key for key in SUPPORTED_HASH_ALGOS.keys()} |
| 33 | +) |
| 34 | + |
25 | 35 |
|
26 | 36 | def detect_hash_algo(checksum_str: str):
|
27 | 37 | """
|
@@ -58,3 +68,35 @@ def validate_checksum_str(checksum_str: str):
|
58 | 68 | raise HashStrNotValidException(
|
59 | 69 | detected_hash_algo=hash_name, checksum_str=checksum_str
|
60 | 70 | )
|
| 71 | + |
| 72 | + |
| 73 | +def get_file_path_from_str(str_path: str): |
| 74 | + """ |
| 75 | + Checks if path is a file and there is read access to it then return a Path object |
| 76 | +
|
| 77 | + :param str_path: provided file path |
| 78 | + :return: file path |
| 79 | + :rtype: Path |
| 80 | + """ |
| 81 | + path_object = Path(str_path) |
| 82 | + if path_object.is_file(): |
| 83 | + path_object = path_object.resolve() |
| 84 | + if os.access(path_object, os.R_OK): |
| 85 | + return path_object |
| 86 | + else: |
| 87 | + raise MissingFilePermissionException(file_path=str_path) |
| 88 | + elif not path_object.exists(): |
| 89 | + raise FileNotFoundException(file_path=str_path) |
| 90 | + else: |
| 91 | + raise ObjectNotAFileException(file_path=str_path) |
| 92 | + |
| 93 | + |
| 94 | +class IntegrityValidator: |
| 95 | + def __init__(self, str_path: str): |
| 96 | + self.file = get_file_path_from_str(str_path) |
| 97 | + |
| 98 | + def validate_file_integrity(self): |
| 99 | + pass |
| 100 | + |
| 101 | + def get_file_checksum(self): |
| 102 | + pass |
0 commit comments