def dotenv() -> None: from rapperswil_jona.env import Env if not os.environ.get('ENV', None): os.environ['ENV'] = 'test' # same as rapperswil_jona:main dotenv_file = os.path.join(os.getcwd(), '.env') Env.load_dotenv_vars(dotenv_file)
def main(argv=None, quiet=False): """Runs original pserve with .env support.""" # NOTE: # `pserve` (PServeCommand) needs `hupper`, it has dependency to **fcntl**. # In some environment (e.g. app engine), fcntl is not found :'( # So, that's why this import is in method. from pyramid.scripts.pserve import PServeCommand if not argv: argv = sys.argv Env.load_dotenv_vars() command = PServeCommand(argv, quiet=quiet) return command.run()
def resolve_env_vars(settings): env = Env() s = settings.copy() for k, v in Env.settings_mappings().items(): # ignores missing key or it has a already value in config if k not in s or s[k]: continue new_v = env.get(v, None) if not isinstance(new_v, str): continue # ignores empty string if ',' in new_v: s[k] = [nv for nv in new_v.split(',') if nv != ''] elif new_v: s[k] = new_v return s
def __init__(self, ctx, req, **kwargs): self.context, self.req = ctx, req self.env = Env() if getattr(req, 'util', None) is None: req.util = self self.__dict__.update(kwargs)
def __init__(self, *args, **kwargs): env_dict = (args[0] or {}) # self.environ is request env. # the `env` is os's environ handler (wrapper) env = Env() if env.is_production: env_dict = self._force_ssl(env_dict) env_dict = self.__class__.trim_port(env_dict) new_args = (env_dict, args[1:]) if sys.version_info[0] > 3: # pylint: disable=missing-super-argument super().__init__(*new_args, **kwargs) else: super(CustomRequest, self).__init__(*new_args, **kwargs)
def includeme(config): env = Env() cache_max_age = 3600 if env.is_production else 0 # routes # static files at /* filenames = [ f for f in ('robots.txt', 'humans.txt', 'favicon.ico') if path.isfile((STATIC_DIR + '/{}').format(f)) ] if filenames: config.add_asset_views(STATIC_DIR, filenames=filenames, http_cache=cache_max_age) # static files at /assets/* config.add_static_view(name='assets', path=STATIC_DIR, cache_max_age=cache_max_age) config.add_route('index', '/')
def env(dotenv): from rapperswil_jona.env import Env return Env()
def usage(argv): cmd = os.path.basename(argv[0]) print('usage: %s <config_uri> [var=value]\n' '(example: "%s {staging|production}.ini")' % (cmd, cmd)) sys.exit(1) def main(argv, _quiet=False): if len(argv) < 2: usage(argv) config_uri = argv[1] if 1 in argv else 'config/production.ini' wsgi_app = get_app(config_uri, 'rapperswil_jona') setup_logging(config_uri) return wsgi_app if __name__ == '__main__': # pylint: disable=relative-import from paste.script.cherrypy_server import cpwsgi_server from rapperswil_jona.env import Env Env.load_dotenv_vars() env = Env() # pylint: disable=invalid-name cpwsgi_server(main(sys.argv), host=env.host, port=env.port, numthreads=10, request_queue_size=100)