diff options
author | Jon Bernard <jbernard@tuxion.com> | 2016-01-17 06:24:53 -0500 |
---|---|---|
committer | Jon Bernard <jbernard@tuxion.com> | 2016-01-17 06:48:44 -0500 |
commit | e570a42cb65d2f3c83c3beaf3c7fd6a07338a9fa (patch) | |
tree | 1b7a0bbec68ada4920950d9ac44f8ea0cfc09036 | |
parent | 8a1581d48702d0a096aa314043dcfd3098f64a93 (diff) | |
download | dotfiles-e570a42cb65d2f3c83c3beaf3c7fd6a07338a9fa.tar.gz dotfiles-e570a42cb65d2f3c83c3beaf3c7fd6a07338a9fa.tar.bz2 dotfiles-e570a42cb65d2f3c83c3beaf3c7fd6a07338a9fa.zip |
Various cleanups
-rw-r--r-- | dotfiles/cli.py | 47 | ||||
-rw-r--r-- | dotfiles/repository.py | 30 |
2 files changed, 37 insertions, 40 deletions
diff --git a/dotfiles/cli.py b/dotfiles/cli.py index b2b68a7..d124c0b 100644 --- a/dotfiles/cli.py +++ b/dotfiles/cli.py @@ -6,10 +6,7 @@ from .repository import Repository from .exceptions import DotfileException -DEFAULT_HOMEDIR = os.path.expanduser('~/') DEFAULT_REPO_PATH = os.path.expanduser('~/Dotfiles') -DEFAULT_REPO_IGNORE = ['.git'] - pass_repo = click.make_pass_decorator(Repository) @@ -33,9 +30,7 @@ def cli(ctx, repository): """Dotfiles is a tool to make managing your dotfile symlinks in $HOME easy, allowing you to keep all your dotfiles in a single directory. """ - ctx.obj = Repository(py.path.local(repository), - py.path.local(DEFAULT_HOMEDIR), - DEFAULT_REPO_IGNORE) + ctx.obj = Repository(py.path.local(repository)) @cli.command() @@ -59,6 +54,26 @@ def remove(repo, debug, files): @cli.command() +@click.option('-v', '--verbose', is_flag=True, help='Show executed commands.') +@click.argument('files', nargs=-1, type=click.Path()) +@pass_repo +def link(repo, verbose, files): + """Create missing symlinks.""" + # TODO: no files should be interpreted as all files + raise RuntimeError('Not implemented yet') + + +@cli.command() +@click.option('-v', '--verbose', is_flag=True, help='Show executed commands.') +@click.argument('files', nargs=-1, type=click.Path(exists=True)) +@pass_repo +def unlink(repo, verbose, files): + """Remove existing symlinks.""" + # TODO: no files should be interpreted as all files with confirmation + raise RuntimeError('Not implemented yet') + + +@cli.command() @click.option('-a', '--all', is_flag=True, help='Show all dotfiles.') @click.option('-c', '--color', is_flag=True, help='Enable color output.') @pass_repo @@ -86,23 +101,3 @@ def status(repo, all, color): click.secho('%c %s' % (char, name), fg=color) except KeyError: continue - - -@cli.command() -@click.option('-v', '--verbose', is_flag=True, help='Show executed commands.') -@click.argument('files', nargs=-1, type=click.Path()) -@pass_repo -def link(repo, verbose, files): - """Create missing symlinks.""" - # TODO: no files should be interpreted as all files - raise RuntimeError('Not implemented yet') - - -@cli.command() -@click.option('-v', '--verbose', is_flag=True, help='Show executed commands.') -@click.argument('files', nargs=-1, type=click.Path(exists=True)) -@pass_repo -def unlink(repo, verbose, files): - """Remove existing symlinks.""" - # TODO: no files should be interpreted as all files with confirmation - raise RuntimeError('Not implemented yet') diff --git a/dotfiles/repository.py b/dotfiles/repository.py index 3444388..a672a52 100644 --- a/dotfiles/repository.py +++ b/dotfiles/repository.py @@ -15,16 +15,18 @@ class Repository(object): :param ignore: a list of targets to ignore """ - def __init__(self, repodir, homedir, ignore=[]): - self.ignore = ignore - self.homedir = homedir + homedir = py.path.local('~/', expanduser=True) + ignore = ['.git', '.hg'] - # create repository if needed + def __init__(self, repodir, homedir=homedir, ignore=ignore): self.repodir = repodir.ensure(dir=1) + self.homedir = homedir + self.ignore = ignore def __str__(self): """Return human-readable repository contents.""" - return ''.join('%s\n' % item for item in self.contents()).rstrip() + return ''.join('%s\n' % item.short_name(self.homedir) + for item in self.contents()).rstrip() def __repr__(self): return '<Repository %r>' % self.repodir @@ -37,7 +39,7 @@ class Repository(object): """Return the expected repository target for the given symlink.""" return self.repodir.join(self.homedir.bestrelpath(name)) - def dotfile(self, name): + def _dotfile(self, name): """Return a valid dotfile for the given path.""" # XXX: it must be below the home directory @@ -45,6 +47,13 @@ class Repository(object): # it cannot be ignored # it must be a file + # 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) + target = self._name_to_target(name) if target.basename in self.ignore: raise TargetIgnored(name) @@ -59,13 +68,6 @@ 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 name.basename[0] != '.': - # raise NotADotfile(name) - return Dotfile(name, target) def dotfiles(self, paths): @@ -74,7 +76,7 @@ class Repository(object): paths = map(py.path.local, paths) for path in paths: try: - dotfiles.append(self.dotfile(path)) + dotfiles.append(self._dotfile(path)) except DotfileException as err: echo(err) return dotfiles |