aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-22 08:53:58 -0500
committerGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-22 08:53:58 -0500
commit252d359d0c937a8ff9801a3079c865b4c7abe448 (patch)
treec29946bb4bd3cae5d015f78a2a840a8cc1a720d3
parente6c935b715ce1fa385e33aa06375796e5e7980db (diff)
downloaddotfiles-252d359d0c937a8ff9801a3079c865b4c7abe448.tar.gz
dotfiles-252d359d0c937a8ff9801a3079c865b4c7abe448.tar.bz2
dotfiles-252d359d0c937a8ff9801a3079c865b4c7abe448.zip
Small refactoring and cleanups
-rw-r--r--dotfiles/cli.py11
-rw-r--r--dotfiles/repository.py22
2 files changed, 16 insertions, 17 deletions
diff --git a/dotfiles/cli.py b/dotfiles/cli.py
index 13a1bad..78f2c89 100644
--- a/dotfiles/cli.py
+++ b/dotfiles/cli.py
@@ -41,9 +41,11 @@ pass_repo = click.make_pass_decorator(Repository)
@click.group(context_settings=dict(help_option_names=['-h', '--help']))
@click.option('-r', '--repo', type=click.Path(), show_default=True,
- default=REPOSITORY_PATH, envvar='DOTFILES_REPO')
-@click.option('--dot/--dot', show_default=True,
- default=PRESERVE_LEADING_DOT, envvar='DOTFILES_DOT')
+ default=REPOSITORY_PATH, envvar='DOTFILES_REPO',
+ help='The repository path')
+@click.option('--dot/--no-dot', show_default=True,
+ default=PRESERVE_LEADING_DOT, envvar='DOTFILES_DOT',
+ help='Preserve the leading dot')
@click.version_option()
@click.pass_context
def cli(ctx, repo, dot):
@@ -57,8 +59,7 @@ def cli(ctx, repo, dot):
DOTFILES_COLOR: Set this to 'True' to enable color output.
DOTFILES_DOT: Set this to 'True' to preserve the leading dot.
"""
- ctx.obj = Repository(path=repo,
- ignore_patterns=IGNORE_PATTERNS,
+ ctx.obj = Repository(repo, ignore_patterns=IGNORE_PATTERNS,
preserve_leading_dot=dot)
diff --git a/dotfiles/repository.py b/dotfiles/repository.py
index b36d77d..cdf2f15 100644
--- a/dotfiles/repository.py
+++ b/dotfiles/repository.py
@@ -11,22 +11,20 @@ class Repository(object):
"""A repository is a directory that contains dotfiles.
:param path: the location of the repository directory
+ :param homedir: the location of the home directory
:param ignore_patterns: a list of glob patterns to ignore
:param preserve_leading_dot: whether to preserve the target's leading dot
- :param home_directory: the location of the home directory
"""
- home_directory = py.path.local('~/', expanduser=True)
+ default_homedir = py.path.local('~/', expanduser=True)
- def __init__(self, path,
- ignore_patterns=[],
- preserve_leading_dot=False,
- home_directory=home_directory):
+ def __init__(self, path, homedir=default_homedir, ignore_patterns=[],
+ preserve_leading_dot=False):
# create repository directory if not found
self.path = py.path.local(path).ensure_dir()
- self.home_directory = home_directory
+ self.homedir = homedir
self.ignore_patterns = ignore_patterns
self.preserve_leading_dot = preserve_leading_dot
@@ -47,13 +45,13 @@ class Repository(object):
"""Return the expected symlink for the given repository target."""
relpath = self.path.bestrelpath(target)
if self.preserve_leading_dot:
- return self.home_directory.join(relpath)
+ return self.homedir.join(relpath)
else:
- return self.home_directory.join('.%s' % relpath)
+ return self.homedir.join('.%s' % relpath)
def _dotfile_target(self, path):
"""Return the expected repository target for the given symlink."""
- relpath = self.home_directory.bestrelpath(path)
+ relpath = self.homedir.bestrelpath(path)
if self.preserve_leading_dot:
return self.path.join(relpath)
else:
@@ -63,7 +61,7 @@ class Repository(object):
"""Return a valid dotfile for the given path."""
target = self._dotfile_target(path)
- if not path.fnmatch('%s/*' % self.home_directory):
+ if not path.fnmatch('%s/*' % self.homedir):
raise NotRootedInHome(path)
if path.fnmatch('%s/*' % self.path):
raise InRepository(path)
@@ -87,7 +85,7 @@ class Repository(object):
return Dotfile(self._dotfile_path(target), target)
contents = self._contents(self.path)
- return sorted(map(construct, contents), key=attrgetter('path'))
+ return sorted(map(construct, contents), key=attrgetter('name'))
def dotfiles(self, paths):
"""Return a collection of dotfiles given a list of paths.