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 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 __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 _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 _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
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