Skip to content

Commit

Permalink
Merge pull request #11327 from camptocamp/use-private-variables
Browse files Browse the repository at this point in the history
Make logger and cache region private
  • Loading branch information
sbrunner committed Aug 22, 2024
2 parents 9126f92 + ac3acf1 commit 08b0c48
Show file tree
Hide file tree
Showing 44 changed files with 290 additions and 290 deletions.
4 changes: 2 additions & 2 deletions admin/c2cgeoportal_admin/schemas/treegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from c2cgeoportal_commons.lib.literal import Literal
from c2cgeoportal_commons.models.main import LayergroupTreeitem, TreeGroup, TreeItem

LOG = logging.getLogger(__name__)
_LOG = logging.getLogger(__name__)

# Correspondence between TreeItem.item_type and route table segment
ITEM_TYPE_ROUTE_MAP = {
Expand Down Expand Up @@ -149,7 +149,7 @@ def treeitem_edit_url(request: pyramid.request.Request, treeitem: TreeGroup) ->
return None
table = ITEM_TYPE_ROUTE_MAP.get(treeitem.item_type, None)
if table is None:
LOG.warning("%s not found in ITEM_TYPE_ROUTE_MAP", treeitem.item_type)
_LOG.warning("%s not found in ITEM_TYPE_ROUTE_MAP", treeitem.item_type)
return None
return request.route_url( # type: ignore
"c2cgeoform_item",
Expand Down
6 changes: 3 additions & 3 deletions admin/c2cgeoportal_admin/views/ogc_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
base_schema = GeoFormSchemaNode(OGCServer, widget=FormWidget(fields_template="ogcserver_fields"))
base_schema.add_unique_validator(OGCServer.name, OGCServer.id)

LOG = logging.getLogger(__name__)
_LOG = logging.getLogger(__name__)


@view_defaults(match_param="table=ogc_servers")
Expand Down Expand Up @@ -252,8 +252,8 @@ def update_cache() -> None:
timeout=60,
)
if not response.ok:
LOG.error("Error while cleaning the OGC server cache:\n%s", response.text)
_LOG.error("Error while cleaning the OGC server cache:\n%s", response.text)

threading.Thread(target=update_cache).start()
except Exception:
LOG.error("Error on cleaning the OGC server cache", exc_info=True)
_LOG.error("Error on cleaning the OGC server cache", exc_info=True)
2 changes: 1 addition & 1 deletion commons/c2cgeoportal_commons/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from plaster.loaders import setup_logging
from sqlalchemy import engine_from_config, pool

LOG = logging.getLogger(__name__)
_LOG = logging.getLogger(__name__)


# Interpret the config file for Python logging.
Expand Down
6 changes: 3 additions & 3 deletions commons/c2cgeoportal_commons/lib/email_.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013-2023, Camptocamp SA
# Copyright (c) 2013-2024, Camptocamp SA
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -42,7 +42,7 @@ class HTTPInternalServerError(BaseException): # type: ignore
"""Fallback class."""


LOG = logging.getLogger(__name__)
_LOG = logging.getLogger(__name__)


def send_email_config(settings: dict[str, Any], email_config_name: str, email: str, **kwargs: Any) -> None:
Expand All @@ -59,7 +59,7 @@ def send_email_config(settings: dict[str, Any], email_config_name: str, email: s
smtp_config,
)
except gaierror:
LOG.exception("Unable to send the email.")
_LOG.exception("Unable to send the email.")
raise HTTPInternalServerError("See server logs for details") # pylint: disable=raise-missing-from


Expand Down
8 changes: 4 additions & 4 deletions commons/c2cgeoportal_commons/lib/url.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013-2023, Camptocamp SA
# Copyright (c) 2013-2024, Camptocamp SA
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,7 +32,7 @@

from pyramid.request import Request

LOG = logging.getLogger(__name__)
_LOG = logging.getLogger(__name__)


class Url:
Expand All @@ -55,7 +55,7 @@ def __init__(self, url: Optional[str] = None):
try:
self._port = url_split.port
except ValueError as error:
LOG.debug(error)
_LOG.debug(error)
self.path = url_split.path
self.query = dict(urllib.parse.parse_qsl(url_split.query))
self.fragment = url_split.fragment
Expand Down Expand Up @@ -94,7 +94,7 @@ def netloc(self, netloc: str) -> None:
if len(netloc_split) == 2:
allowed = re.compile(r"^[0-9]+$")
if not allowed.match(netloc_split[1]):
LOG.debug("The netloc '%s' contains invalid port", netloc)
_LOG.debug("The netloc '%s' contains invalid port", netloc)
self._port = None
else:
self._port = int(netloc_split[1])
Expand Down
4 changes: 2 additions & 2 deletions commons/c2cgeoportal_commons/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class BaseType(sqlalchemy.ext.declarative.DeclarativeMeta, type):
DBSessions: dict[str, sqlalchemy.orm.scoping.scoped_session[sqlalchemy.orm.Session]] = {}


LOG = logging.getLogger(__name__)
_LOG = logging.getLogger(__name__)


class InvalidateCacheEvent:
Expand All @@ -77,4 +77,4 @@ def _cache_invalidate_cb() -> None:
zope.event.notify(InvalidateCacheEvent())

except ModuleNotFoundError:
LOG.error("c2cwsgiutils broadcast not found")
_LOG.error("c2cwsgiutils broadcast not found")
2 changes: 1 addition & 1 deletion commons/c2cgeoportal_commons/models/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def state_str(state: Any) -> str:
# information
sqlalchemy.orm.base.state_str = state_str

LOG = logging.getLogger(__name__)
_LOG = logging.getLogger(__name__)

_schema: str = config["schema"] or "main"
_srid: int = cast(int, config["srid"]) or 3857
Expand Down
2 changes: 1 addition & 1 deletion commons/c2cgeoportal_commons/models/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, *args: Any, **kwargs: Any):
RelationSelect2Widget = GenericClass # type: ignore[misc,assignment]


LOG = logging.getLogger(__name__)
_LOG = logging.getLogger(__name__)

_schema: str = config["schema_static"] or "static"

Expand Down
6 changes: 3 additions & 3 deletions docker/qgisserver/geomapfish_qgisserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from . import gmf_logging

LOG = logging.getLogger(__name__)
_LOG = logging.getLogger(__name__)


def serverClassFactory( # pylint: disable=invalid-name
Expand All @@ -32,12 +32,12 @@ def serverClassFactory( # pylint: disable=invalid-name
level=Qgis.Critical,
)

LOG.info("Starting GeoMapFish access restriction...")
_LOG.info("Starting GeoMapFish access restriction...")

try:
from .accesscontrol import GeoMapFishAccessControl # pylint: disable=import-outside-toplevel

return GeoMapFishAccessControl(serverIface)
except Exception: # pylint: disable=broad-exception-caught
LOG.error("Cannot setup GeoMapFishAccessControl", exc_info=True)
_LOG.error("Cannot setup GeoMapFishAccessControl", exc_info=True)
return None
Loading

0 comments on commit 08b0c48

Please sign in to comment.