def setup_common(): global config current_dir = os.path.dirname(os.path.abspath(__file__)) configfile = os.path.realpath(os.path.join(current_dir, "test.ini")) cfg = ConfigParser() cfg.read(configfile) db_url = cfg.get("test", "sqlalchemy.url") assert db_url is not None configuration._config = { "sqlalchemy.url": db_url, "sqlalchemy_slave.url": db_url, "srid": 21781, "schema": "main", "schema_static": "main_static", "default_max_age": 86400, "app.cfg": "/src/geoportal/tests/config.yaml", "package": "c2cgeoportal", "enable_admin_interface": True, } config = testing.setUp(settings=configuration.get_config()) c2cgeoportal_geoportal.init_dbsessions(config.get_settings(), config) functionality.FUNCTIONALITIES_TYPES = None cleanup_db()
def __call__(self, filename, options, fileobj=None, lineno=0): print('Entering into %s extractor' % self.__class__) del fileobj, lineno try: # initialize DB connections in a way similar to c2cgeoportal_geoportal.lib.lingua_extractor settings = config.get_config() class R: settings = None class C: registry = R() config_ = C() config_.registry.settings = settings init_dbsessions(settings, config_) try: self._extract_messages() file = "geoportailv3_geoportal-legends.pot" if str(self.__class__).find('LuxembourgTooltipsExtractor') > 0: file = "geoportailv3_geoportal-tooltips.pot" for attribute in self._get_missing_keys(file): self._insert_attribute(attribute.msgid, (attribute.comment, "")) except ProgrammingError as e: print( colorize( "ERROR! The database is probably not up to date " "(should be ignored when happen during the upgrade)", RED, )) print(colorize(e, RED)) if os.environ.get("IGNORE_I18N_ERRORS", "FALSE") != "TRUE": raise except NoSuchTableError as e: print( colorize( "ERROR! The schema didn't seem to exists " "(should be ignored when happen during the deploy)", RED, )) print(colorize(e, RED)) if os.environ.get("IGNORE_I18N_ERRORS", "FALSE") != "TRUE": raise except OperationalError as e: print( colorize( "ERROR! The database didn't seem to exists " "(should be ignored when happen during the deploy)", RED, )) print(colorize(e, RED)) if os.environ.get("IGNORE_I18N_ERRORS", "FALSE") != "TRUE": raise return self.messages
def __init__(self): super().__init__() if os.path.exists("geoportal/config.yaml"): config.init("geoportal/config.yaml") self.config = config.get_config() else: self.config = None self.tpl = None
def settings(): config_uri = 'tests.ini' if os.path.exists( 'tests.ini') else 'commons/tests.ini' fileConfig(config_uri, defaults=dict(os.environ)) settings = plaster.get_settings(config_uri, 'tests') config.init(settings.get('app.cfg')) settings.update(config.get_config()) return settings
def includeme(config: Configurator) -> None: """ Initialize the model for a Pyramid app. Activate this setup using ``config.include('c2cgeoportal_admin.commons')``. """ settings = config.get_settings() configuration.init(settings.get('app.cfg')) # update the settings object from the YAML application config file settings.update(configuration.get_config())
def get_config(): config.init(context.config.get_main_option('app.cfg')) settings = {} settings.update(config.get_config()) main = context.config.get_main_option('type') == 'main' settings.update({ 'script_location': context.config.get_main_option('script_location'), 'version_table': context.config.get_main_option('version_table'), 'version_locations': context.config.get_main_option('version_locations'), 'version_table_schema': config['schema' if main else 'schema_static'], }) return settings
def __init__(self): super().__init__() if os.path.exists("geoportal/config.yaml"): config.init("geoportal/config.yaml") self.config = config.get_config() else: self.config = None if os.path.exists("project.yaml"): with open("project.yaml") as f: self.package = yaml.safe_load(f) else: self.package = None self.env = None
def setup_method(self, _): # the c2cgeoportal includeme function requires a number # of settings config._config = { "sqlalchemy.url": "postgresql://*****:*****@db:5432/geomapfish_tests", "srid": 3857, "schema": "main", "schema_static": "main_static", "default_max_age": 86400, "app.cfg": "/src/geoportal/tests/config.yaml", "package": "c2cgeoportal", "enable_admin_interface": True, } self.config = testing.setUp(settings=config.get_config())
def __init__(self): super().__init__() log.info(f'entering into {self.__class__} lux extractor') if os.path.exists("geoportal/config.yaml"): config.init("geoportal/config.yaml") self.config = config.get_config() else: self.config = None if os.path.exists("project.yaml"): with open("project.yaml") as f: self.package = yaml.safe_load(f) else: self.package = None self.env = None self.messages = [] self.fields = set() self.TIMEOUT = 15
def _collect_app_config(self, filename): config.init(filename) settings = config.get_config() # Collect raster layers names raster = [ Message(None, raster_layer, None, [], "", "", (filename, "raster/{}".format(raster_layer))) for raster_layer in list(settings.get("raster", {}).keys()) ] # Collect layers enum values (for filters) class R: settings = None class C: registry = R() config_ = C() config_.registry.settings = settings init_dbsessions(settings, config_) from c2cgeoportal_commons import models c2cgeoportal_geoportal.init_dbsessions(settings, config_) from c2cgeoportal_geoportal.views.layers import Layers enums = [] enum_layers = settings.get("layers", {}).get("enum", {}) for layername in list(enum_layers.keys()): layerinfos = enum_layers.get(layername, {}) attributes = layerinfos.get("attributes", {}) for fieldname in list(attributes.keys()): values = self._enumerate_attributes_values( models.DBSessions, Layers, layerinfos, fieldname) for value, in values: if value != "": msgid = value if isinstance(value, str) else value location = "/layers/{}/values/{}/{}".format( layername, fieldname, value.encode("ascii", errors="replace") if isinstance(value, str) else value) enums.append( Message(None, msgid, None, [], "", "", (filename, location))) return raster + enums
def main(_, **settings): """ This function returns a Pyramid WSGI application. """ configuration.init(settings.get('app.cfg')) settings.update(configuration.get_config()) config = Configurator(settings=settings) config.include('c2cwsgiutils.pyramid.includeme') config.include('c2cgeoportal_admin') from c2cgeoportal_commons.testing import ( generate_mappers, get_engine, get_session_factory, get_tm_session, ) # Initialize the dev dbsession settings = config.get_settings() settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager' session_factory = get_session_factory(get_engine(settings)) config.registry['dbsession_factory'] = session_factory # Make request.dbsession available for use in Pyramid config.add_request_method( # request.tm is the transaction manager used by pyramid_tm lambda request: get_tm_session(session_factory, request.tm), 'dbsession', reify=True) config.add_subscriber(add_renderer_globals, BeforeRender) config.add_subscriber(add_localizer, NewRequest) generate_mappers() health_check = HealthCheck(config) health_check.add_url_check('http://{}/'.format( settings['healthcheck_host'])) return config.make_wsgi_app()