aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-13 17:37:30 -0500
committerGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-13 17:37:30 -0500
commit9e5cf5dae98f803c3e5850236cf1d48cc540d598 (patch)
treefbd9df2da842327db09b11a283c078ef03da667d
parentf0a93685da8be0187039afc0589bba1caf74df62 (diff)
downloaddotfiles-9e5cf5dae98f803c3e5850236cf1d48cc540d598.tar.gz
dotfiles-9e5cf5dae98f803c3e5850236cf1d48cc540d598.tar.bz2
dotfiles-9e5cf5dae98f803c3e5850236cf1d48cc540d598.zip
Separate dotfile error checking from action
-rw-r--r--dotfiles.py44
1 files changed, 30 insertions, 14 deletions
diff --git a/dotfiles.py b/dotfiles.py
index 7bae516..a3482e1 100644
--- a/dotfiles.py
+++ b/dotfiles.py
@@ -149,6 +149,30 @@ class Dotfile(object):
def __repr__(self):
return '<Dotfile %r>' % self.name
+ def _add(self, verbose):
+ if verbose:
+ click.echo('MOVE %s -> %s' % (self.name, self.target))
+ self.name.move(self.target)
+ # self._link(verbose)
+ self.link(verbose)
+
+ def _remove(self, verbose):
+ # self._unlink(verbose)
+ self.unlink(verbose)
+ if verbose:
+ click.echo('MOVE %s -> %s' % (self.target, self.name))
+ self.target.move(self.name)
+
+ def _link(self, verbose):
+ if verbose:
+ click.echo('LINK %s -> %s' % (self.name, self.target))
+ self.name.mksymlinkto(self.target, absolute=0)
+
+ def _unlink(self, verbose):
+ if verbose:
+ click.echo('REMOVE %s' % self.name)
+ self.name.remove()
+
@property
def state(self):
if self.target.check(exists=0):
@@ -162,34 +186,28 @@ class Dotfile(object):
return 'conflict'
return 'ok'
+ # TODO: update below exceptions
+
def add(self, verbose=False):
if self.name.check(file=0):
raise Exception('%s is not a file' % self.name.basename)
if self.target.check(exists=1):
raise OSError(errno.EEXIST, self.target)
- if verbose:
- click.echo('MOVE %s -> %s' % (self.name, self.target))
- self.name.move(self.target)
- self.link(verbose)
+ self._add(verbose)
def remove(self, verbose=False):
if not self.name.check(link=1):
raise Exception('%s is not a symlink' % self.name.basename)
if self.target.check(exists=0):
raise OSError(errno.ENOENT, self.target)
- self.unlink(verbose)
- if verbose:
- click.echo('MOVE %s -> %s' % (self.target, self.name))
- self.target.move(self.name)
+ self._remove(verbose)
def link(self, verbose=False):
if self.name.check(exists=1):
raise OSError(errno.EEXIST, self.name)
if self.target.check(exists=0):
raise OSError(errno.ENOENT, self.target)
- if verbose:
- click.echo('LINK %s -> %s' % (self.name, self.target))
- self.name.mksymlinkto(self.target, absolute=0)
+ self._link(verbose)
def unlink(self, verbose=False):
if self.name.check(link=0):
@@ -198,9 +216,7 @@ class Dotfile(object):
raise Exception('%s does not exist' % self.target)
if not self.name.samefile(self.target):
raise Exception('good lord')
- if verbose:
- click.echo('REMOVE %s' % self.name)
- self.name.remove()
+ self._unlink(verbose)
pass_repo = click.make_pass_decorator(Repository)