mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2025-01-18 10:30:48 +00:00
add ability to read conn info from toml
This commit is contained in:
parent
be69d905c4
commit
d57269f147
@ -2,8 +2,14 @@ import logging
|
||||
import socket
|
||||
import time
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import Iterable, Optional, Union
|
||||
|
||||
try:
|
||||
import tomllib
|
||||
except ModuleNotFoundError:
|
||||
import tomli as tomllib
|
||||
|
||||
from .event import Event
|
||||
from .packet import RequestHeader
|
||||
from .subject import Subject
|
||||
@ -27,6 +33,10 @@ class VbanCmd(metaclass=ABCMeta):
|
||||
def __init__(self, **kwargs):
|
||||
for attr, val in kwargs.items():
|
||||
setattr(self, attr, val)
|
||||
if self.ip is None:
|
||||
conn = self._conn_from_toml()
|
||||
for attr, val in conn.items():
|
||||
setattr(self, attr, val)
|
||||
|
||||
self.packet_request = RequestHeader(
|
||||
name=self.streamname,
|
||||
@ -45,6 +55,12 @@ class VbanCmd(metaclass=ABCMeta):
|
||||
"""Ensure subclasses override str magic method"""
|
||||
pass
|
||||
|
||||
def _conn_from_toml(self) -> str:
|
||||
filepath = Path.cwd() / "vban.toml"
|
||||
with open(filepath, "rb") as f:
|
||||
conn = tomllib.load(f)
|
||||
return conn["connection"]
|
||||
|
||||
def __enter__(self):
|
||||
self.login()
|
||||
return self
|
||||
|
Loading…
Reference in New Issue
Block a user