Skip to content

Commit

Permalink
Catch up with hamster-lib 0.13 config helper changes
Browse files Browse the repository at this point in the history
``hamster-lib 0.13.0`` changes the interface of the configuration helpers
in a backwards incompatible way. The now unnecessary helper was also removed.

Closes: #182
  • Loading branch information
jtojnar authored and elbenfreund committed Jun 19, 2017
1 parent 709bc6a commit aa55a04
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
15 changes: 8 additions & 7 deletions hamster_gtk/hamster_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
from hamster_lib.helpers import config_helpers
from six import text_type

# [FIXME]
# Remove once hamster-lib has been patched
from hamster_gtk.helpers import get_config_instance
from hamster_gtk.misc import HamsterAboutDialog as AboutDialog
from hamster_gtk.overview import OverviewDialog
from hamster_gtk.preferences import PreferencesDialog
Expand Down Expand Up @@ -139,6 +136,9 @@ def __init__(self):
super(HamsterGTK, self).__init__()
self.set_resource_base_path('/org/projecthamster/hamster-gtk')
self.window = None

self._appdirs = config_helpers.HamsterAppDirs('hamster-gtk')

# Which config backend to use.
self.config_store = 'file'
# Yes this is redundent, but more transparent. And we can worry about
Expand All @@ -162,7 +162,7 @@ def save_config(self, config):
dict: Dictionary of config keys and values.
"""
cp_instance = self._config_to_configparser(config)
config_helpers.write_config_file(cp_instance, 'hamster-gtk', 'hamster-gtk.conf')
config_helpers.write_config_file(cp_instance, self._appdirs, 'hamster-gtk.conf')
self.controller.signal_handler.emit('config-changed')

def _create_actions(self):
Expand Down Expand Up @@ -266,7 +266,7 @@ def _get_default_config(self):
Note: Those defaults are independend of the particular config store.
"""
appdirs = config_helpers.HamsterAppDirs('hamster-gtk')
appdirs = self._appdirs
return {
# Backend
'store': 'sqlalchemy',
Expand Down Expand Up @@ -379,7 +379,7 @@ def _write_config_to_file(self, configparser_instance):
Args:
cp_instance (SafeConfigParser): Instance to be written to file.
"""
config_helpers.write_config_file(configparser_instance, 'hamster-gtk', 'hamster-gtk.conf')
config_helpers.write_config_file(configparser_instance, self._appdirs, 'hamster-gtk.conf')

def _get_config_from_file(self):
"""
Expand All @@ -397,7 +397,8 @@ def get_fallback():
config = self._get_default_config()
return self._config_to_configparser(config)

cp_instance = get_config_instance(get_fallback(), 'hamster-gtk', 'hamster-gtk.conf')
cp_instance = config_helpers.load_config_file(self._appdirs, 'hamster-gtk.conf',
get_fallback())
return self._configparser_to_config(cp_instance)


Expand Down
17 changes: 0 additions & 17 deletions hamster_gtk/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,6 @@ def calendar_date_to_datetime(date):
return datetime.date(int(year), int(month) + 1, int(day))


# [FIXME]
# Remove once hamster-lib is patched
# This should probably be named/limited to: 'read_config_file'.
# The 'fallback' behaviour should live with ``_get_config_from_file``.
def get_config_instance(fallback_config_instance, app_name, file_name):
"""Patched version of ``hamster-lib`` helper function until it get fixed upstream."""
from hamster_lib.helpers import config_helpers
from backports.configparser import SafeConfigParser
config = SafeConfigParser()
path = config_helpers.get_config_path(app_name, file_name)
existing_config = config.read(path)
if not existing_config:
config = config_helpers.write_config_file(fallback_config_instance, app_name,
file_name=file_name)
return config


def decompose_raw_fact_string(text, raw=False):
"""
Try to match a given string with modular regex groups.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

requirements = [
'orderedset',
'hamster-lib',
'hamster-lib >= 0.13.0',
]

setup(
Expand Down

0 comments on commit aa55a04

Please sign in to comment.