refactor(config): update access methods for configuration properties
This commit is contained in:
@@ -100,7 +100,7 @@ def main(argv=None) -> int:
|
||||
elif args.config_command == "get":
|
||||
print(cfg.get(args.key))
|
||||
else:
|
||||
cfg.show()
|
||||
parser.error("Unknown config command: expected 'get' or 'set'")
|
||||
else:
|
||||
parser.error("Unknown command")
|
||||
except Exception as e:
|
||||
|
||||
@@ -16,6 +16,7 @@ class Config:
|
||||
self._config_file = self._config_dir / _CONFIG_NAME
|
||||
self._data = self._load()
|
||||
|
||||
# Private
|
||||
def _load(self) -> dict:
|
||||
if not self._config_file.exists():
|
||||
self._config_dir.mkdir(parents=True, exist_ok=True)
|
||||
@@ -28,57 +29,46 @@ class Config:
|
||||
with self._config_file.open("wb") as f:
|
||||
tomli_w.dump(self._data, f)
|
||||
|
||||
@property
|
||||
def obs_host(self) -> str:
|
||||
# Public
|
||||
def get_obs_host(self) -> str:
|
||||
return self._data["obs"]["host"]
|
||||
|
||||
@obs_host.setter
|
||||
def obs_host(self, value: str) -> None:
|
||||
def set_obs_host(self, value: str) -> None:
|
||||
self._data["obs"]["host"] = value
|
||||
self._save()
|
||||
|
||||
@property
|
||||
def obs_port(self) -> int:
|
||||
def get_obs_port(self) -> int:
|
||||
return self._data["obs"]["port"]
|
||||
|
||||
@obs_port.setter
|
||||
def obs_port(self, value: int) -> None:
|
||||
def set_obs_port(self, value: int) -> None:
|
||||
self._data["obs"]["port"] = value
|
||||
self._save()
|
||||
|
||||
@property
|
||||
def obs_password(self) -> str:
|
||||
def get_obs_password(self) -> str:
|
||||
return self._data["obs"]["password"]
|
||||
|
||||
@obs_password.setter
|
||||
def obs_password(self, value: str) -> None:
|
||||
def set_obs_password(self, value: str) -> None:
|
||||
self._data["obs"]["password"] = value
|
||||
self._save()
|
||||
|
||||
@property
|
||||
def max_record_time(self) -> int:
|
||||
def get_max_record_time(self) -> int:
|
||||
return self._data["record"]["max_record_time"]
|
||||
|
||||
@max_record_time.setter
|
||||
def max_record_time(self, value: int) -> None:
|
||||
def set_max_record_time(self, value: int) -> None:
|
||||
self._data["record"]["max_record_time"] = value
|
||||
self._save()
|
||||
|
||||
@property
|
||||
def clip_output(self) -> str:
|
||||
def get_clip_output(self) -> str:
|
||||
return os.path.expanduser(self._data["record"]["clip_output"])
|
||||
|
||||
@clip_output.setter
|
||||
def clip_output(self, value: str) -> None:
|
||||
def set_clip_output(self, value: str) -> None:
|
||||
self._data["record"]["clip_output"] = value
|
||||
self._save()
|
||||
|
||||
@property
|
||||
def vod_output(self) -> str:
|
||||
def get_vod_output(self) -> str:
|
||||
return os.path.expanduser(self._data["record"]["vod_output"])
|
||||
|
||||
@vod_output.setter
|
||||
def vod_output(self, value: str) -> None:
|
||||
def set_vod_output(self, value: str) -> None:
|
||||
self._data["record"]["vod_output"] = value
|
||||
self._save()
|
||||
|
||||
@@ -97,8 +87,3 @@ class Config:
|
||||
raise KeyError(f"Unknown config key: {key!r}")
|
||||
self._data[section][field] = type(current)(value)
|
||||
self._save()
|
||||
|
||||
def show(self) -> None:
|
||||
for section, values in self._data.items():
|
||||
for field, value in values.items():
|
||||
print(f"{section}.{field} = {value!r}")
|
||||
|
||||
@@ -8,11 +8,13 @@ from rewind.state import load_state, add_marker_to_state, remove_marker_from_sta
|
||||
from rewind.config import Config
|
||||
from tqdm import tqdm
|
||||
|
||||
config = Config()
|
||||
|
||||
def clip(seconds_from_end: float) -> None:
|
||||
if seconds_from_end <= 0 or seconds_from_end > 600:
|
||||
raise ValueError("Clip length must be positive and less than or equal to 10 minutes")
|
||||
|
||||
clip_output = Config().clip_output
|
||||
clip_output = Config().get_clip_output()
|
||||
os.makedirs(clip_output, exist_ok=True)
|
||||
|
||||
output_file_name = f"{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}.mp4"
|
||||
@@ -31,7 +33,7 @@ def clip(seconds_from_end: float) -> None:
|
||||
print(f"Created clip: {output_path}")
|
||||
|
||||
def save(first_marker: str, second_marker: str):
|
||||
vod_dir = Config().vod_output
|
||||
vod_dir = config.get_vod_output()
|
||||
os.makedirs(vod_dir, exist_ok=True)
|
||||
|
||||
first_timestamp = get_marker_timestamp(first_marker)
|
||||
|
||||
@@ -88,7 +88,7 @@ class Handler(FileSystemEventHandler):
|
||||
|
||||
def main() -> None:
|
||||
config = Config()
|
||||
con = open_obs_connection(config.obs_host, config.obs_port, config.obs_password, OBS_MAX_RETRIES)
|
||||
con = open_obs_connection(config.get_obs_host(), config.get_obs_port(), config.get_obs_password(), OBS_MAX_RETRIES)
|
||||
|
||||
recording_dir = con.get_record_directory().record_directory
|
||||
start_recording(con)
|
||||
@@ -103,8 +103,8 @@ def main() -> None:
|
||||
observer.start()
|
||||
|
||||
while running:
|
||||
cleanup_physical_files(recording_dir, config.max_record_time)
|
||||
cleanup_state(config.max_record_time)
|
||||
cleanup_physical_files(recording_dir, config.get_max_record_time())
|
||||
cleanup_state(config.get_max_record_time())
|
||||
time.sleep(INTERVAL)
|
||||
finally:
|
||||
if observer:
|
||||
|
||||
Reference in New Issue
Block a user