Skip to content

Commit

Permalink
Fight with buildozer errors, but at least compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdanbobrowski committed Sep 4, 2024
1 parent 1130fe6 commit 92a07c5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions blog2epub/common/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@


class Blog2EpubSettings:
def __init__(self):
self.path = os.path.join(str(Path.home()), ".blog2epub")
def __init__(self, path: Optional[str] = None):
if path is None:
path = os.path.join(str(Path.home()), ".blog2epub")
self.path = path
self._prepare_path()
self.fname = os.path.join(self.path, "blog2epub.yml")
self.settings_file = os.path.join(self.path, "blog2epub.yml")
self.data: ConfigurationModel = self._read()

def _prepare_path(self):
Expand All @@ -20,10 +22,10 @@ def _prepare_path(self):

def _read(self) -> ConfigurationModel:
data = ConfigurationModel()
if not os.path.isfile(self.fname):
if not os.path.isfile(self.settings_file):
self.save(data)
else:
with open(self.fname, "rb") as stream:
with open(self.settings_file, "rb") as stream:
data_in_file = yaml.safe_load(stream)
data = ConfigurationModel(**data_in_file)
return data
Expand All @@ -38,5 +40,5 @@ def save(self, data: Optional[ConfigurationModel] = None):
if data is None:
data = self.data
data = self._save_history(data)
with open(self.fname, "w") as outfile:
with open(self.settings_file, "w") as outfile:
yaml.dump(data.model_dump(), outfile, default_flow_style=False)

0 comments on commit 92a07c5

Please sign in to comment.