diff --git a/moonraker/components/gpio.py b/moonraker/components/gpio.py index bd52f64..ab64a95 100644 --- a/moonraker/components/gpio.py +++ b/moonraker/components/gpio.py @@ -7,10 +7,10 @@ from __future__ import annotations import os import re import asyncio -import platform import pathlib import logging import periphery +from ..utils import KERNEL_VERSION # Annotation imports from typing import ( @@ -28,11 +28,6 @@ if TYPE_CHECKING: GpioEventCallback = Callable[[float, float, int], Optional[Awaitable[None]]] -try: - KERNEL_VERSION = tuple([int(part) for part in platform.release().split(".")[:2]]) -except Exception: - KERNEL_VERSION = (0, 0) - GPIO_PATTERN = r""" (?P[~^])? (?P!)? diff --git a/moonraker/components/machine.py b/moonraker/components/machine.py index be72feb..c78c602 100644 --- a/moonraker/components/machine.py +++ b/moonraker/components/machine.py @@ -96,6 +96,7 @@ class Machine: dist_info = {'name': distro.name(pretty=True)} dist_info.update(distro.info()) dist_info['release_info'] = distro.distro_release_info() + dist_info['kernel_version'] = platform.release() self.inside_container = False self.moonraker_service_info: Dict[str, Any] = {} self.sudo_req_lock = asyncio.Lock() diff --git a/moonraker/loghelper.py b/moonraker/loghelper.py index c2809a0..8245fb7 100644 --- a/moonraker/loghelper.py +++ b/moonraker/loghelper.py @@ -11,6 +11,7 @@ import time import os import sys import asyncio +import platform from queue import SimpleQueue as Queue from .common import RequestType @@ -61,6 +62,7 @@ class MoonrakerLoggingHandler(logging.handlers.TimedRotatingFileHandler): strtime = time.asctime(time.gmtime()) header = f"{'-'*20} Log Start | {strtime} {'-'*20}\n" self.stream.write(header) + self.stream.write(f"platform: {platform.platform(terse=True)}\n") app_section = "\n".join([f"{k}: {v}" for k, v in self.app_args.items()]) self.stream.write(app_section + "\n") if self.rollover_info: @@ -82,7 +84,8 @@ class LogManager: stdout_fmt = logging.Formatter( '[%(filename)s:%(funcName)s()] - %(message)s') stdout_hdlr.setFormatter(stdout_fmt) - app_args_str = "\n".join([f"{k}: {v}" for k, v in app_args.items()]) + app_args_str = f"platform: {platform.platform(terse=True)}\n" + app_args_str += "\n".join([f"{k}: {v}" for k, v in app_args.items()]) sys.stdout.write(f"\nApplication Info:\n{app_args_str}\n") self.file_hdlr: Optional[MoonrakerLoggingHandler] = None self.listener: Optional[logging.handlers.QueueListener] = None diff --git a/moonraker/utils/__init__.py b/moonraker/utils/__init__.py index 61c8c53..5a216a3 100644 --- a/moonraker/utils/__init__.py +++ b/moonraker/utils/__init__.py @@ -20,6 +20,7 @@ import struct import socket import enum import ipaddress +import platform from . import source_info from . import json_wrapper @@ -43,6 +44,11 @@ SYS_MOD_PATHS += glob.glob("/usr/lib/python3*/site-packages") SYS_MOD_PATHS += glob.glob("/usr/lib/*-linux-gnu/python3*/site-packages") IPAddress = Union[ipaddress.IPv4Address, ipaddress.IPv6Address] +try: + KERNEL_VERSION = tuple([int(part) for part in platform.release().split(".")[:2]]) +except Exception: + KERNEL_VERSION = (0, 0) + class ServerError(Exception): def __init__(self, message: str, status_code: int = 400) -> None: Exception.__init__(self, message)