aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@tuxion.com> 2014-07-24 16:35:12 -0400
committerGravatar Jon Bernard <jbernard@tuxion.com> 2014-07-24 16:35:12 -0400
commit16481edc0788a1f9f7cd3038634e308b7dcfbf2f (patch)
treeab534ef34b58cd9aada493582f9b027b4ddde43c
parent4a215801542e28a6c7fdaa2d9e9679ebe911f9fe (diff)
downloaddotfiles-16481edc0788a1f9f7cd3038634e308b7dcfbf2f.tar.gz
dotfiles-16481edc0788a1f9f7cd3038634e308b7dcfbf2f.tar.bz2
dotfiles-16481edc0788a1f9f7cd3038634e308b7dcfbf2f.zip
Clean up kwargs handling in repository constructor
This add a defaults attribute where default values are stored instead of accumulating them in the cli. I think improves readability and is certainly easier to manage.
-rw-r--r--dotfiles/core.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/dotfiles/core.py b/dotfiles/core.py
index e3d4a9b..84b383e 100644
--- a/dotfiles/core.py
+++ b/dotfiles/core.py
@@ -1,12 +1,3 @@
-# -*- coding: utf-8 -*-
-
-"""
-dotfiles.core
-~~~~~~~~~~~~~
-
-This module provides the basic functionality of dotfiles.
-"""
-
import os
import os.path
import shutil
@@ -112,15 +103,28 @@ class Dotfile(object):
class Dotfiles(object):
"""A Dotfiles Repository."""
- __attrs__ = ['homedir', 'repository', 'prefix', 'ignore', 'externals',
- 'packages', 'dry_run']
+ defaults = {
+ 'prefix': '',
+ 'packages': set(),
+ 'externals': dict(),
+ 'ignore': set(['.dotfilesrc']),
+ 'homedir': os.path.expanduser('~/'),
+ 'path': os.path.expanduser('~/Dotfiles'),
+ }
def __init__(self, **kwargs):
- # Map args from kwargs to instance-local variables
- for k, v in kwargs.items():
- if k in self.__attrs__:
- setattr(self, k, v)
+ # merge provided arguments with defaults into configuration
+ configuration = {key: kwargs.get(key, self.defaults[key])
+ for key in self.defaults}
+
+ # map configuration items to instance-local variables
+ for k, v in configuration.items():
+ setattr(self, k, v)
+
+ # FIXME: compatibility shims, remove these
+ self.dry_run = False
+ self.repository = self.path
self._load()