From 4ec7ae423fcc957d3d1ee14faea54afbdc406ded Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Fri, 15 Jan 2016 16:10:00 -0500 Subject: Add initial support for nesting This feature means to replace what was called 'packages'. The old packages implementation was only one subdirectory lower than the home directory and quite limiting in that regard. Even worse, they had to be configured manually in the configuration file and could not be created from the command line. This approach offers any depth the user specifies because the rule is: you can only add files to the repository, not directories. So if a user adds a directory, the effect will be that each file contained in any portion of that directory will be moved into the repository and a symlink created. This completely removes both manual configuration and link ambiguity because there is always only once choice. The repository is used to maintain the directory structure, but only the leaf nodes (files) are symlinked in the home directory. This also makes it easy to store other non-dotfile files in the repository like wallpapers, fonts, music, or whatever. --- dotfiles.py | 21 ++++++++++++++------- test_dotfiles.py | 1 - 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/dotfiles.py b/dotfiles.py index efc4d41..1805e97 100644 --- a/dotfiles.py +++ b/dotfiles.py @@ -115,7 +115,7 @@ class Repository(object): def _name_to_target(self, name): """Return the expected repository target for the given symlink.""" - return self.repodir.join(name.basename[1:]) + return self.repodir.join(self.homedir.bestrelpath(name)[1:]) def dotfile(self, name): """Return a valid dotfile for the given path.""" @@ -134,12 +134,10 @@ class Repository(object): # this occurs when the symlink does not yet exist continue - if not self.homedir.samefile(name.dirname): - raise NotRootedInHome(name) - - if name.dirname != self.homedir: - raise IsNested(name) - + # if not self.homedir.samefile(name.dirname): + # raise NotRootedInHome(name) + # if name.dirname != self.homedir: + # raise IsNested(name) if name.basename[0] != '.': raise NotADotfile(name) @@ -180,7 +178,15 @@ class Dotfile(object): def __repr__(self): return '' % self.name + def _ensure_target_dir(self, verbose): + target_dir = py.path.local(self.target.dirname) + if not target_dir.check(): + if verbose: + click.echo('MKDIR %s' % self.target.dirname) + target_dir.ensure(dir=1) + def _add(self, verbose): + self._ensure_target_dir(verbose) if verbose: click.echo('MOVE %s -> %s' % (self.name, self.target)) self.name.move(self.target) @@ -191,6 +197,7 @@ class Dotfile(object): if verbose: click.echo('MOVE %s -> %s' % (self.target, self.name)) self.target.move(self.name) + # TODO: remove directory if empty def _link(self, verbose): if verbose: diff --git a/test_dotfiles.py b/test_dotfiles.py index 7cfb276..0fd55a6 100644 --- a/test_dotfiles.py +++ b/test_dotfiles.py @@ -71,7 +71,6 @@ class TestRepository(object): assert contents[1].target == target_b assert contents[2].target == target_c - @pytest.mark.xfail(reason='nesting not yet supported') def test_nested_name_to_target(self, repo, home): r = Repository(repo, home) -- cgit v1.2.3