def handle(self, **options): key = options['key'] configure = ConfigLoader.from_env(suppress_logs=True, silent=True) uwsgi_cfg = configure.get(key) if not uwsgi_cfg: self.stderr.write( f'Parsing error: uWSGI config was not found by the key "{key}"' ) return if options['print']: self.stdout.write('*' * 80 + '\n') self.stdout.write('uWSGI CONFIG'.center(80)) self.stdout.write('*' * 80 + '\n') write_uwsgi_ini_cfg(self.stdout, uwsgi_cfg) self.stdout.write('*' * 80 + '\n') self.stdout.flush() cfg_file = options['file'] with open(cfg_file, 'w') as file: write_uwsgi_ini_cfg(file, uwsgi_cfg) os.execvp('uwsgi', ('--ini', cfg_file))
def test__from_env(self): env = { 'CONFIG__PARSERS': 'EnvironmentParser,RedisParser,YamlParser', 'ENVIRONMENTPARSER__SCOPE': 'nested', 'YAMLPARSER__CONFIG': './tests/data/config.yml', 'REDISPARSER__HOST': 'wtf.test', 'NESTED__VARIABLE': 'i_am_here', } loader = ConfigLoader.from_env(env=env) assert [type(p) for p in loader.parsers ] == [EnvironmentParser, RedisParser, YamlParser] assert loader.get( 'variable') == 'i_am_here', 'Ensure env copied from ConfigLoader' with pytest.raises(Exception): loader.get('nothing.here') loader = ConfigLoader.from_env(env=env, silent=True) assert loader.get('nothing.here', True) is True loader = ConfigLoader.from_env(parser_modules=['EnvironmentParser'], env={}) assert loader.parsers
def test__from_env__raises_on_empty_values(self): with pytest.raises(ValueError): ConfigLoader.from_env([], {})
FILE_UPLOAD_TEMP_DIR = TEMP_DIR # for TemporaryUploadedFile MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media') STATIC_ROOT = os.path.join(PROJECT_PATH, 'static') USERMEDIA_ROOT = os.path.join(PROJECT_PATH, 'usermedia') # ------ for path in (STATIC_ROOT, MEDIA_ROOT, USERMEDIA_ROOT, TEMP_DIR): if not os.path.exists(path): os.makedirs(path, mode=0o755, exist_ok=True) # ★★★★★★★★★★★★★★★ CONFIG LOADER ★★★★★★★★★★★★★★★ # yml_conf = os.path.join(PROJECT_PATH, 'config', os.environ.get('DJANGO_CONFIG_FILE_NAME', 'dev.yml')) os.environ.setdefault('YAMLPARSER__CONFIG', yml_conf) configure = ConfigLoader.from_env(suppress_logs=True, silent=True) # ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ # DEBUG = configure('debug', False) if configure('security', False): SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECURE_SSL_REDIRECT = True SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True # --------------- SECRET SETTINGS --------------- SECRET_KEY = configure('common.secret_key', 'secret') if SECRET_KEY == 'secret': warnings.warn('SECRET_KEY is not assigned! Production unsafe!')