# Path: django_docker_helpers/utils.py
# def dot_path(obj: t.Union[t.Dict, object],
#              path: str,
#              default: t.Any = None,
#              separator: str = '.'):
#     """
#     Provides an access to elements of a mixed dict/object type by a delimiter-separated path.
#     ::
# 
#         class O1:
#             my_dict = {'a': {'b': [1, 2]}}
# 
#         class O2:
#             def __init__(self):
#                 self.nested = O1()
# 
#         class O3:
#             final = O2()
# 
#         o = O3()
#         assert utils.dot_path(o, 'final.nested.my_dict.a.b.1') == 2
# 
#     .. testoutput::
# 
#         True
# 
#     :param obj: object or dict
#     :param path: path to value
#     :param default: default value if chain resolve failed
#     :param separator: ``.`` by default
#     :return: value or default
#     """
#     path_items = path.split(separator)
#     val = obj
#     sentinel = object()
#     for item in path_items:
#         if isinstance(val, dict):
#             val = val.get(item, sentinel)
#             if val is sentinel:
#                 return default
#         elif isinstance(val, (list, tuple)):
#             try:
#                 val = val[int(item)]
#             except (IndexError, TypeError, ValueError):
#                 return default
#         else:
#             val = getattr(val, item, sentinel)
#             if val is sentinel:
#                 return default
#     return val
# 
# def run_env_once(f: t.Callable) -> t.Callable:
#     """
#     A decorator to prevent ``manage.py`` from running code twice for everything.
#     (https://stackoverflow.com/questions/16546652/why-does-django-run-everything-twice)
# 
#     :param f: function or method to decorate
#     :return: callable
#     """
# 
#     @wraps(f)
#     def wrapper(*args, **kwargs):
#         key = _build_cache_key_for_env(wrapper.__name__, *args, **kwargs)
#         has_run = os.environ.get(key)
#         if has_run == '1':
#             return
#         result = f(*args, **kwargs)
#         os.environ[key] = '1'
#         return result
# 
#     return wrapper
# 
# def wf(raw_str: str,
#        flush: bool = True,
#        prevent_completion_polluting: bool = True,
#        stream: t.TextIO = sys.stdout):
#     """
#     Writes a given ``raw_str`` into a ``stream``. Ignores output if ``prevent_completion_polluting`` is set and there's
#     no extra ``sys.argv`` arguments present (a bash completion issue).
# 
#     :param raw_str: a raw string to print
#     :param flush: execute ``flush()``
#     :param prevent_completion_polluting: don't write anything if ``len(sys.argv) <= 1``
#     :param stream: ``sys.stdout`` by default
#     :return: None
#     """
#     if prevent_completion_polluting and len(sys.argv) <= 1:
#         return
# 
#     stream.write(raw_str)
#     flush and hasattr(stream, 'flush') and stream.flush()


from django.core.handlers.wsgi import WSGIHandler
from django.core.management import execute_from_command_line
from django_docker_helpers.utils import dot_path, run_env_once, wf
    from django.conf import settings
    from django.db import IntegrityError
        from django.contrib.auth.models import User
    from gunicorn.app.base import Application
def create_admin(user_config_path: str = 'CONFIG.superuser') -> bool:
    """
    Creates a superuser from a specified dict/object bundle located at ``user_config_path``.
    Skips if the specified object contains no email or no username.
    If a user with the specified username already exists and has no usable password it updates user's password with
    a specified one.

    ``user_config_path`` can accept any path to a deep nested object, like dict of dicts,
    object of dicts of objects, and so on. Let's assume you have this weird config in your ``settings.py``:
    ::

        class MyConfigObject:
            my_var = {
                'user': {
                    'username': 'user',
                    'password': 'qwe',
                    'email': 'no@example.com',
                }
            }
        local_config = MyConfigObject()

    To access the ``'user'`` bundle you have to specify: ``local_config.my_var.user``.

    :param user_config_path: dot-separated path to object or dict, default is ``'CONFIG.superuser'``
    :return: ``True`` if user has been created, ``False`` otherwise
    """
    wf('Creating superuser... ', False)
    username, email, password = [
        dot_path(settings, '{0}.{1}'.format(user_config_path, 'username')),
        dot_path(settings, '{0}.{1}'.format(user_config_path, 'email')),

# Path: django_docker_helpers/utils.py
# def dot_path(obj: t.Union[t.Dict, object],
#              path: str,
#              default: t.Any = None,
#              separator: str = '.'):
#     """
#     Provides an access to elements of a mixed dict/object type by a delimiter-separated path.
#     ::
# 
#         class O1:
#             my_dict = {'a': {'b': [1, 2]}}
# 
#         class O2:
#             def __init__(self):
#                 self.nested = O1()
# 
#         class O3:
#             final = O2()
# 
#         o = O3()
#         assert utils.dot_path(o, 'final.nested.my_dict.a.b.1') == 2
# 
#     .. testoutput::
# 
#         True
# 
#     :param obj: object or dict
#     :param path: path to value
#     :param default: default value if chain resolve failed
#     :param separator: ``.`` by default
#     :return: value or default
#     """
#     path_items = path.split(separator)
#     val = obj
#     sentinel = object()
#     for item in path_items:
#         if isinstance(val, dict):
#             val = val.get(item, sentinel)
#             if val is sentinel:
#                 return default
#         elif isinstance(val, (list, tuple)):
#             try:
#                 val = val[int(item)]
#             except (IndexError, TypeError, ValueError):
#                 return default
#         else:
#             val = getattr(val, item, sentinel)
#             if val is sentinel:
#                 return default
#     return val
# 
# def run_env_once(f: t.Callable) -> t.Callable:
#     """
#     A decorator to prevent ``manage.py`` from running code twice for everything.
#     (https://stackoverflow.com/questions/16546652/why-does-django-run-everything-twice)
# 
#     :param f: function or method to decorate
#     :return: callable
#     """
# 
#     @wraps(f)
#     def wrapper(*args, **kwargs):
#         key = _build_cache_key_for_env(wrapper.__name__, *args, **kwargs)
#         has_run = os.environ.get(key)
#         if has_run == '1':
#             return
#         result = f(*args, **kwargs)
#         os.environ[key] = '1'
#         return result
# 
#     return wrapper
# 
# def wf(raw_str: str,
#        flush: bool = True,
#        prevent_completion_polluting: bool = True,
#        stream: t.TextIO = sys.stdout):
#     """
#     Writes a given ``raw_str`` into a ``stream``. Ignores output if ``prevent_completion_polluting`` is set and there's
#     no extra ``sys.argv`` arguments present (a bash completion issue).
# 
#     :param raw_str: a raw string to print
#     :param flush: execute ``flush()``
#     :param prevent_completion_polluting: don't write anything if ``len(sys.argv) <= 1``
#     :param stream: ``sys.stdout`` by default
#     :return: None
#     """
#     if prevent_completion_polluting and len(sys.argv) <= 1:
#         return
# 
#     stream.write(raw_str)
#     flush and hasattr(stream, 'flush') and stream.flush()


# Path: django_docker_helpers/management.py
from django.core.handlers.wsgi import WSGIHandler
from django.core.management import execute_from_command_line
from django_docker_helpers.utils import dot_path, run_env_once, wf
    from django.conf import settings
    from django.db import IntegrityError
        from django.contrib.auth.models import User
    from gunicorn.app.base import Application

def create_admin(user_config_path: str = 'CONFIG.superuser') -> bool:
    """
    Creates a superuser from a specified dict/object bundle located at ``user_config_path``.
    Skips if the specified object contains no email or no username.
    If a user with the specified username already exists and has no usable password it updates user's password with
    a specified one.

    ``user_config_path`` can accept any path to a deep nested object, like dict of dicts,
    object of dicts of objects, and so on. Let's assume you have this weird config in your ``settings.py``:
    ::

        class MyConfigObject:
            my_var = {
                'user': {
                    'username': 'user',
                    'password': 'qwe',
                    'email': 'no@example.com',
                }
            }
        local_config = MyConfigObject()

    To access the ``'user'`` bundle you have to specify: ``local_config.my_var.user``.

    :param user_config_path: dot-separated path to object or dict, default is ``'CONFIG.superuser'``
    :return: ``True`` if user has been created, ``False`` otherwise
    """
    wf('Creating superuser... ', False)
    username, email, password = [
        dot_path(settings, '{0}.{1}'.format(user_config_path, 'username')),
        dot_path(settings, '{0}.{1}'.format(user_config_path, 'email')),

        dot_path(settings, '{0}.{1}'.format(user_config_path, 'password')),