File size: 1,820 Bytes
8c1771d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c9e62a
 
 
8c1771d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c9e62a
8c1771d
1
2
3
4
5
6
7
8
9
10
11
12
13
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
import json
import logging
import os
from pathlib import Path


def stats_pathname(pathname: Path | str):
    current_pathname = Path(pathname)
    return current_pathname.is_dir()


def create_folder_if_not_exists(pathname: Path | str):
    current_pathname = Path(pathname)
    try:
        print(f"Pathname exists? {current_pathname.exists()}, That's a folder? {current_pathname.is_dir()}...")
        logging.info(f"Pathname exists? {current_pathname.exists()}, That's a folder? {current_pathname.is_dir()}...")
        current_pathname.unlink(missing_ok=True)
    except PermissionError as pe:
        print(f"permission denied on removing pathname before folder creation:{pe}.")
        logging.error(f"permission denied on removing pathname before folder creation:{pe}.")
    except IsADirectoryError as errdir:
        print(f"that's a directory:{errdir}.")
        logging.error(f"that's a directory:{errdir}.")

    print(f"Creating pathname: {current_pathname} ...")
    logging.info(f"Creating pathname: {current_pathname} ...")
    current_pathname.mkdir(mode=0o770, parents=True, exist_ok=True)

    print(f"assertion: pathname exists and is a folder: {current_pathname} ...")
    logging.info(f"assertion: pathname exists and is a folder: {current_pathname} ...")
    assert current_pathname.is_dir()


if __name__ == '__main__':
    folders_string = os.getenv("FOLDERS_MAP")
    folders_dict = json.loads(folders_string)
    for folder_env_ref, folder_env_path in folders_dict.items():
        print(f"folder_env_ref:{folder_env_ref}, folder_env_path:{folder_env_path}.")
        logging.info(f"folder_env_ref:{folder_env_ref}, folder_env_path:{folder_env_path}.")
        create_folder_if_not_exists(folder_env_path)
        print("========")
        assert os.getenv(folder_env_ref) == folder_env_path