Skip to content

Project directory setup

Module for project directory setup.

Methods

create_dirs: Creates the main project directory and the associated subdirectories for the project.

check_if_dir_exists: Checks if the directory about to be created already exists.

check_if_dir_exists(dir_path)

Check if directory exists.

Parameters:

Name Type Description Default
dir_path str

String with path to the directory to check if it exists.

required

Returns:

Name Type Description
dir_exists bool

Boolean value representing whether the directory exists or not.

Source code in report_generator/project_setup/project_directory_setup.py
48
49
50
51
52
53
54
55
56
57
58
59
60
def check_if_dir_exists(dir_path: str) -> bool:
    """Check if directory exists.

    Args:
        dir_path (str):     String with path to the directory to check
                            if it exists.

    Returns:
        dir_exists (bool):  Boolean value representing whether the directory
                            exists or not.
    """
    dir_exists = os.path.exists(dir_path)
    return dir_exists

create_dirs(home_dir, directory_name)

Create the project directories.

Creates directories for project files to be inserted.

Examples:

Example of use.

Parameters:

Name Type Description Default
home_dir str

String value for the path to the home directory.

required
directory_name str

String value for the name of the directory that is created.

required

Returns:

Name Type Description
dir_path str

String value for the path to the project's directory

Source code in report_generator/project_setup/project_directory_setup.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def create_dirs(home_dir: str, directory_name: str) -> str:
    """Create the project directories.

    Creates directories for project files to be inserted.

    Examples:
        Example of use.

    Args:
        home_dir (str):         String value for the path to the
                                home directory.

        directory_name (str):   String value for the name of the
                                directory that is created.
    Returns:
        dir_path (str):         String value for the path to the
                                project's directory
    """
    dir_path = os.path.join(home_dir, directory_name)

    if check_if_dir_exists(dir_path):
        raise FileExistsError(f"Directory {directory_name} already exists")

    os.makedirs(dir_path)
    os.makedirs(os.path.join(dir_path, "data"))
    os.makedirs(os.path.join(dir_path, "data", "database"))
    os.makedirs(os.path.join(dir_path, "data", "excel_src"))
    os.makedirs(os.path.join(dir_path, "data", "duplicates"))
    # os.makedirs(os.path.join(dir_path, "data", "locations"))
    os.makedirs(os.path.join(dir_path, "report"))

    return dir_path