utils: add kernel version

Move the kernel version tuple calculation out of gpio.py into
the utils package so its available for any module that requires
it.  In addition, report the kernel version string with the distribution
info and log the platform in the rollover header.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-03-11 06:16:09 -04:00
parent 10dfb0d477
commit 98bb40bd80
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
4 changed files with 12 additions and 7 deletions

View File

@ -7,10 +7,10 @@ from __future__ import annotations
import os import os
import re import re
import asyncio import asyncio
import platform
import pathlib import pathlib
import logging import logging
import periphery import periphery
from ..utils import KERNEL_VERSION
# Annotation imports # Annotation imports
from typing import ( from typing import (
@ -28,11 +28,6 @@ if TYPE_CHECKING:
GpioEventCallback = Callable[[float, float, int], Optional[Awaitable[None]]] 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""" GPIO_PATTERN = r"""
(?P<bias>[~^])? (?P<bias>[~^])?
(?P<inverted>!)? (?P<inverted>!)?

View File

@ -96,6 +96,7 @@ class Machine:
dist_info = {'name': distro.name(pretty=True)} dist_info = {'name': distro.name(pretty=True)}
dist_info.update(distro.info()) dist_info.update(distro.info())
dist_info['release_info'] = distro.distro_release_info() dist_info['release_info'] = distro.distro_release_info()
dist_info['kernel_version'] = platform.release()
self.inside_container = False self.inside_container = False
self.moonraker_service_info: Dict[str, Any] = {} self.moonraker_service_info: Dict[str, Any] = {}
self.sudo_req_lock = asyncio.Lock() self.sudo_req_lock = asyncio.Lock()

View File

@ -11,6 +11,7 @@ import time
import os import os
import sys import sys
import asyncio import asyncio
import platform
from queue import SimpleQueue as Queue from queue import SimpleQueue as Queue
from .common import RequestType from .common import RequestType
@ -61,6 +62,7 @@ class MoonrakerLoggingHandler(logging.handlers.TimedRotatingFileHandler):
strtime = time.asctime(time.gmtime()) strtime = time.asctime(time.gmtime())
header = f"{'-'*20} Log Start | {strtime} {'-'*20}\n" header = f"{'-'*20} Log Start | {strtime} {'-'*20}\n"
self.stream.write(header) 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()]) app_section = "\n".join([f"{k}: {v}" for k, v in self.app_args.items()])
self.stream.write(app_section + "\n") self.stream.write(app_section + "\n")
if self.rollover_info: if self.rollover_info:
@ -82,7 +84,8 @@ class LogManager:
stdout_fmt = logging.Formatter( stdout_fmt = logging.Formatter(
'[%(filename)s:%(funcName)s()] - %(message)s') '[%(filename)s:%(funcName)s()] - %(message)s')
stdout_hdlr.setFormatter(stdout_fmt) 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") sys.stdout.write(f"\nApplication Info:\n{app_args_str}\n")
self.file_hdlr: Optional[MoonrakerLoggingHandler] = None self.file_hdlr: Optional[MoonrakerLoggingHandler] = None
self.listener: Optional[logging.handlers.QueueListener] = None self.listener: Optional[logging.handlers.QueueListener] = None

View File

@ -20,6 +20,7 @@ import struct
import socket import socket
import enum import enum
import ipaddress import ipaddress
import platform
from . import source_info from . import source_info
from . import json_wrapper 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") SYS_MOD_PATHS += glob.glob("/usr/lib/*-linux-gnu/python3*/site-packages")
IPAddress = Union[ipaddress.IPv4Address, ipaddress.IPv6Address] 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): class ServerError(Exception):
def __init__(self, message: str, status_code: int = 400) -> None: def __init__(self, message: str, status_code: int = 400) -> None:
Exception.__init__(self, message) Exception.__init__(self, message)