aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-11 12:20:18 -0500
committerGravatar Jon Bernard <jbernard@tuxion.com> 2016-01-11 12:20:18 -0500
commit3a8a5714337d54ca239a3add4dd663b9b05ba3af (patch)
tree8716e8a94fcafbaea294fb767966844d6ded1bf7
parent0366d9ee47a742613c13998e0f4621bd32c8f681 (diff)
downloaddotfiles-3a8a5714337d54ca239a3add4dd663b9b05ba3af.tar.gz
dotfiles-3a8a5714337d54ca239a3add4dd663b9b05ba3af.tar.bz2
dotfiles-3a8a5714337d54ca239a3add4dd663b9b05ba3af.zip
Add custom exceptions for dotfile validation
-rw-r--r--dotfiles.py47
1 files changed, 40 insertions, 7 deletions
diff --git a/dotfiles.py b/dotfiles.py
index 3641ecd..7bae516 100644
--- a/dotfiles.py
+++ b/dotfiles.py
@@ -28,6 +28,41 @@ class TargetIgnored(DotfileException):
DotfileException.__init__(self, message)
+class IsDirectory(DotfileException):
+
+ def __init__(self, path):
+ message = '%s is a directory' % path.basename
+ DotfileException.__init__(self, message)
+
+
+class InRepository(DotfileException):
+
+ def __init__(self, path):
+ message = '%s is within the repository' % path.basename
+ DotfileException.__init__(self, message)
+
+
+class NotRootedInHome(DotfileException):
+
+ def __init__(self, path):
+ message = '%s is not rooted in the home directory' % path.basename
+ DotfileException.__init__(self, message)
+
+
+class IsNested(DotfileException):
+
+ def __init__(self, path):
+ message = '%s is nested' % path.basename
+ DotfileException.__init__(self, message)
+
+
+class NotADotfile(DotfileException):
+
+ def __init__(self, path):
+ message = '%s is not a dotfile' % path.basename
+ DotfileException.__init__(self, message)
+
+
class Repository(object):
"""A repository is a directory that contains dotfiles.
@@ -66,26 +101,24 @@ class Repository(object):
raise TargetIgnored(name)
if name.check(dir=1):
- raise Exception('%s is a directory' % name.basename)
+ raise IsDirectory(name)
for path in name.parts():
try:
if self.repodir.samefile(path):
- raise Exception('%s is within the repository' %
- name.basename)
+ raise InRepository(name)
except py.error.ENOENT:
# this occurs when the symlink does not yet exist
continue
if not self.homedir.samefile(name.dirname):
- raise Exception('%s is not rooted in the home directory' %
- name.basename)
+ raise NotRootedInHome(name)
if name.dirname != self.homedir:
- raise Exception('%s is nested' % name.basename)
+ raise IsNested(name)
if name.basename[0] != '.':
- raise Exception('%s is not a dotfile' % name.basename)
+ raise NotADotfile(name)
return Dotfile(name, target)