def setup_common(): global config configfile = "/opt/c2cgeoportal/geoportal/tests/tests.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": "/opt/c2cgeoportal/geoportal/tests/config.yaml", "package": "c2cgeoportal", "enable_admin_interface": True, "getitfixed": {"enabled": False}, } config = testing.setUp(settings=configuration.get_config()) c2cgeoportal_geoportal.init_dbsessions(config.get_settings(), config) setup_db()
def settings(): config_uri = "/opt/c2cgeoportal/commons/tests/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 get_config(): conf = context.config.get_section(context.config.config_ini_section) # Load config from c2cgeoportal if available app_cfg = context.config.get_main_option("app.cfg") if app_cfg: from c2c.template.config import config config.init(context.config.get_main_option("app.cfg")) conf.update(config.get_config()) if "sqlalchemy.url" not in conf: conf[ "sqlalchemy.url"] = "postgresql://{PGUSER}:{PGPASSWORD}@{PGHOST}:{PGPORT}/{PGDATABASE}".format( **os.environ) conf.update({ "version_table_schema": conf.get("getitfixed", {}).get("schema", "getitfixed") }) # for 'autogenerate' support from getitfixed import models # noqa conf["target_metadata"] = models.meta.Base.metadata return conf
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) from c2cgeoportal_geoportal.lib import functionality functionality.FUNCTIONALITIES_TYPES = None cleanup_db()
def get_settings() -> Dict[str, Any]: logging.getLogger("c2cgeoportal_geoportal").setLevel(logging.DEBUG) configfile = "/opt/c2cgeoportal/geoportal/tests/tests.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": "/opt/c2cgeoportal/geoportal/tests/config.yaml", "package": "c2cgeoportal", "enable_admin_interface": True, "getitfixed": {"enabled": False}, "vector_tiles": { "srid": 21781, "extent": [599900, 199950, 600100, 200050], "resolutions": [4000, 2000, 1000, 500, 250, 100, 50, 20, 10, 5, 2.5, 1, 0.5, 0.25, 0.1, 0.05], }, } return configuration.get_config()
def get_wsgi_app_settings(self, name: str = None, defaults: Dict[str, str] = None) -> Dict: settings = super().get_wsgi_app_settings(name, defaults) configuration.init(settings.get('app.cfg')) settings.update(configuration.get_config()) return settings
def __init__(self): super().__init__() if os.path.exists("/etc/geomapfish/config.yaml"): config.init("/etc/geomapfish/config.yaml") self.config = config.get_config() else: self.config = None self.env = 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 __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 get_wsgi_app_settings( self, name: Optional[str] = None, defaults: Optional[Dict[str, str]] = None ) -> Dict[str, Any]: settings = cast(Dict[str, Any], super().get_wsgi_app_settings(name, defaults)) configuration.init(settings.get("app.cfg")) settings.update(configuration.get_config()) if "available_locale_names" not in settings: settings["available_locale_names"] = available_locale_names() 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 __init__(self, server_iface: qgis.server.QgsServerInterface): super().__init__(server_iface) self.server_iface = server_iface self.initialized = False try: config.init( os.environ.get("GEOMAPFISH_CONFIG", "/etc/qgisserver/geomapfish.yaml")) c2cwsgiutils.broadcast.init() DBSession = create_session_factory( # noqa: ignore=N806 config.get("sqlalchemy_slave.url"), config.get_config().get("sqlalchemy", {})) if "GEOMAPFISH_OGCSERVER" in os.environ: self.single = True self.ogcserver_accesscontrol = OGCServerAccessControl( server_iface, os.environ["GEOMAPFISH_OGCSERVER"], os.environ["QGIS_PROJECT_FILE"], config.get("srid"), DBSession, ) LOG.info("Use OGC server named '%s'.", os.environ["GEOMAPFISH_OGCSERVER"]) self.initialized = True elif "GEOMAPFISH_ACCESSCONTROL_CONFIG" in os.environ: self.single = False self.ogcserver_accesscontrols = {} with open(os.environ["GEOMAPFISH_ACCESSCONTROL_CONFIG"] ) as ac_config_file: ac_config = yaml.safe_load(ac_config_file.read()) for map_, map_config in ac_config.get("map_config").items(): map_config["access_control"] = OGCServerAccessControl( server_iface, map_config["ogc_server"], map_, config.get("srid"), DBSession) self.ogcserver_accesscontrols[map_] = map_config LOG.info("Use config '%s'.", os.environ["GEOMAPFISH_ACCESSCONTROL_CONFIG"]) self.initialized = True else: LOG.error( "The environment variable 'GEOMAPFISH_OGCSERVER' or " "'GEOMAPFISH_ACCESSCONTROL_CONFIG' is not defined.", ) except Exception: # pylint: disable=broad-except LOG.error("Cannot setup GeoMapFishAccessControl", exc_info=True) server_iface.registerAccessControl( self, int(os.environ.get("GEOMAPFISH_POSITION", 100)))
def settings(): setup_module() settings = { **configuration.get_config(), **yaml.load(GMF_CONFIG, Loader=yaml.BaseLoader)["vars"], } with patch( "c2c.template.get_config", return_value=settings, ): yield 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 settings(): setup_module() yield { **configuration.get_config(), "available_locale_names": ["fr", "en", "de", "it"], "fulltextsearch": { "languages": { "fr": "french", "en": "english", "de": "german", "it": "italian", } }, }
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 get_config(): config.init(context.config.get_main_option('app.cfg')) settings = {} settings.update(config.get_config()) alembic_name = context.config.get_main_option('type') schema_config_name = 'schema{}'.format( '_{}'.format(alembic_name) if alembic_name != 'main' else '') 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_config_name], }) return settings
def get_config(): config.init(context.config.get_main_option("app.cfg")) settings: Dict[str, str] = {} settings.update(config.get_config()) alembic_name = context.config.get_main_option("type") schema_config_name = "schema{}".format( "_{}".format(alembic_name) if alembic_name != "main" else "") 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_config_name], }) return settings
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()
def __call__(self, filename, options): configuration.init(filename) settings = configuration.get_config() for path in ( ("getitfixed", "admin_new_issue_email", "email_subject"), ("getitfixed", "admin_new_issue_email", "email_body"), ("getitfixed", "new_issue_email", "email_subject"), ("getitfixed", "new_issue_email", "email_body"), ("getitfixed", "update_issue_email", "email_subject"), ("getitfixed", "update_issue_email", "email_body"), ("getitfixed", "resolved_issue_email", "email_subject"), ("getitfixed", "resolved_issue_email", "email_body"), ): value = settings for key in path: value = value[key] # yield Message(msgctxt msgid msgid_plural flags comment tcomment location) yield Message(None, value, None, [], u"", u"", (filename, "/".join(path)))
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) c2cwsgiutils.pretty_json.init(config) config.include("c2cgeoportal_admin") # Initialize the dev dbsession settings = config.get_settings() settings["tm.manager_hook"] = "pyramid_tm.explicit_manager" configure_mappers() engine = engine_from_config(settings) session_factory = sessionmaker() session_factory.configure(bind=engine) def get_tm_session(session_factory, transaction_manager): dbsession = session_factory() zope.sqlalchemy.register(dbsession, transaction_manager=transaction_manager) return dbsession # 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) return config.make_wsgi_app()
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ # Update the settings object from the YAML application config file configuration.init(settings.get("app.cfg")) settings.update(configuration.get_config()) config = Configurator( settings=settings, locale_negotiator="getitfixed.i18n.locale_negotiator") config.include("getitfixed") config.include("getitfixed.models") c2cgeoform.routes.register_routes(config) def notfound_view(request): request.response.status = 404 return {} config.add_notfound_view(notfound_view, append_slash=True, renderer="getitfixed:templates/404.jinja2") return config.make_wsgi_app()
def _collect_app_config(self, filename: str) -> List[Message]: 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()) ] # Init db sessions class R: settings: Dict[str, Any] = {} class C: registry = R() def get_settings(self) -> Dict[str, Any]: return self.registry.settings def add_tween(self, *args: Any, **kwargs: Any) -> None: pass config_ = C() config_.registry.settings = settings c2cgeoportal_geoportal.init_dbsessions(settings, config_) # Collect layers enum values (for filters) from c2cgeoportal_commons.models import DBSessions # pylint: disable=import-outside-toplevel from c2cgeoportal_commons.models.main import Metadata # pylint: disable=import-outside-toplevel 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( DBSessions, layerinfos, fieldname) for (value, ) in values: if isinstance(value, str) and value != "": msgid = value location = "/layers/{}/values/{}/{}".format( layername, fieldname, value.encode("ascii", errors="replace").decode("ascii"), ) enums.append( Message(None, msgid, None, [], "", "", (filename, location))) metadata_list = [] defs = config["admin_interface"]["available_metadata"] # pylint: disable=unsubscriptable-object names = [e["name"] for e in defs if e.get("translate", False)] if names: engine = sqlalchemy.create_engine(config["sqlalchemy.url"]) DBSession = sqlalchemy.orm.session.sessionmaker( ) # noqa: disable=N806 DBSession.configure(bind=engine) session = DBSession() query = session.query(Metadata).filter(Metadata.name.in_(names)) # pylint: disable=no-member for metadata in query.all(): location = "metadata/{}/{}".format(metadata.name, metadata.id) metadata_list.append( Message(None, metadata.value, None, [], "", "", (filename, location))) interfaces_messages = [] for interface, interface_config in config["interfaces_config"].items(): for ds_index, datasource in enumerate( interface_config.get("constants", {}).get("gmfSearchOptions", {}).get("datasources", [])): for a_index, action in enumerate( datasource.get("groupActions", [])): location = ( "interfaces_config/{}/constants/gmfSearchOptions/datasources[{}]/" "groupActions[{}]/title".format( interface, ds_index, a_index)) interfaces_messages.append( Message(None, action["title"], None, [], "", "", (filename, location))) for merge_tab in (interface_config.get("constants", {}).get( "gmfDisplayQueryGridOptions", {}).get("mergeTabs", {}).keys()): location = "interfaces_config/{}/constants/gmfDisplayQueryGridOptions/mergeTabs/{}/".format( interface, merge_tab) interfaces_messages.append( Message(None, merge_tab, None, [], "", "", (filename, location))) return raster + enums + metadata_list + interfaces_messages
def __init__(self, server_iface): super().__init__(server_iface) self.server_iface = server_iface self.initialized = False try: config.init( os.environ.get("GEOMAPFISH_CONFIG", "/etc/qgisserver/geomapfish.yaml")) c2cwsgiutils.broadcast.init() configure_mappers() db_match = re.match(".*(@[^@]+)$", config.get("sqlalchemy_slave.url")) QgsMessageLog.logMessage( "Connect to the database: ***{}".format( db_match.group(1) if db_match else ""), "GeoMapFishAccessControl", level=Qgis.Info, ) engine = sqlalchemy.create_engine( config["sqlalchemy_slave.url"], **(config.get_config().get("sqlalchemy", {}))) session_factory = sessionmaker() session_factory.configure(bind=engine) DBSession = scoped_session(session_factory) # noqa: N806 if "GEOMAPFISH_OGCSERVER" in os.environ: self.single = True self.ogcserver_accesscontrol = OGCServerAccessControl( server_iface, os.environ["GEOMAPFISH_OGCSERVER"], config.get("srid"), DBSession) QgsMessageLog.logMessage( "Use OGC server named '{}'.".format( os.environ["GEOMAPFISH_OGCSERVER"]), "GeoMapFishAccessControl", level=Qgis.Info, ) self.initialized = True elif "GEOMAPFISH_ACCESSCONTROL_CONFIG" in os.environ: self.single = False self.ogcserver_accesscontrols = {} with open(os.environ["GEOMAPFISH_ACCESSCONTROL_CONFIG"] ) as ac_config_file: ac_config = yaml.safe_load(ac_config_file.read()) for map_, map_config in ac_config.get("map_config").items(): map_config["access_control"] = OGCServerAccessControl( server_iface, map_config["ogc_server"], config.get("srid"), DBSession) self.ogcserver_accesscontrols[map_] = map_config QgsMessageLog.logMessage( "Use config '{}'.".format( os.environ["GEOMAPFISH_ACCESSCONTROL_CONFIG"]), "GeoMapFishAccessControl", level=Qgis.Info, ) self.initialized = True else: QgsMessageLog.logMessage( "The environment variable 'GEOMAPFISH_OGCSERVER' or " "'GEOMAPFISH_ACCESSCONTROL_CONFIG' is not defined.", "GeoMapFishAccessControl", level=Qgis.Critical, ) except Exception: print("".join(traceback.format_exception(*sys.exc_info()))) QgsMessageLog.logMessage( "".join(traceback.format_exception(*sys.exc_info())), "GeoMapFishAccessControl", level=Qgis.Critical, ) server_iface.registerAccessControl( self, int(os.environ.get("GEOMAPFISH_POSITION", 100)))
TextInputWidget, ) from c2c.template.config import config from c2cgeoform import default_map_settings from c2cgeoform.ext.deform_ext import RelationSelectWidget from c2cgeoform.ext import colander_ext, deform_ext from c2cgeoform.models import FileData from getitfixed.i18n import _ from getitfixed.models.meta import Base from getitfixed.url import generate_url schema = "getitfixed" _getitfixed_config = (config.get_config() or {}).get("getitfixed", {}) _map_config = { **default_map_settings, **{"mobile": True}, **_getitfixed_config.get("map", {}), } STATUS_NEW = "new" STATUS_VALIDATED = "validated" STATUS_IN_PROGRESS = "in_progress" STATUS_REPORTER = "waiting_for_reporter" STATUS_RESOLVED = "resolved" STATUSES = { STATUS_NEW: _("New"), STATUS_VALIDATED: _("Validated"),
def settings(): settings = {} config.init( os.environ.get("GEOMAPFISH_CONFIG", "/etc/qgisserver/geomapfish.yaml")) settings.update(config.get_config()) return settings
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.models import DBSessions from c2cgeoportal_commons.models.main import Metadata 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( DBSessions, Layers, layerinfos, fieldname) for value, in values: if value is not None and isinstance(value, str) and value != "": msgid = 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))) metadata_list = [] defs = config["admin_interface"]["available_metadata"] names = [e["name"] for e in defs if e.get("translate", False)] if len(names) > 0: import sqlalchemy engine = sqlalchemy.create_engine(config["sqlalchemy.url"]) Session = sqlalchemy.orm.session.sessionmaker() # noqa Session.configure(bind=engine) session = Session() query = session.query(Metadata).filter(Metadata.name.in_(names)) for metadata in query.all(): location = "metadata/{}/{}".format(metadata.name, metadata.id) metadata_list.append( Message(None, metadata.value, None, [], u"", u"", (filename, location))) return raster + enums + metadata_list
CheckboxWidget = GenericClass HiddenWidget = GenericClass MapWidget = GenericClass SelectWidget = GenericClass TextAreaWidget = GenericClass ColanderGeometry = GenericClass RelationSelect2Widget = GenericClass TextInputWidget = GenericClass LOG = logging.getLogger(__name__) _schema: str = config["schema"] or "main" _srid: int = cast(int, config["srid"]) or 3857 # Set some default values for the admin interface _admin_config: Dict = config.get_config().get("admin_interface", {}) _map_config: Dict = {**default_map_settings, **_admin_config.get("map", {})} view_srid_match = re.match(r"EPSG:(\d+)", _map_config["view"]["projection"]) if "map_srid" not in _admin_config and view_srid_match is not None: _admin_config["map_srid"] = view_srid_match.group(1) class FullTextSearch(GeoInterface, Base): __tablename__ = "tsearch" __table_args__ = (Index("tsearch_ts_idx", "ts", postgresql_using="gin"), { "schema": _schema }) id = Column(Integer, primary_key=True) label = Column(Unicode) layer_name = Column(Unicode)
def settings(): setup_module() yield {**configuration.get_config()}
def __init__(self, server_iface: qgis.server.QgsServerInterface): super().__init__(server_iface) self.server_iface = server_iface self.initialized = False try: config.init( os.environ.get("GEOMAPFISH_CONFIG", "/etc/qgisserver/geomapfish.yaml")) c2cwsgiutils.broadcast.init() DBSession = create_session_factory( # noqa: ignore=N806 config.get("sqlalchemy_slave.url"), config.get_config().get("sqlalchemy", {})) if "GEOMAPFISH_OGCSERVER" in os.environ: self.single = True self.ogcserver_accesscontrol = OGCServerAccessControl( server_iface, os.environ["GEOMAPFISH_OGCSERVER"], os.environ["QGIS_PROJECT_FILE"], config.get("srid"), DBSession, ) LOG.info("Use OGC server named '%s'.", os.environ["GEOMAPFISH_OGCSERVER"]) self.initialized = True elif "GEOMAPFISH_ACCESSCONTROL_CONFIG" in os.environ: self.single = False self.ogcserver_accesscontrols = {} with open(os.environ["GEOMAPFISH_ACCESSCONTROL_CONFIG"], encoding="utf-8") as ac_config_file: ac_config = yaml.safe_load(ac_config_file.read()) for map_, map_config in ac_config.get("map_config").items(): map_config["access_control"] = OGCServerAccessControl( server_iface, map_config["ogc_server"], map_, config.get("srid"), DBSession) self.ogcserver_accesscontrols[map_] = map_config LOG.info("Use config '%s'.", os.environ["GEOMAPFISH_ACCESSCONTROL_CONFIG"]) self.initialized = True elif "GEOMAPFISH_ACCESSCONTROL_BASE_URL" in os.environ: self.ogcserver_accesscontrols = {} single_ogc_server = None base_url = Url(os.environ["GEOMAPFISH_ACCESSCONTROL_BASE_URL"]) session = DBSession() try: from c2cgeoportal_commons.models.main import ( # pylint: disable=import-outside-toplevel OGCServer, ) for ogcserver in session.query(OGCServer).all(): errors: Set[str] = set() url = get_url2( f"The OGC server '{ogcserver.name}'", ogcserver.url, None, errors, config.get_config().get("servers", {}), ) if errors: LOG.warning( "Ignoring OGC server '%s', get error on parsing URL:\n%s", ogcserver.name, "\n".join(errors), ) continue if url is None: LOG.warning( "Ignoring OGC server '%s', the URL is None", ogcserver.name) continue if (base_url.scheme == url.scheme and base_url.netloc == url.netloc and base_url.path == url.path): query = url.query_lower if "map" not in query: if single_ogc_server is None: single_ogc_server = ogcserver LOG.debug( "OGC server '%s', 'map' is not in the parameters => single server?", ogcserver.name, ) else: LOG.error( "OGC server '%s', 'map' is not in the parameters and we already have a single OCG server '%s'", ogcserver.name, single_ogc_server.name, ) continue map_ = url.query_lower["map"] self.ogcserver_accesscontrols[map_] = { "ogcserver": ogcserver.name, "access_control": OGCServerAccessControl( server_iface, ogcserver.name, map_, config.get("srid"), DBSession, ogcserver=ogcserver, ), } LOG.info("OGC server '%s' registered for map", ogcserver.name) else: LOG.debug( "Ignoring OGC server '%s', Don't match the base URL '%s' and '%s'", ogcserver.name, base_url, url, ) if self.ogcserver_accesscontrols and single_ogc_server is not None: if os.environ.get("QGIS_PROJECT_FILE"): LOG.error( "We have OGC servers with and without parameter MAP and a value in QGIS_PROJECT_FILE, fallback to single OGC server mode." ) self.ogcserver_accesscontrols = {} else: LOG.error( "We have OGC servers with and without parameter MAP but no value in QGIS_PROJECT_FILE, fallback to multiple OGC server mode." ) single_ogc_server = None if single_ogc_server is not None: self.single = True self.ogcserver_accesscontrol = OGCServerAccessControl( server_iface, single_ogc_server.name, os.environ["QGIS_PROJECT_FILE"], config.get("srid"), DBSession, single_ogc_server, ) LOG.info("Use OGC server named '%s'.", single_ogc_server.name) else: self.single = False self.initialized = True finally: session.close() else: LOG.error( "The environment variable 'GEOMAPFISH_OGCSERVER', 'GEOMAPFISH_ACCESSCONTROL_CONFIG' " "or 'GEOMAPFISH_ACCESSCONTROL_BASE_URL' should be defined.", ) except Exception: # pylint: disable=broad-except LOG.error("Cannot setup GeoMapFishAccessControl", exc_info=True) server_iface.registerAccessControl( self, int(os.environ.get("GEOMAPFISH_POSITION", 100)))