diff options
author | Jon Bernard <jbernard@tuxion.com> | 2015-12-29 14:56:07 -0500 |
---|---|---|
committer | Jon Bernard <jbernard@tuxion.com> | 2015-12-29 15:01:56 -0500 |
commit | cc1cb610776e0a6b8fbeba56c4d04d6f3126ee30 (patch) | |
tree | bab1a0f4bdd50715e50a2d233c3404a46b2f4ff6 | |
parent | ec2c6493bbe5658c3d463ca9c8ba553beca2ca3e (diff) | |
download | dotfiles-cc1cb610776e0a6b8fbeba56c4d04d6f3126ee30.tar.gz dotfiles-cc1cb610776e0a6b8fbeba56c4d04d6f3126ee30.tar.bz2 dotfiles-cc1cb610776e0a6b8fbeba56c4d04d6f3126ee30.zip |
Add dotfile functions for string representation
-rw-r--r-- | dotfiles/dotfile.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/dotfiles/dotfile.py b/dotfiles/dotfile.py index 68c6a20..0fd117f 100644 --- a/dotfiles/dotfile.py +++ b/dotfiles/dotfile.py @@ -27,6 +27,23 @@ class Dotfile: self.name = name self.target = target + def __repr__(self): + return repr((str(self.name), str(self.target), self.state())) + + def __str__(self): + short_name, short_target = self._truncate_paths() + return '{} -> {} {}'.format(short_name, short_target, self.state()) + + def _truncate_paths(self): + discard = len(str(self.name.common(self.target))) + 1 + return (str(self.name)[discard:], str(self.target)[discard:]) + + def state(self): + return '(unknown)' + + def invalid(self): + return self.state != '(ok)' + def add(self): if self.target.check(exists=1): raise OSError(errno.EEXIST, self.target) |