import json
import os
from os.path import dirname, join

MAIN_DIRECTORY = dirname(dirname(__file__))


def get_full_path(*path):
    return join(MAIN_DIRECTORY, *path)


def get_model_data_path(*path):
    return get_full_path("model", *path)


def get_resources_data_path(*path):
    return get_full_path("resources", *path)


def get_utils_data_path(*path):
    return get_full_path("utils", *path)


def check_dir_if_not_create(path):
    if not check_dir_if_exists(path):
        os.makedirs(path)


def check_dir_if_exists(path):
    return os.path.exists(path)


# custom labels data   utils/custom_labels.json
def get_custom_labels():
    try:
        with open(get_utils_data_path("custom_labels.json"), 'rb') as f:
            return json.loads(f.read())
    except Exception as ex:
        print('utils/custom_labels.json')
        return []


# custom labels data   utils/custom_labels.json
def get_custom_label_object():
    try:
        obj = {}
        for val in get_custom_labels():
            obj[val] = ''

        return obj
    except Exception as ex:
        print('Exception',str(ex))
        return {}


def remove_file(filename):
    try:
        os.remove(filename)
        print("removed")
    except OSError as e:
        print("Error",e)
        pass
