Skip to content

Commit

Permalink
Better configuration logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sam210723 committed Feb 28, 2024
1 parent e73c9a2 commit 448a8ab
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions wavebin/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import appdirs
import configparser
from dataclasses import dataclass, asdict, make_dataclass
from dataclasses import dataclass, asdict
import logging
from pathlib import Path
from pprint import pformat

from wavebin import __main__ as main
from wavebin.vendor import Vendor
Expand Down Expand Up @@ -56,7 +57,7 @@ class Configuration():
) / "wavebin.ini"


def load(self, reset: bool = False):
def load(self, reset: bool = False) -> bool:
"""
Load configuration from file
"""
Expand All @@ -80,7 +81,10 @@ def load(self, reset: bool = False):
self.ui.maximised = parser.getboolean('ui', 'maximised')

# Log current configuration
logging.debug(str(config).replace("Configuration(", "Configuration ("))
logging.debug(f"Configuration loaded from \"{self.path.absolute()}\"")
for l in self.print(): logging.debug(l)

return True


def save(self) -> bool:
Expand All @@ -102,11 +106,25 @@ def save(self) -> bool:
try:
with open(str(self.path.absolute()), "w") as fh:
parser.write(fh)

logging.debug(f"Configuration saved to \"{self.path.absolute()}\"")
return True

except OSError as e:
logging.error(e)
logging.error(f"Failed to save configuration file\n{e}")
return False


def print(self) -> list[str]:
"""
Pretty print configuration options
"""

return pformat(
config,
width=1,
sort_dicts=False
).split('\n')


config = Configuration(App(), UI())

0 comments on commit 448a8ab

Please sign in to comment.