mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2025-01-18 10:30:48 +00:00
logging module now used to log interface events.
register, deregister method aliases added to Subject class.
This commit is contained in:
parent
db96872965
commit
23bc15e437
@ -1,4 +1,5 @@
|
||||
import itertools
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
@ -118,6 +119,8 @@ class Loader(metaclass=SingletonType):
|
||||
loads data into memory if not found
|
||||
"""
|
||||
|
||||
logger = logging.getLogger("config.Loader")
|
||||
|
||||
def __init__(self, kind):
|
||||
self._kind = kind
|
||||
self._configs = dict()
|
||||
@ -131,14 +134,16 @@ class Loader(metaclass=SingletonType):
|
||||
|
||||
def parse(self, identifier, data):
|
||||
if identifier in self._configs:
|
||||
print(f"config file with name {identifier} already in memory, skipping..")
|
||||
self.logger.info(
|
||||
f"config file with name {identifier} already in memory, skipping.."
|
||||
)
|
||||
return False
|
||||
self.parser = dataextraction_factory(data)
|
||||
return True
|
||||
|
||||
def register(self, identifier, data=None):
|
||||
self._configs[identifier] = data if data else self.parser.data
|
||||
print(f"config {self.name}/{identifier} loaded into memory")
|
||||
self.logger.info(f"config {self.name}/{identifier} loaded into memory")
|
||||
|
||||
def deregister(self):
|
||||
self._configs.clear()
|
||||
@ -161,6 +166,7 @@ def loader(kind):
|
||||
|
||||
returns configs loaded into memory
|
||||
"""
|
||||
logger = logging.getLogger("config.loader")
|
||||
loader = Loader(kind)
|
||||
|
||||
for path in (
|
||||
@ -169,7 +175,7 @@ def loader(kind):
|
||||
Path.home() / "Documents/Voicemeeter" / "configs" / kind.name,
|
||||
):
|
||||
if path.is_dir():
|
||||
print(f"Checking [{path}] for TOML config files:")
|
||||
logger.info(f"Checking [{path}] for TOML config files:")
|
||||
for file in path.glob("*.toml"):
|
||||
identifier = file.with_suffix("").stem
|
||||
if loader.parse(identifier, file):
|
||||
|
@ -1,15 +1,16 @@
|
||||
import logging
|
||||
from abc import abstractmethod
|
||||
from enum import IntEnum
|
||||
from functools import cached_property
|
||||
from typing import Iterable, NoReturn
|
||||
|
||||
from .base import VbanCmd
|
||||
from .bus import request_bus_obj as bus
|
||||
from .command import Command
|
||||
from .config import request_config as configs
|
||||
from .kinds import KindMapClass
|
||||
from .kinds import request_kind_map as kindmap
|
||||
from .strip import request_strip_obj as strip
|
||||
from .vbancmd import VbanCmd
|
||||
|
||||
|
||||
class FactoryBuilder:
|
||||
@ -19,6 +20,7 @@ class FactoryBuilder:
|
||||
Separates construction from representation.
|
||||
"""
|
||||
|
||||
logger = logging.getLogger("vbancmd.factorybuilder")
|
||||
BuilderProgress = IntEnum("BuilderProgress", "strip bus command", start=0)
|
||||
|
||||
def __init__(self, factory, kind: KindMapClass):
|
||||
@ -33,7 +35,7 @@ class FactoryBuilder:
|
||||
def _pinfo(self, name: str) -> NoReturn:
|
||||
"""prints progress status for each step"""
|
||||
name = name.split("_")[1]
|
||||
print(self._info[int(getattr(self.BuilderProgress, name))])
|
||||
self.logger.info(self._info[int(getattr(self.BuilderProgress, name))])
|
||||
|
||||
def make_strip(self):
|
||||
self._factory.strip = tuple(
|
||||
|
@ -1,6 +1,11 @@
|
||||
import logging
|
||||
|
||||
|
||||
class Subject:
|
||||
"""Adds support for observers"""
|
||||
|
||||
logger = logging.getLogger("subject.subject")
|
||||
|
||||
def __init__(self):
|
||||
"""list of current observers"""
|
||||
|
||||
@ -22,16 +27,26 @@ class Subject:
|
||||
|
||||
if observer not in self._observers:
|
||||
self._observers.append(observer)
|
||||
self.logger.info(f"{type(observer).__name__} added to event observers")
|
||||
else:
|
||||
print(f"Failed to add: {observer}")
|
||||
self.logger.error(
|
||||
f"Failed to add {type(observer).__name__} to event observers"
|
||||
)
|
||||
|
||||
register = add
|
||||
|
||||
def remove(self, observer):
|
||||
"""removes an observer from _observers"""
|
||||
|
||||
try:
|
||||
self._observers.remove(observer)
|
||||
self.logger.info(f"{type(observer).__name__} removed from event observers")
|
||||
except ValueError:
|
||||
print(f"Failed to remove: {observer}")
|
||||
self.logger.error(
|
||||
f"Failed to remove {type(observer).__name__} from event observers"
|
||||
)
|
||||
|
||||
deregister = remove
|
||||
|
||||
def clear(self):
|
||||
"""clears the _observers list"""
|
||||
|
@ -1,3 +1,4 @@
|
||||
import logging
|
||||
import socket
|
||||
import time
|
||||
from abc import ABCMeta, abstractmethod
|
||||
@ -21,6 +22,7 @@ class VbanCmd(metaclass=ABCMeta):
|
||||
1000000, 1500000, 2000000, 3000000,
|
||||
]
|
||||
# fmt: on
|
||||
logger = logging.getLogger("vbancmd.vbancmd")
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
for attr, val in kwargs.items():
|
||||
@ -57,6 +59,8 @@ class VbanCmd(metaclass=ABCMeta):
|
||||
self.updater = Updater(self)
|
||||
self.updater.start()
|
||||
|
||||
self.logger.info(f"{type(self).__name__}: Successfully logged into {self}")
|
||||
|
||||
def _set_rt(
|
||||
self,
|
||||
id_: str,
|
||||
|
@ -1,3 +1,4 @@
|
||||
import logging
|
||||
import socket
|
||||
import threading
|
||||
import time
|
||||
@ -39,6 +40,8 @@ class Updater(threading.Thread):
|
||||
notifies observers of event updates
|
||||
"""
|
||||
|
||||
logger = logging.getLogger("worker.updater")
|
||||
|
||||
def __init__(self, remote):
|
||||
super().__init__(name="updater", target=self.update, daemon=True)
|
||||
self._remote = remote
|
||||
@ -98,7 +101,7 @@ class Updater(threading.Thread):
|
||||
return fget()
|
||||
|
||||
def update(self):
|
||||
print(f"Listening for {', '.join(self._remote.event.get())} events")
|
||||
self.logger.info(f"Listening for {', '.join(self._remote.event.get())} events")
|
||||
(
|
||||
self._remote.cache["strip_level"],
|
||||
self._remote.cache["bus_level"],
|
||||
|
Loading…
Reference in New Issue
Block a user