-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split collection_reader file
- Loading branch information
1 parent
f169b3a
commit effa3d8
Showing
16 changed files
with
615 additions
and
513 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright 2022 TOSIT.IO | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from .check_collection_structure import ( | ||
MissingMandatoryDirectoryError, | ||
PathDoesNotExistsError, | ||
PathIsNotADirectoryError, | ||
) | ||
from .collections import Collections |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright 2022 TOSIT.IO | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
from tdp.core.constants import ( | ||
DAG_DIRECTORY_NAME, | ||
DEFAULT_VARS_DIRECTORY_NAME, | ||
PLAYBOOKS_DIRECTORY_NAME, | ||
) | ||
|
||
MANDATORY_DIRECTORIES = [ | ||
DAG_DIRECTORY_NAME, | ||
DEFAULT_VARS_DIRECTORY_NAME, | ||
PLAYBOOKS_DIRECTORY_NAME, | ||
] | ||
|
||
|
||
class PathDoesNotExistsError(Exception): | ||
pass | ||
|
||
|
||
class PathIsNotADirectoryError(Exception): | ||
pass | ||
|
||
|
||
class MissingMandatoryDirectoryError(Exception): | ||
pass | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def check_collection_structure(path: Path) -> None: | ||
"""Check the structure of a collection. | ||
Args: | ||
path: Path to the collection. | ||
Raises: | ||
PathDoesNotExistsError: If the path does not exists. | ||
PathIsNotADirectoryError: If the path is not a directory. | ||
MissingMandatoryDirectoryError: If the collection does not contain a mandatory directory. | ||
""" | ||
if not path.exists(): | ||
raise PathDoesNotExistsError(f"{path} does not exists.") | ||
if not path.is_dir(): | ||
raise PathIsNotADirectoryError(f"{path} is not a directory.") | ||
for mandatory_directory in MANDATORY_DIRECTORIES: | ||
mandatory_path = path / mandatory_directory | ||
if not mandatory_path.exists() or not mandatory_path.is_dir(): | ||
raise MissingMandatoryDirectoryError( | ||
f"{path} does not contain the mandatory directory {mandatory_directory}.", | ||
) |
Oops, something went wrong.