arthexis 0.1.13__py3-none-any.whl → 0.1.14__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of arthexis might be problematic. Click here for more details.

Files changed (107) hide show
  1. {arthexis-0.1.13.dist-info → arthexis-0.1.14.dist-info}/METADATA +222 -221
  2. arthexis-0.1.14.dist-info/RECORD +109 -0
  3. {arthexis-0.1.13.dist-info → arthexis-0.1.14.dist-info}/licenses/LICENSE +674 -674
  4. config/__init__.py +5 -5
  5. config/active_app.py +15 -15
  6. config/asgi.py +43 -43
  7. config/auth_app.py +7 -7
  8. config/celery.py +32 -32
  9. config/context_processors.py +67 -69
  10. config/horologia_app.py +7 -7
  11. config/loadenv.py +11 -11
  12. config/logging.py +59 -48
  13. config/middleware.py +25 -25
  14. config/offline.py +49 -49
  15. config/settings.py +691 -682
  16. config/settings_helpers.py +109 -109
  17. config/urls.py +171 -166
  18. config/wsgi.py +17 -17
  19. core/admin.py +3771 -2809
  20. core/admin_history.py +50 -50
  21. core/admindocs.py +151 -151
  22. core/apps.py +356 -272
  23. core/auto_upgrade.py +57 -57
  24. core/backends.py +265 -236
  25. core/changelog.py +342 -0
  26. core/entity.py +133 -133
  27. core/environment.py +61 -61
  28. core/fields.py +168 -168
  29. core/form_fields.py +75 -75
  30. core/github_helper.py +188 -25
  31. core/github_issues.py +178 -172
  32. core/github_repos.py +72 -0
  33. core/lcd_screen.py +78 -78
  34. core/liveupdate.py +25 -25
  35. core/log_paths.py +100 -100
  36. core/mailer.py +85 -85
  37. core/middleware.py +91 -91
  38. core/models.py +3609 -2795
  39. core/notifications.py +105 -105
  40. core/public_wifi.py +267 -227
  41. core/reference_utils.py +108 -108
  42. core/release.py +721 -368
  43. core/rfid_import_export.py +113 -0
  44. core/sigil_builder.py +149 -149
  45. core/sigil_context.py +20 -20
  46. core/sigil_resolver.py +315 -315
  47. core/system.py +752 -493
  48. core/tasks.py +408 -394
  49. core/temp_passwords.py +181 -181
  50. core/test_system_info.py +186 -139
  51. core/tests.py +2095 -1521
  52. core/tests_liveupdate.py +17 -17
  53. core/urls.py +11 -11
  54. core/user_data.py +641 -633
  55. core/views.py +2175 -1417
  56. core/widgets.py +213 -94
  57. core/workgroup_urls.py +17 -17
  58. core/workgroup_views.py +94 -94
  59. nodes/admin.py +1720 -1161
  60. nodes/apps.py +87 -85
  61. nodes/backends.py +160 -160
  62. nodes/dns.py +203 -203
  63. nodes/feature_checks.py +133 -133
  64. nodes/lcd.py +165 -165
  65. nodes/models.py +1737 -1597
  66. nodes/reports.py +411 -411
  67. nodes/rfid_sync.py +195 -0
  68. nodes/signals.py +18 -0
  69. nodes/tasks.py +46 -46
  70. nodes/tests.py +3810 -3116
  71. nodes/urls.py +15 -14
  72. nodes/utils.py +121 -105
  73. nodes/views.py +683 -619
  74. ocpp/admin.py +948 -948
  75. ocpp/apps.py +25 -25
  76. ocpp/consumers.py +1565 -1459
  77. ocpp/evcs.py +844 -844
  78. ocpp/evcs_discovery.py +158 -158
  79. ocpp/models.py +917 -917
  80. ocpp/reference_utils.py +42 -42
  81. ocpp/routing.py +11 -11
  82. ocpp/simulator.py +745 -745
  83. ocpp/status_display.py +26 -26
  84. ocpp/store.py +601 -541
  85. ocpp/tasks.py +31 -31
  86. ocpp/test_export_import.py +130 -130
  87. ocpp/test_rfid.py +913 -702
  88. ocpp/tests.py +4445 -4094
  89. ocpp/transactions_io.py +189 -189
  90. ocpp/urls.py +50 -50
  91. ocpp/views.py +1479 -1251
  92. pages/admin.py +708 -539
  93. pages/apps.py +10 -10
  94. pages/checks.py +40 -40
  95. pages/context_processors.py +127 -119
  96. pages/defaults.py +13 -13
  97. pages/forms.py +198 -198
  98. pages/middleware.py +205 -153
  99. pages/models.py +607 -426
  100. pages/tests.py +2612 -2200
  101. pages/urls.py +25 -25
  102. pages/utils.py +12 -12
  103. pages/views.py +1165 -1128
  104. arthexis-0.1.13.dist-info/RECORD +0 -105
  105. nodes/actions.py +0 -70
  106. {arthexis-0.1.13.dist-info → arthexis-0.1.14.dist-info}/WHEEL +0 -0
  107. {arthexis-0.1.13.dist-info → arthexis-0.1.14.dist-info}/top_level.txt +0 -0
config/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
- """Config package initialization."""
2
-
3
- from .celery import app as celery_app
4
-
5
- __all__ = ("celery_app",)
1
+ """Config package initialization."""
2
+
3
+ from .celery import app as celery_app
4
+
5
+ __all__ = ("celery_app",)
config/active_app.py CHANGED
@@ -1,15 +1,15 @@
1
- import threading
2
- import socket
3
-
4
- _active = threading.local()
5
- _active.name = socket.gethostname()
6
-
7
-
8
- def get_active_app():
9
- """Return the currently active app name."""
10
- return getattr(_active, "name", socket.gethostname())
11
-
12
-
13
- def set_active_app(name: str) -> None:
14
- """Set the active app name for the current thread."""
15
- _active.name = name or socket.gethostname()
1
+ import threading
2
+ import socket
3
+
4
+ _active = threading.local()
5
+ _active.name = socket.gethostname()
6
+
7
+
8
+ def get_active_app():
9
+ """Return the currently active app name."""
10
+ return getattr(_active, "name", socket.gethostname())
11
+
12
+
13
+ def set_active_app(name: str) -> None:
14
+ """Set the active app name for the current thread."""
15
+ _active.name = name or socket.gethostname()
config/asgi.py CHANGED
@@ -1,43 +1,43 @@
1
- """
2
- ASGI config for config project.
3
-
4
- It exposes the ASGI callable as a module-level variable named ``application``.
5
-
6
- For more information on this file, see
7
- https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
8
- """
9
-
10
- import os
11
- from config.loadenv import loadenv
12
- from typing import Any, Awaitable, Callable, Dict, MutableMapping
13
- from channels.auth import AuthMiddlewareStack
14
- from channels.routing import ProtocolTypeRouter, URLRouter
15
- from django.core.asgi import get_asgi_application
16
- import ocpp.routing
17
-
18
- from core.mcp.asgi import application as mcp_application
19
- from core.mcp.asgi import is_mcp_scope
20
-
21
- loadenv()
22
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
23
-
24
- django_asgi_app = get_asgi_application()
25
-
26
- Scope = MutableMapping[str, Any]
27
- Receive = Callable[[], Awaitable[Dict[str, Any]]]
28
- Send = Callable[[Dict[str, Any]], Awaitable[None]]
29
-
30
- websocket_patterns = ocpp.routing.websocket_urlpatterns
31
-
32
- async def http_application(scope: Scope, receive: Receive, send: Send) -> None:
33
- if is_mcp_scope(scope):
34
- await mcp_application(scope, receive, send)
35
- else:
36
- await django_asgi_app(scope, receive, send)
37
-
38
- application = ProtocolTypeRouter(
39
- {
40
- "http": http_application,
41
- "websocket": AuthMiddlewareStack(URLRouter(websocket_patterns)),
42
- }
43
- )
1
+ """
2
+ ASGI config for config project.
3
+
4
+ It exposes the ASGI callable as a module-level variable named ``application``.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
8
+ """
9
+
10
+ import os
11
+ from config.loadenv import loadenv
12
+ from typing import Any, Awaitable, Callable, Dict, MutableMapping
13
+ from channels.auth import AuthMiddlewareStack
14
+ from channels.routing import ProtocolTypeRouter, URLRouter
15
+ from django.core.asgi import get_asgi_application
16
+ import ocpp.routing
17
+
18
+ from core.mcp.asgi import application as mcp_application
19
+ from core.mcp.asgi import is_mcp_scope
20
+
21
+ loadenv()
22
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
23
+
24
+ django_asgi_app = get_asgi_application()
25
+
26
+ Scope = MutableMapping[str, Any]
27
+ Receive = Callable[[], Awaitable[Dict[str, Any]]]
28
+ Send = Callable[[Dict[str, Any]], Awaitable[None]]
29
+
30
+ websocket_patterns = ocpp.routing.websocket_urlpatterns
31
+
32
+ async def http_application(scope: Scope, receive: Receive, send: Send) -> None:
33
+ if is_mcp_scope(scope):
34
+ await mcp_application(scope, receive, send)
35
+ else:
36
+ await django_asgi_app(scope, receive, send)
37
+
38
+ application = ProtocolTypeRouter(
39
+ {
40
+ "http": http_application,
41
+ "websocket": AuthMiddlewareStack(URLRouter(websocket_patterns)),
42
+ }
43
+ )
config/auth_app.py CHANGED
@@ -1,7 +1,7 @@
1
- from django.contrib.auth.apps import AuthConfig as DjangoAuthConfig
2
-
3
-
4
- class AuthConfig(DjangoAuthConfig):
5
- """Use a shorter label for the auth section in the admin."""
6
-
7
- verbose_name = "AUTH"
1
+ from django.contrib.auth.apps import AuthConfig as DjangoAuthConfig
2
+
3
+
4
+ class AuthConfig(DjangoAuthConfig):
5
+ """Use a shorter label for the auth section in the admin."""
6
+
7
+ verbose_name = "AUTH"
config/celery.py CHANGED
@@ -1,32 +1,32 @@
1
- """Celery application configuration."""
2
-
3
- import os
4
-
5
- from celery import Celery
6
-
7
-
8
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
9
-
10
- # When running on production-oriented nodes, avoid Celery debug mode.
11
- NODE_ROLE = os.environ.get("NODE_ROLE", "")
12
- PRODUCTION_ROLES = {
13
- "constellation",
14
- "satellite",
15
- "control",
16
- "terminal",
17
- "gateway",
18
- }
19
- if NODE_ROLE.lower() in PRODUCTION_ROLES:
20
- for var in ["CELERY_TRACE_APP", "CELERY_DEBUG"]:
21
- os.environ.pop(var, None)
22
- os.environ.setdefault("CELERY_LOG_LEVEL", "INFO")
23
-
24
- app = Celery("config")
25
- app.config_from_object("django.conf:settings", namespace="CELERY")
26
- app.autodiscover_tasks()
27
-
28
-
29
- @app.task(bind=True)
30
- def debug_task(self): # pragma: no cover - debug helper
31
- """A simple debug task."""
32
- print(f"Request: {self.request!r}")
1
+ """Celery application configuration."""
2
+
3
+ import os
4
+
5
+ from celery import Celery
6
+
7
+
8
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
9
+
10
+ # When running on production-oriented nodes, avoid Celery debug mode.
11
+ NODE_ROLE = os.environ.get("NODE_ROLE", "")
12
+ PRODUCTION_ROLES = {
13
+ "constellation",
14
+ "satellite",
15
+ "control",
16
+ "terminal",
17
+ "gateway",
18
+ }
19
+ if NODE_ROLE.lower() in PRODUCTION_ROLES:
20
+ for var in ["CELERY_TRACE_APP", "CELERY_DEBUG"]:
21
+ os.environ.pop(var, None)
22
+ os.environ.setdefault("CELERY_LOG_LEVEL", "INFO")
23
+
24
+ app = Celery("config")
25
+ app.config_from_object("django.conf:settings", namespace="CELERY")
26
+ app.autodiscover_tasks()
27
+
28
+
29
+ @app.task(bind=True)
30
+ def debug_task(self): # pragma: no cover - debug helper
31
+ """A simple debug task."""
32
+ print(f"Request: {self.request!r}")
@@ -1,69 +1,67 @@
1
- import socket
2
-
3
- from django.contrib.sites.models import Site
4
- from django.http import HttpRequest
5
- from django.conf import settings
6
-
7
-
8
- def site_and_node(request: HttpRequest):
9
- """Provide current Site and Node based on request host.
10
-
11
- Returns a dict with keys ``badge_site`` and ``badge_node``.
12
- ``badge_site`` is a ``Site`` instance or ``None`` if no match.
13
- ``badge_node`` is a ``Node`` instance or ``None`` if no match.
14
- ``badge_site_color`` and ``badge_node_color`` provide the configured colors.
15
- """
16
- host = request.get_host().split(":")[0]
17
- site = Site.objects.filter(domain__iexact=host).first()
18
-
19
- node = None
20
- try:
21
- from nodes.models import Node
22
-
23
- node = Node.get_local()
24
- if not node:
25
- hostname = socket.gethostname()
26
- try:
27
- addresses = socket.gethostbyname_ex(hostname)[2]
28
- except socket.gaierror:
29
- addresses = []
30
-
31
- node = Node.objects.filter(hostname__iexact=hostname).first()
32
- if not node:
33
- for addr in addresses:
34
- node = Node.objects.filter(address=addr).first()
35
- if node:
36
- break
37
- if not node:
38
- node = (
39
- Node.objects.filter(hostname__iexact=host).first()
40
- or Node.objects.filter(address=host).first()
41
- )
42
- except Exception:
43
- node = None
44
-
45
- site_color = "#28a745"
46
- if site:
47
- try:
48
- site_color = site.badge.badge_color
49
- except Exception:
50
- pass
51
-
52
- node_color = "#28a745"
53
- if node:
54
- node_color = node.badge_color
55
-
56
- site_name = site.name if site else ""
57
- node_role_name = node.role.name if node and node.role else ""
58
- return {
59
- "badge_site": site,
60
- "badge_node": node,
61
- # Public views fall back to the node role when the site name is blank.
62
- "badge_site_name": site_name or node_role_name,
63
- # Admin site badge uses the site display name if set, otherwise the domain.
64
- "badge_admin_site_name": site_name or (site.domain if site else ""),
65
- "badge_site_color": site_color,
66
- "badge_node_color": node_color,
67
- "current_site_domain": site.domain if site else host,
68
- "TIME_ZONE": settings.TIME_ZONE,
69
- }
1
+ import socket
2
+
3
+ from django.contrib.sites.models import Site
4
+ from django.http import HttpRequest
5
+ from django.conf import settings
6
+
7
+
8
+ DEFAULT_BADGE_COLOR = "#28a745"
9
+ UNKNOWN_BADGE_COLOR = "#6c757d"
10
+
11
+
12
+ def site_and_node(request: HttpRequest):
13
+ """Provide current Site and Node based on request host.
14
+
15
+ Returns a dict with keys ``badge_site`` and ``badge_node``.
16
+ ``badge_site`` is a ``Site`` instance or ``None`` if no match.
17
+ ``badge_node`` is a ``Node`` instance or ``None`` if no match.
18
+ ``badge_site_color`` and ``badge_node_color`` report the palette color used
19
+ for the corresponding badge. Badges always use green when the entity is
20
+ known and grey when the value cannot be determined.
21
+ """
22
+ host = request.get_host().split(":")[0]
23
+ site = Site.objects.filter(domain__iexact=host).first()
24
+
25
+ node = None
26
+ try:
27
+ from nodes.models import Node
28
+
29
+ node = Node.get_local()
30
+ if not node:
31
+ hostname = socket.gethostname()
32
+ try:
33
+ addresses = socket.gethostbyname_ex(hostname)[2]
34
+ except socket.gaierror:
35
+ addresses = []
36
+
37
+ node = Node.objects.filter(hostname__iexact=hostname).first()
38
+ if not node:
39
+ for addr in addresses:
40
+ node = Node.objects.filter(address=addr).first()
41
+ if node:
42
+ break
43
+ if not node:
44
+ node = (
45
+ Node.objects.filter(hostname__iexact=host).first()
46
+ or Node.objects.filter(address=host).first()
47
+ )
48
+ except Exception:
49
+ node = None
50
+
51
+ site_color = DEFAULT_BADGE_COLOR if site else UNKNOWN_BADGE_COLOR
52
+ node_color = DEFAULT_BADGE_COLOR if node else UNKNOWN_BADGE_COLOR
53
+
54
+ site_name = site.name if site else ""
55
+ node_role_name = node.role.name if node and node.role else ""
56
+ return {
57
+ "badge_site": site,
58
+ "badge_node": node,
59
+ # Public views fall back to the node role when the site name is blank.
60
+ "badge_site_name": site_name or node_role_name,
61
+ # Admin site badge uses the site display name if set, otherwise the domain.
62
+ "badge_admin_site_name": site_name or (site.domain if site else ""),
63
+ "badge_site_color": site_color,
64
+ "badge_node_color": node_color,
65
+ "current_site_domain": site.domain if site else host,
66
+ "TIME_ZONE": settings.TIME_ZONE,
67
+ }
config/horologia_app.py CHANGED
@@ -1,7 +1,7 @@
1
- from django_celery_beat.apps import BeatConfig as BaseBeatConfig
2
-
3
-
4
- class HorologiaConfig(BaseBeatConfig):
5
- """Customize Periodic Tasks app label."""
6
-
7
- verbose_name = "5. Horologia"
1
+ from django_celery_beat.apps import BeatConfig as BaseBeatConfig
2
+
3
+
4
+ class HorologiaConfig(BaseBeatConfig):
5
+ """Customize Periodic Tasks app label."""
6
+
7
+ verbose_name = "5. Horologia"
config/loadenv.py CHANGED
@@ -1,11 +1,11 @@
1
- from pathlib import Path
2
- from dotenv import load_dotenv
3
-
4
-
5
- BASE_DIR = Path(__file__).resolve().parent.parent
6
-
7
-
8
- def loadenv() -> None:
9
- """Load all .env files from the repository root."""
10
- for env_file in sorted(BASE_DIR.glob("*.env")):
11
- load_dotenv(env_file, override=False)
1
+ from pathlib import Path
2
+ from dotenv import load_dotenv
3
+
4
+
5
+ BASE_DIR = Path(__file__).resolve().parent.parent
6
+
7
+
8
+ def loadenv() -> None:
9
+ """Load all .env files from the repository root."""
10
+ for env_file in sorted(BASE_DIR.glob("*.env")):
11
+ load_dotenv(env_file, override=False)
config/logging.py CHANGED
@@ -1,48 +1,59 @@
1
- import sys
2
- import os
3
- import glob
4
- import logging
5
- from logging.handlers import TimedRotatingFileHandler
6
- from pathlib import Path
7
- from django.conf import settings
8
-
9
- from .active_app import get_active_app
10
-
11
-
12
- class ActiveAppFileHandler(TimedRotatingFileHandler):
13
- """File handler that writes to a file named after the active app."""
14
-
15
- def _current_file(self) -> Path:
16
- log_dir = Path(settings.LOG_DIR)
17
- log_dir.mkdir(parents=True, exist_ok=True)
18
- if "test" in sys.argv:
19
- return log_dir / "tests.log"
20
- return log_dir / f"{get_active_app()}.log"
21
-
22
- def emit(self, record: logging.LogRecord) -> None:
23
- current = str(self._current_file())
24
- if self.baseFilename != current:
25
- self.baseFilename = current
26
- Path(self.baseFilename).parent.mkdir(parents=True, exist_ok=True)
27
- if self.stream:
28
- self.stream.close()
29
- self.stream = self._open()
30
- super().emit(record)
31
-
32
- def rotation_filename(self, default_name: str) -> str:
33
- """Place rotated logs inside the old log directory."""
34
- default_path = Path(default_name)
35
- old_log_dir = Path(settings.OLD_LOG_DIR)
36
- old_log_dir.mkdir(parents=True, exist_ok=True)
37
- return str(old_log_dir / default_path.name)
38
-
39
- def getFilesToDelete(self):
40
- """Return files to delete in the old log directory respecting backupCount."""
41
- if self.backupCount <= 0:
42
- return []
43
- _, base_name = os.path.split(self.baseFilename)
44
- files = glob.glob(os.path.join(settings.OLD_LOG_DIR, base_name + ".*"))
45
- files.sort()
46
- if len(files) <= self.backupCount:
47
- return []
48
- return files[: len(files) - self.backupCount]
1
+ import sys
2
+ import os
3
+ import glob
4
+ import logging
5
+ from logging.handlers import TimedRotatingFileHandler
6
+ from pathlib import Path
7
+ from django.conf import settings
8
+
9
+ from .active_app import get_active_app
10
+
11
+
12
+ class ActiveAppFileHandler(TimedRotatingFileHandler):
13
+ """File handler that writes to a file named after the active app."""
14
+
15
+ def _current_file(self) -> Path:
16
+ log_dir = Path(settings.LOG_DIR)
17
+ log_dir.mkdir(parents=True, exist_ok=True)
18
+ if "test" in sys.argv:
19
+ return log_dir / "tests.log"
20
+ return log_dir / f"{get_active_app()}.log"
21
+
22
+ def emit(self, record: logging.LogRecord) -> None:
23
+ current = str(self._current_file())
24
+ if self.baseFilename != current:
25
+ self.baseFilename = current
26
+ Path(self.baseFilename).parent.mkdir(parents=True, exist_ok=True)
27
+ if self.stream:
28
+ self.stream.close()
29
+ self.stream = self._open()
30
+ super().emit(record)
31
+
32
+ def rotation_filename(self, default_name: str) -> str:
33
+ """Place rotated logs inside the old log directory."""
34
+ default_path = Path(default_name)
35
+ old_log_dir = Path(settings.OLD_LOG_DIR)
36
+ old_log_dir.mkdir(parents=True, exist_ok=True)
37
+ return str(old_log_dir / default_path.name)
38
+
39
+ def getFilesToDelete(self):
40
+ """Return files to delete in the old log directory respecting backupCount."""
41
+ if self.backupCount <= 0:
42
+ return []
43
+ _, base_name = os.path.split(self.baseFilename)
44
+ files = glob.glob(os.path.join(settings.OLD_LOG_DIR, base_name + ".*"))
45
+ files.sort()
46
+ if len(files) <= self.backupCount:
47
+ return []
48
+ return files[: len(files) - self.backupCount]
49
+
50
+
51
+ class ErrorFileHandler(ActiveAppFileHandler):
52
+ """File handler dedicated to capturing application errors."""
53
+
54
+ def _current_file(self) -> Path:
55
+ log_dir = Path(settings.LOG_DIR)
56
+ log_dir.mkdir(parents=True, exist_ok=True)
57
+ if "test" in sys.argv:
58
+ return log_dir / "tests-error.log"
59
+ return log_dir / "error.log"
config/middleware.py CHANGED
@@ -1,25 +1,25 @@
1
- from utils.sites import get_site
2
- import socket
3
- from nodes.models import Node
4
-
5
- from .active_app import set_active_app
6
-
7
-
8
- class ActiveAppMiddleware:
9
- """Store the current app based on the request's site."""
10
-
11
- def __init__(self, get_response):
12
- self.get_response = get_response
13
-
14
- def __call__(self, request):
15
- site = get_site(request)
16
- node = Node.get_local()
17
- role_name = node.role.name if node and node.role else "Terminal"
18
- active = site.name or role_name
19
- set_active_app(active)
20
- request.active_app = active
21
- try:
22
- response = self.get_response(request)
23
- finally:
24
- set_active_app(socket.gethostname())
25
- return response
1
+ from utils.sites import get_site
2
+ import socket
3
+ from nodes.models import Node
4
+
5
+ from .active_app import set_active_app
6
+
7
+
8
+ class ActiveAppMiddleware:
9
+ """Store the current app based on the request's site."""
10
+
11
+ def __init__(self, get_response):
12
+ self.get_response = get_response
13
+
14
+ def __call__(self, request):
15
+ site = get_site(request)
16
+ node = Node.get_local()
17
+ role_name = node.role.name if node and node.role else "Terminal"
18
+ active = site.name or role_name
19
+ set_active_app(active)
20
+ request.active_app = active
21
+ try:
22
+ response = self.get_response(request)
23
+ finally:
24
+ set_active_app(socket.gethostname())
25
+ return response
config/offline.py CHANGED
@@ -1,49 +1,49 @@
1
- import os
2
- import functools
3
- import asyncio
4
-
5
-
6
- class OfflineError(RuntimeError):
7
- """Raised when a network operation is attempted in offline mode."""
8
-
9
-
10
- def _is_offline() -> bool:
11
- flag = os.environ.get("ARTHEXIS_OFFLINE", "").lower()
12
- return flag not in ("", "0", "false", "no")
13
-
14
-
15
- def requires_network(func):
16
- """Decorator that blocks execution when offline mode is enabled.
17
-
18
- When the environment variable ``ARTHEXIS_OFFLINE`` is set to a truthy value,
19
- any function decorated with ``@requires_network`` will raise
20
- :class:`OfflineError` before executing. Works with both synchronous and
21
- asynchronous callables.
22
- """
23
-
24
- if asyncio.iscoroutinefunction(func):
25
-
26
- @functools.wraps(func)
27
- async def async_wrapper(*args, **kwargs):
28
- if _is_offline():
29
- raise OfflineError(f"{func.__name__} requires network access")
30
- return await func(*args, **kwargs)
31
-
32
- return async_wrapper
33
-
34
- @functools.wraps(func)
35
- def sync_wrapper(*args, **kwargs):
36
- if _is_offline():
37
- raise OfflineError(f"{func.__name__} requires network access")
38
- return func(*args, **kwargs)
39
-
40
- return sync_wrapper
41
-
42
-
43
- def network_available() -> bool:
44
- """Return ``True`` if network operations are permitted."""
45
-
46
- return not _is_offline()
47
-
48
-
49
- __all__ = ["OfflineError", "requires_network", "network_available"]
1
+ import os
2
+ import functools
3
+ import asyncio
4
+
5
+
6
+ class OfflineError(RuntimeError):
7
+ """Raised when a network operation is attempted in offline mode."""
8
+
9
+
10
+ def _is_offline() -> bool:
11
+ flag = os.environ.get("ARTHEXIS_OFFLINE", "").lower()
12
+ return flag not in ("", "0", "false", "no")
13
+
14
+
15
+ def requires_network(func):
16
+ """Decorator that blocks execution when offline mode is enabled.
17
+
18
+ When the environment variable ``ARTHEXIS_OFFLINE`` is set to a truthy value,
19
+ any function decorated with ``@requires_network`` will raise
20
+ :class:`OfflineError` before executing. Works with both synchronous and
21
+ asynchronous callables.
22
+ """
23
+
24
+ if asyncio.iscoroutinefunction(func):
25
+
26
+ @functools.wraps(func)
27
+ async def async_wrapper(*args, **kwargs):
28
+ if _is_offline():
29
+ raise OfflineError(f"{func.__name__} requires network access")
30
+ return await func(*args, **kwargs)
31
+
32
+ return async_wrapper
33
+
34
+ @functools.wraps(func)
35
+ def sync_wrapper(*args, **kwargs):
36
+ if _is_offline():
37
+ raise OfflineError(f"{func.__name__} requires network access")
38
+ return func(*args, **kwargs)
39
+
40
+ return sync_wrapper
41
+
42
+
43
+ def network_available() -> bool:
44
+ """Return ``True`` if network operations are permitted."""
45
+
46
+ return not _is_offline()
47
+
48
+
49
+ __all__ = ["OfflineError", "requires_network", "network_available"]