-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract config to separate module.
- Loading branch information
Showing
8 changed files
with
211 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Configuration for pomito.""" | ||
import logging | ||
import os | ||
from configparser import ConfigParser | ||
|
||
logger = logging.getLogger("pomito.config") | ||
|
||
|
||
class Configuration(object): | ||
"""Configuration settings for pomito. | ||
Configuration is read from `config.ini` file in pomito data directory. See | ||
documentation for more details. | ||
""" | ||
|
||
# Set sensible defaults | ||
session_duration = 25 * 60 # Pomodoro session duration | ||
short_break_duration = 5 * 60 | ||
long_break_duration = 15 * 60 | ||
long_break_frequency = 4 # A long break after 4 sessions | ||
ui_plugin = "qtapp" | ||
task_plugin = "nulltask" | ||
|
||
def __init__(self, config_file): | ||
"""Create an instance of pomito configuration.""" | ||
self._config_file = config_file | ||
self._parser = ConfigParser() | ||
|
||
def get_setting(self, plugin): | ||
"""Get setting for a plugin.""" | ||
if self._parser.has_section(plugin): | ||
return self._parser.items(plugin) | ||
return [] | ||
|
||
def load(self): | ||
"""Parse the pomito user configuration file.""" | ||
config_file = self._config_file | ||
if config_file is None or not os.path.isfile(config_file): | ||
logger.info("Config file '{0}' not found. Using defaults.".format(config_file)) | ||
return | ||
|
||
self._parser.read(config_file) | ||
if self._parser.has_section("pomito"): | ||
self.session_duration = self._parser.getint("pomito", "session_duration") * 60 | ||
self.short_break_duration = self._parser.getint("pomito", "short_break_duration") * 60 | ||
self.long_break_duration = self._parser.getint("pomito", "long_break_duration") * 60 | ||
self.long_break_frequency = self._parser.getint("pomito", "long_break_frequency") | ||
|
||
if self._parser.has_section("plugins"): | ||
self.ui_plugin = self._parser.get("plugins", "ui") | ||
self.task_plugin = self._parser.get("plugins", "task") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.