diff options
author | Viljami Ilola <+@hix.fi> | 2024-04-27 01:29:45 +0300 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-04-27 01:29:45 +0300 |
commit | 7a33e5020f9b1e7cf89bc532e2ddcf681f5bcf9c (patch) | |
tree | 544e868288f05213452dec9b7b789bd1eb208191 /src/sliceitoff/settings | |
parent | a4794437d561a01c8bea12d59502e4cc72acfbea (diff) |
volume control
Diffstat (limited to 'src/sliceitoff/settings')
-rw-r--r-- | src/sliceitoff/settings/settings.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/sliceitoff/settings/settings.py b/src/sliceitoff/settings/settings.py index cf588b7..19cca7d 100644 --- a/src/sliceitoff/settings/settings.py +++ b/src/sliceitoff/settings/settings.py @@ -4,6 +4,7 @@ from pathlib import Path from .static import DEFAULT_SETTINGS class Settings: + """ Handles loading and saving settings from config file""" def __init__(self, filename = None): self.settings=[] if filename: @@ -26,6 +27,7 @@ class Settings: self.settings.append(entry) def validate_line(self, line): + """ Validates and splits config line """ if not line or line[0] == '#': return None data = line.split('=') @@ -34,41 +36,50 @@ class Settings: return data[0], data[1] def get_values(self, option): + """ Gets all values for certain option """ return [x[1] for x in self.settings if x[0]==option] def put_values(self, option, values): + """ Puts multiple values with same option name """ for x in values: self.put_value(option, x) def remove_values(self, option): + """ Removes all values with given option name """ for x in self.settings[:]: if x[0]==option: self.settings.remove(x) def replace_values(self, option, values): + """ After replacement only given values are attached to the option """ self.remove_values(option) self.put_values(option, values) def get_value(self, option): + """ Gets first value of the option """ v = self.get_values(option) if not v: return None - return v + return v[0] def get_value_or_default(self, option): - v = self.get_values(option) + """ Gets first value if found otherwise default """ + v = self.get_value(option) if v: return v return [x[1] for x in DEFAULT_SETTINGS if x[0]==option][1] def put_value(self, option, value): + """ Puts single value with option name """ self.settings.append((option, value)) def replace_value(self, option, value): + """ Replaces even multiple values from option just to add one """ self.remove_values(option) self.put_value(option, value) def save(self): + """ Saves options to config file """ with open(self.config_filename, 'w', encoding="utf-8") as config_file: for option, value in self.settings: config_file.write(f"{option}={value}\n") |