Exemple #1
0
def config(option: str, default=undefined, *args, **kwargs):
    if "split" in kwargs:
        kwargs.pop("split")
        kwargs["cast"] = Csv()

    if default is not undefined and default is not None:
        kwargs.setdefault("cast", type(default))
    return _config(option, default=default, *args, **kwargs)
Exemple #2
0
def get_data():
    data = []
    try:
        with open(_config("CACHE_FILE"), "rb") as cache:
            data = _pickle.load(cache)
    except Exception as _:
        pass
    return data
Exemple #3
0
def config(config_name, default=None, cast=None, private=False):

    if cast is None and default is not None:
        cast = type(default)
    cfg = None

    try:
        cfg = _config(config_name,
                      default=default or Undefined(),
                      cast=cast or Undefined())
    except Exception:
        cfg = cast(default) if cast else default
    if not private:
        print(config_name + ' = ' + str(cfg))
    return cfg
Exemple #4
0
def config(option: str, default=undefined, *args, **kwargs):
    """
    Pull a config parameter from the environment.

    Read the config variable ``option``. If it's optional, use the ``default`` value.
    Input is automatically cast to the correct type, where the type is derived from the
    default value if possible.

    Pass ``split=True`` to split the comma-separated input into a list.
    """
    if "split" in kwargs:
        kwargs.pop("split")
        kwargs["cast"] = Csv()

    if default is not undefined and default is not None:
        kwargs.setdefault("cast", type(default))
    return _config(option, default=default, *args, **kwargs)
Exemple #5
0
def exists():
    return _os.path.exists(_config("CACHE_FILE"))
Exemple #6
0
def invalidate():
    _os.remove(_config("CACHE_FILE"))
Exemple #7
0
def write_data(data):
    with open(_config("CACHE_FILE"), "wb") as cache:
        _pickle.dump(data, cache, _pickle.HIGHEST_PROTOCOL)
Exemple #8
0
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': LOGS_DIR / 'django.log',
            'maxBytes': 1024 * 1024 * 3,
            'backupCount': 2,
            'formatter': 'standard',
        },
        'app_file': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': LOGS_DIR / 'app.log',
            'maxBytes': 1024 * 1024 * 3,
            'backupCount': 2,
            'formatter': 'standard',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file', 'console'],
            'level': _config('DJANGO_LOG_LEVEL', 'INFO'),
            'propagate': True,
        },
        'koocook_core': {
            'handlers': ['app_file', 'console'],
            'level': _config('DJANGO_LOG_LEVEL', 'INFO'),
        },
        'koocook_auth': {
            'handlers': ['app_file', 'console'],
            'level': _config('DJANGO_LOG_LEVEL', 'INFO'),
        }
    },
}
Exemple #9
0
from decouple import config as _config
from .dirs import BASE_DIR as _BASE_DIR

DATABASE_NAME = _config('DATABASE_NAME', (_BASE_DIR / 'db.sqlite3').as_posix())

# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': _config('DATABASE_ENGINE', 'django.db.backends.sqlite3'),
        'NAME': DATABASE_NAME,
        'USER': _config('DATABASE_USERNAME', 'username'),
        'PASSWORD': _config('DATABASE_PASSWORD', 'password'),
        'HOST': _config('DATABASE_HOST', '127.0.0.1'),
        'PORT': _config('DATABASE_PORT', '5432'),
        'TEST': {
            'NAME': _config('TEST_DATABASE_NAME', 'test_' + DATABASE_NAME),
        }
    }
}
Exemple #10
0
from decouple import config as _config

AUTHENTICATION_BACKENDS = (
    'social_core.backends.google.GoogleOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)

LOGIN_REDIRECT_URL = _config('LOGIN_REDIRECT_URL', '/')
SOCIAL_AUTH_URL_NAMESPACE = 'social'
SOCIAL_AUTH_POSTGRES_JSONFIELD = True
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = _config('SOCIAL_AUTH_GOOGLE_OAUTH2_KEY',
                                        cast=str)
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = _config('SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET',
                                           cast=str)
SOCIAL_AUTH_PIPELINE = ('social_core.pipeline.social_auth.social_details',
                        'social_core.pipeline.social_auth.social_uid',
                        'social_core.pipeline.social_auth.auth_allowed',
                        'social_core.pipeline.social_auth.social_user',
                        'social_core.pipeline.user.get_username',
                        'social_core.pipeline.user.create_user',
                        'social_core.pipeline.social_auth.associate_user',
                        'social_core.pipeline.social_auth.load_extra_data',
                        'social_core.pipeline.user.user_details',
                        'koocook_auth.pipelines.associate_social_profile')