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 itertools
|
||||||
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -118,6 +119,8 @@ class Loader(metaclass=SingletonType):
|
|||||||
loads data into memory if not found
|
loads data into memory if not found
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
logger = logging.getLogger("config.Loader")
|
||||||
|
|
||||||
def __init__(self, kind):
|
def __init__(self, kind):
|
||||||
self._kind = kind
|
self._kind = kind
|
||||||
self._configs = dict()
|
self._configs = dict()
|
||||||
@ -131,14 +134,16 @@ class Loader(metaclass=SingletonType):
|
|||||||
|
|
||||||
def parse(self, identifier, data):
|
def parse(self, identifier, data):
|
||||||
if identifier in self._configs:
|
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
|
return False
|
||||||
self.parser = dataextraction_factory(data)
|
self.parser = dataextraction_factory(data)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def register(self, identifier, data=None):
|
def register(self, identifier, data=None):
|
||||||
self._configs[identifier] = data if data else self.parser.data
|
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):
|
def deregister(self):
|
||||||
self._configs.clear()
|
self._configs.clear()
|
||||||
@ -161,6 +166,7 @@ def loader(kind):
|
|||||||
|
|
||||||
returns configs loaded into memory
|
returns configs loaded into memory
|
||||||
"""
|
"""
|
||||||
|
logger = logging.getLogger("config.loader")
|
||||||
loader = Loader(kind)
|
loader = Loader(kind)
|
||||||
|
|
||||||
for path in (
|
for path in (
|
||||||
@ -169,7 +175,7 @@ def loader(kind):
|
|||||||
Path.home() / "Documents/Voicemeeter" / "configs" / kind.name,
|
Path.home() / "Documents/Voicemeeter" / "configs" / kind.name,
|
||||||
):
|
):
|
||||||
if path.is_dir():
|
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"):
|
for file in path.glob("*.toml"):
|
||||||
identifier = file.with_suffix("").stem
|
identifier = file.with_suffix("").stem
|
||||||
if loader.parse(identifier, file):
|
if loader.parse(identifier, file):
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
|
import logging
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from typing import Iterable, NoReturn
|
from typing import Iterable, NoReturn
|
||||||
|
|
||||||
from .base import VbanCmd
|
|
||||||
from .bus import request_bus_obj as bus
|
from .bus import request_bus_obj as bus
|
||||||
from .command import Command
|
from .command import Command
|
||||||
from .config import request_config as configs
|
from .config import request_config as configs
|
||||||
from .kinds import KindMapClass
|
from .kinds import KindMapClass
|
||||||
from .kinds import request_kind_map as kindmap
|
from .kinds import request_kind_map as kindmap
|
||||||
from .strip import request_strip_obj as strip
|
from .strip import request_strip_obj as strip
|
||||||
|
from .vbancmd import VbanCmd
|
||||||
|
|
||||||
|
|
||||||
class FactoryBuilder:
|
class FactoryBuilder:
|
||||||
@ -19,6 +20,7 @@ class FactoryBuilder:
|
|||||||
Separates construction from representation.
|
Separates construction from representation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
logger = logging.getLogger("vbancmd.factorybuilder")
|
||||||
BuilderProgress = IntEnum("BuilderProgress", "strip bus command", start=0)
|
BuilderProgress = IntEnum("BuilderProgress", "strip bus command", start=0)
|
||||||
|
|
||||||
def __init__(self, factory, kind: KindMapClass):
|
def __init__(self, factory, kind: KindMapClass):
|
||||||
@ -33,7 +35,7 @@ class FactoryBuilder:
|
|||||||
def _pinfo(self, name: str) -> NoReturn:
|
def _pinfo(self, name: str) -> NoReturn:
|
||||||
"""prints progress status for each step"""
|
"""prints progress status for each step"""
|
||||||
name = name.split("_")[1]
|
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):
|
def make_strip(self):
|
||||||
self._factory.strip = tuple(
|
self._factory.strip = tuple(
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class Subject:
|
class Subject:
|
||||||
"""Adds support for observers"""
|
"""Adds support for observers"""
|
||||||
|
|
||||||
|
logger = logging.getLogger("subject.subject")
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""list of current observers"""
|
"""list of current observers"""
|
||||||
|
|
||||||
@ -22,16 +27,26 @@ class Subject:
|
|||||||
|
|
||||||
if observer not in self._observers:
|
if observer not in self._observers:
|
||||||
self._observers.append(observer)
|
self._observers.append(observer)
|
||||||
|
self.logger.info(f"{type(observer).__name__} added to event observers")
|
||||||
else:
|
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):
|
def remove(self, observer):
|
||||||
"""removes an observer from _observers"""
|
"""removes an observer from _observers"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._observers.remove(observer)
|
self._observers.remove(observer)
|
||||||
|
self.logger.info(f"{type(observer).__name__} removed from event observers")
|
||||||
except ValueError:
|
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):
|
def clear(self):
|
||||||
"""clears the _observers list"""
|
"""clears the _observers list"""
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
@ -21,6 +22,7 @@ class VbanCmd(metaclass=ABCMeta):
|
|||||||
1000000, 1500000, 2000000, 3000000,
|
1000000, 1500000, 2000000, 3000000,
|
||||||
]
|
]
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
logger = logging.getLogger("vbancmd.vbancmd")
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
for attr, val in kwargs.items():
|
for attr, val in kwargs.items():
|
||||||
@ -57,6 +59,8 @@ class VbanCmd(metaclass=ABCMeta):
|
|||||||
self.updater = Updater(self)
|
self.updater = Updater(self)
|
||||||
self.updater.start()
|
self.updater.start()
|
||||||
|
|
||||||
|
self.logger.info(f"{type(self).__name__}: Successfully logged into {self}")
|
||||||
|
|
||||||
def _set_rt(
|
def _set_rt(
|
||||||
self,
|
self,
|
||||||
id_: str,
|
id_: str,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
import socket
|
import socket
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
@ -39,6 +40,8 @@ class Updater(threading.Thread):
|
|||||||
notifies observers of event updates
|
notifies observers of event updates
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
logger = logging.getLogger("worker.updater")
|
||||||
|
|
||||||
def __init__(self, remote):
|
def __init__(self, remote):
|
||||||
super().__init__(name="updater", target=self.update, daemon=True)
|
super().__init__(name="updater", target=self.update, daemon=True)
|
||||||
self._remote = remote
|
self._remote = remote
|
||||||
@ -98,7 +101,7 @@ class Updater(threading.Thread):
|
|||||||
return fget()
|
return fget()
|
||||||
|
|
||||||
def update(self):
|
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["strip_level"],
|
||||||
self._remote.cache["bus_level"],
|
self._remote.cache["bus_level"],
|
||||||
|
Loading…
Reference in New Issue
Block a user