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:
parent
10dfb0d477
commit
98bb40bd80
|
@ -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<bias>[~^])?
|
||||
(?P<inverted>!)?
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue