diff options
author | Jon Bernard <jbernard@tuxion.com> | 2016-07-18 15:36:41 -0400 |
---|---|---|
committer | Jon Bernard <jbernard@tuxion.com> | 2016-07-18 15:36:41 -0400 |
commit | af991f612a54d347deb5449aec273012c2c059df (patch) | |
tree | 46bfed4f4892c8b8dca82f62e09f4c1bb1e29567 | |
parent | e09398c6ef5af049a28b88690911343ba5238e67 (diff) | |
download | dotfiles-af991f612a54d347deb5449aec273012c2c059df.tar.gz dotfiles-af991f612a54d347deb5449aec273012c2c059df.tar.bz2 dotfiles-af991f612a54d347deb5449aec273012c2c059df.zip |
Reverse leading dot logic
-rw-r--r-- | dotfiles/repository.py | 24 | ||||
-rw-r--r-- | tests/conftest.py | 2 | ||||
-rw-r--r-- | tests/test_repository.py | 10 |
3 files changed, 18 insertions, 18 deletions
diff --git a/dotfiles/repository.py b/dotfiles/repository.py index cdf2f15..836e0b5 100644 --- a/dotfiles/repository.py +++ b/dotfiles/repository.py @@ -13,20 +13,20 @@ class Repository(object): :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 remove_leading_dot: whether to remove the target's leading dot """ - default_homedir = py.path.local('~/', expanduser=True) - - def __init__(self, path, homedir=default_homedir, ignore_patterns=[], - preserve_leading_dot=False): + def __init__(self, path, + remove_leading_dot=DEFAULT_REMOVE_LEADING_DOT, + ignore_patterns=DEFAULT_IGNORE_PATTERNS, + homedir=DEFAULT_HOMEDIR): # create repository directory if not found self.path = py.path.local(path).ensure_dir() self.homedir = homedir self.ignore_patterns = ignore_patterns - self.preserve_leading_dot = preserve_leading_dot + self.remove_leading_dot = remove_leading_dot def __str__(self): """Return human-readable repository contents.""" @@ -44,18 +44,18 @@ class Repository(object): def _dotfile_path(self, target): """Return the expected symlink for the given repository target.""" relpath = self.path.bestrelpath(target) - if self.preserve_leading_dot: - return self.homedir.join(relpath) - else: + if self.remove_leading_dot: return self.homedir.join('.%s' % relpath) + else: + return self.homedir.join(relpath) def _dotfile_target(self, path): """Return the expected repository target for the given symlink.""" relpath = self.homedir.bestrelpath(path) - if self.preserve_leading_dot: - return self.path.join(relpath) - else: + if self.remove_leading_dot: return self.path.join(relpath[1:]) + else: + return self.path.join(relpath) def _dotfile(self, path): """Return a valid dotfile for the given path.""" diff --git a/tests/conftest.py b/tests/conftest.py index f5beb21..9e1d16a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ from dotfiles.repository import Repository def repo(request, tmpdir): path = tmpdir.ensure_dir('repo') home = tmpdir.ensure_dir(request.param) - return Repository(path, home) + return Repository(path, homedir=home) @pytest.fixture(scope='function') diff --git a/tests/test_repository.py b/tests/test_repository.py index 73d5315..58e6cf9 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -25,20 +25,20 @@ def test_str(repo): @pytest.mark.parametrize('path', ['.foo', '.foo/bar/baz']) def test_dotfile_path(repo, path): - repo.preserve_leading_dot = True + repo.remove_leading_dot = False assert (repo._dotfile_path(repo.path.join(path)) == repo.homedir.join(path)) - repo.preserve_leading_dot = False + repo.remove_leading_dot = True assert (repo._dotfile_path(repo.path.join(path)) == repo.homedir.join('.%s' % path)) @pytest.mark.parametrize('path', ['.foo', '.foo/bar/baz']) def test_dotfile_target(repo, path): - repo.preserve_leading_dot = True + repo.remove_leading_dot = False assert (repo._dotfile_target(repo.homedir.join(path)) == repo.path.join(path)) - repo.preserve_leading_dot = False + repo.remove_leading_dot = True assert (repo._dotfile_target(repo.homedir.join(path)) == repo.path.join(path[1:])) @@ -48,7 +48,7 @@ def test_dotfile(repo): repo._dotfile(py.path.local('/tmp/foo')) with pytest.raises(TargetIgnored): repo.ignore_patterns = ['.foo'] - repo.preserve_leading_dot = True + repo.remove_leading_dot = False repo._dotfile(py.path.local(repo.homedir.join('.foo'))) with pytest.raises(TargetIgnored): repo.ignore_patterns = ['foo'] |