From 0e4305a62fee77e1b9c692c3d360471f31ae9c3c Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Sat, 2 Jan 2016 23:37:09 -0500 Subject: Remove dotfile-specific operations from repository These are handled in the CLI and there is no need for repository to be involved. --- dotfiles/repository.py | 60 ++++++++------------------------------------------ 1 file changed, 9 insertions(+), 51 deletions(-) diff --git a/dotfiles/repository.py b/dotfiles/repository.py index f394ed1..d9750ef 100644 --- a/dotfiles/repository.py +++ b/dotfiles/repository.py @@ -16,16 +16,6 @@ class Repository(object): Both of the above attributes are received as string objects and converted to py.path.local objects for internal use. - - The repository implements these fundamental operations: - - status -- list the dotfiles (and their state) contained herein - check -- list any dotfiles unsynced or unmanaged that require attention - sync -- create some or all missing dotfile symlinks - unsync -- remove some or all dotfile symlinks - add -- add a dotfile to this repository and create its symlink - remove -- the opposited of add - move -- change the name of this repository and update dependent symlinks """ def __init__(self, repodir, homedir='~'): @@ -33,7 +23,8 @@ class Repository(object): self.homedir = homedir def __str__(self): - return self._contents() or '[no dotfiles found]' + """Convert repository contents to human readable form.""" + return ''.join('%s\n' % item for item in self.contents()).rstrip() def __repr__(self): return '' % self.repodir @@ -54,50 +45,17 @@ class Repository(object): def homedir(self, path): self._homedir = py.path.local(path, expanduser=True) - def _target_to_name(self, target): + def _expected_name(self, target): return py.path.local("%s/.%s" % (self.homedir, target.basename)) - def _load(self): + def contents(self): """Given a repository path, discover all existing dotfiles.""" - dotfiles = [] + contents = [] self._repodir.ensure(dir=1) - targets = self._repodir.listdir() - for target in targets: + for target in self._repodir.listdir(): target = py.path.local(target) - name = self._target_to_name(target) - dotfiles.append(Dotfile(name, target)) - return sorted(dotfiles, key=attrgetter('name')) - - # TODO: pass dotfile objects to CLI instead of string - - def _contents(self, all=True): - """Convert loaded contents to human readable form.""" - contents = '' - dotfiles = self._load() - for dotfile in dotfiles: - if all or not dotfile.is_ok(): - contents += '\n%s' % dotfile - return contents.lstrip() - - def status(self): - """Returns a string list of all dotfiles.""" - return str(self) - - def check(self): - """Returns a string list of only unsynced or missing dotfiles.""" - return self._contents(all=False) - - def sync(self): - raise NotImplementedError - - def unsync(self): - raise NotImplementedError - - def add(self): - raise NotImplementedError - - def remove(self): - raise NotImplementedError + contents.append(Dotfile(self._expected_name(target), target)) + return sorted(contents, key=attrgetter('name')) - def move(self): + def rename(self): raise NotImplementedError -- cgit v1.2.3