def wsgi(): """Simple Pyramid wsgi server for development purpose """ load_init_function_from_entry_points() Configuration.load('pyramid') configuration_post_load() BlokManager.load() config = Configurator() config.include_from_entry_point() config.load_config_bloks() wsgi_host = Configuration.get('wsgi_host') wsgi_port = int(Configuration.get('wsgi_port')) app = config.make_wsgi_app() server = make_server(wsgi_host, wsgi_port, app) preload_databases(loadwithoutmigration=False) try: from colorama import Fore, Style start_msg = ("Pyramid development server running at %shttp://%s:%s%s" % (Fore.BLUE, wsgi_host, wsgi_port, Style.RESET_ALL)) except ImportError: logger.info("`pip install colorama` to get colored link") start_msg = "Pyramid development server running at http://%s:%s" % ( wsgi_host, wsgi_port) logger.info(start_msg) print(start_msg) server.serve_forever()
def anyblok_createdb(): """Create a database and install blok from config""" load_init_function_from_entry_points() Configuration.load('createdb') configuration_post_load() BlokManager.load() db_name = get_db_name() db_template_name = Configuration.get('db_template_name', None) url = Configuration.get('get_url')(db_name=db_name) create_database(url, template=db_template_name) registry = RegistryManager.get(db_name) if registry is None: return if Configuration.get('install_all_bloks'): bloks = registry.System.Blok.list_by_state('uninstalled') else: install_bloks = Configuration.get('install_bloks') or [] iou_bloks = Configuration.get('install_or_update_bloks') or [] bloks = list(set(install_bloks + iou_bloks)) registry.upgrade(install=bloks) registry.commit() registry.close()
def anyblok_createdb(): """Create a database and install blok from config""" load_init_function_from_entry_points() Configuration.load('createdb') configuration_post_load() BlokManager.load() db_name = get_db_name() db_template_name = Configuration.get('db_template_name', None) url = Configuration.get('get_url')(db_name=db_name) create_database(url, template=db_template_name) anyblok_registry = RegistryManager.get(db_name) if anyblok_registry is None: return anyblok_registry.System.Parameter.set( "with-demo", Configuration.get('with_demo', False)) if Configuration.get('install_all_bloks'): bloks = anyblok_registry.System.Blok.list_by_state('uninstalled') else: install_bloks = Configuration.get('install_bloks') or [] iou_bloks = Configuration.get('install_or_update_bloks') or [] bloks = list(set(install_bloks + iou_bloks)) anyblok_registry.upgrade(install=bloks) anyblok_registry.commit() anyblok_registry.close()
def init(self, parser, opts, args): Configuration.parse_options(opts) # get the configuration save in AnyBlok configuration in # gunicorn configuration for name in Configuration.configuration.keys(): if name in self.cfg.settings: value = Configuration.get(name) if value: self.cfg.settings[name].set(value) configuration_post_load()
def init(self, parser, opts, args): Configuration.parse_options(opts) # get the configuration save in AnyBlok configuration in # gunicorn configuration for name in Configuration.configuration.keys(): if name in self.cfg.settings: value = Configuration.get(name) if value: self.cfg.settings[name].set(value) configuration_post_load()
def asgi() -> None: """uvicorn ASGI dev server""" load_init_function_from_entry_points() argv: List[str] = copy(sys.argv) Configuration.load("uvicorn") sys.argv = argv configuration_post_load() BlokManager.load() kwargs = { "app": create_app(preload_database(loadwithoutmigration=False)), "host": Configuration.get("host"), "port": Configuration.get("port"), # "uds": uds, # "fd": fd, # "loop": loop, # "http": http, # "ws": ws, # "lifespan": lifespan, # "env_file": env_file, # "log_config": LOGGING_CONFIG if log_config is None else log_config, # "log_level": log_level, # "access_log": access_log, # "interface": interface, # "debug": debug, # "reload": reload, # "reload_dirs": reload_dirs if reload_dirs else None, # "workers": workers, # "proxy_headers": proxy_headers, # "forwarded_allow_ips": forwarded_allow_ips, # "root_path": root_path, # "limit_concurrency": limit_concurrency, # "backlog": backlog, # "limit_max_requests": limit_max_requests, # "timeout_keep_alive": timeout_keep_alive, # "ssl_keyfile": ssl_keyfile, # "ssl_certfile": ssl_certfile, # "ssl_version": ssl_version, # "ssl_cert_reqs": ssl_cert_reqs, # "ssl_ca_certs": ssl_ca_certs, # "ssl_ciphers": ssl_ciphers, # "headers": list([header.split(":") for header in headers]), # "use_colors": use_colors, } run(**kwargs)
def update_project(): anyblok.load_init_function_from_entry_points() Configuration.load('update-project') anyblok.configuration_post_load() BlokManager.load() db_name = Configuration.get('db_name') logger.info("update project: db_name=%r", db_name) to_install = [] to_update = [] to_uninstall = [] url = get_url() options = {} if not database_exists(url): db_template_name = Configuration.get('db_template_name', None) create_database(url, template=db_template_name) to_install.append('team') version = None else: options.update(dict(loadwithoutmigration=True)) registry = RegistryManager.get(db_name, **options) registry.update_blok_list() # case, new blok added version = registry.System.Blok.query().filter_by( name='team').one().installed_version if version is None: pass else: to_update.append('team') registry.upgrade(install=to_install, update=to_update, uninstall=to_uninstall) if version is None: registry.Pyramid.User.insert(login='******') registry.Pyramid.CredentialStore.insert(login='******', password='******') registry.commit() registry.close() logger.info("Project updated: db_name=%r", db_name)
def load_registry(self): if not self.enabled or self.registryLoaded: return from anyblok.config import Configuration, get_db_name from anyblok import ( load_init_function_from_entry_points, configuration_post_load, ) from anyblok.blok import BlokManager from anyblok.registry import RegistryManager, return_list # Load the registry here not in configuration, # because the configurations are not loaded in order of score self.registryLoaded = True load_init_function_from_entry_points(unittest=True) Configuration.load_config_for_test() Configuration.parse_options(self.AnyBlokOptions) configuration_post_load() BlokManager.load() db_name = get_db_name() registry = RegistryManager.get(db_name) if not registry: return installed_bloks = registry.System.Blok.list_by_state("installed") selected_bloks = return_list( Configuration.get('selected_bloks')) or installed_bloks unwanted_bloks = return_list(Configuration.get('unwanted_bloks')) or [] self.authorized_blok_paths = set( BlokManager.getPath(b) for b in BlokManager.list() if b in selected_bloks and b not in unwanted_bloks) test_dirs = self.authorized_blok_test_dirs = set() for startpath in self.authorized_blok_paths: for root, dirs, _ in walk(startpath): if 'tests' in dirs: test_dirs.add(join(root, 'tests')) registry.close() # free the registry to force create it again
def wsgi(): """Simple wsgi server for dev """ load_init_function_from_entry_points() Configuration.load('pyramid') configuration_post_load() BlokManager.load() config = Configurator() config.include_from_entry_point() config.load_config_bloks() wsgi_host = Configuration.get('wsgi_host') wsgi_port = int(Configuration.get('wsgi_port')) app = config.make_wsgi_app() server = make_server(wsgi_host, wsgi_port, app) preload_databases(loadwithoutmigration=False) logger.info("Serve forever on %r:%r" % (wsgi_host, wsgi_port)) server.serve_forever()
def wsgi(): """Simple wsgi server for dev """ load_init_function_from_entry_points() Configuration.load('pyramid') configuration_post_load() BlokManager.load() config = Configurator() config.include_from_entry_point() config.load_config_bloks() wsgi_host = Configuration.get('wsgi_host') wsgi_port = int(Configuration.get('wsgi_port')) app = config.make_wsgi_app() server = make_server(wsgi_host, wsgi_port, app) preload_databases(loadwithoutmigration=False) logger.info("Serve forever on %r:%r" % (wsgi_host, wsgi_port)) server.serve_forever()
def load_registry(self): if self.enabled and self.registryLoaded is False: # Load the registry here not in configuration, # because the configuration are not load in order of score self.registryLoaded = True load_init_function_from_entry_points(unittest=True) Configuration.load_config_for_test() Configuration.parse_options(self.AnyBlokOptions) configuration_post_load() BlokManager.load() db_name = get_db_name() registry = RegistryManager.get(db_name) if registry: installed_bloks = registry.System.Blok.list_by_state( "installed") selected_bloks = return_list( Configuration.get('selected_bloks')) or installed_bloks unwanted_bloks = return_list( Configuration.get('unwanted_bloks')) or [] self.bloks_path = [BlokManager.getPath(x) for x in BlokManager.ordered_bloks] self.authoried_bloks_test_files = [] for blok in installed_bloks: if blok not in selected_bloks or blok in unwanted_bloks: continue startpath = BlokManager.getPath(blok) for root, dirs, _ in walk(startpath): if 'tests' in dirs: self.authoried_bloks_test_files.append( join(root, 'tests')) registry.close() # free the registry to force create it again
# -*- coding: utf-8 -*- # This file is a part of the AnyBlok project # # Copyright (C) 2017 Jean-Sebastien SUZANNE <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file,You can # obtain one at http://mozilla.org/MPL/2.0/. from anyblok.config import Configuration from anyblok import ( load_init_function_from_entry_points, configuration_post_load, ) load_init_function_from_entry_points(unittest=True) Configuration.load_config_for_test() configuration_post_load(unittest=True)
def load_configuration(): load_init_function_from_entry_points(unittest=True) Configuration.load_config_for_test() Configuration.parse_options(MockParser()) configuration_post_load(unittest=True)
# # Copyright (C) 2015 Jean-Sebastien SUZANNE <*****@*****.**> # Copyright (C) 2017 Jean-Sebastien SUZANNE <*****@*****.**> # Copyright (C) 2018 Jean-Sebastien SUZANNE <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file,You can # obtain one at http://mozilla.org/MPL/2.0/. from anyblok.config import Configuration from anyblok import ( load_init_function_from_entry_points, configuration_post_load, ) load_init_function_from_entry_points(unittest=True) Configuration.load_config_for_test() class MockParser: def _get_kwargs(self): return [] def _get_args(self): return False Configuration.parse_options(MockParser()) configuration_post_load(unittest=True)
configuration_post_load, ) if BlokManager.bloks: # AnyBlok already load, the state are not sure, better to stop here sys.exit(1) load_init_function_from_entry_points() # load default files ad = AppDirs('AnyBlok') # load the global configuration file Configuration.parse_configfile(path.join(ad.site_config_dir, 'conf.cfg'), ()) # load the user configuration file Configuration.parse_configfile(path.join(ad.user_config_dir, 'conf.cfg'), ()) # load config file in environment variable configfile = environ.get('ANYBLOK_CONFIGFILE') if configfile: Configuration.parse_configfile(configfile) if 'logging_level' in Configuration.configuration: Configuration.initialize_logging() configuration_post_load() BlokManager.load() preload_databases() config = Configurator() config.include_from_entry_point() config.load_config_bloks() app = config.make_wsgi_app()