diff options
author | Jon Bernard <jbernard@tuxion.com> | 2016-01-08 07:44:26 -0500 |
---|---|---|
committer | Jon Bernard <jbernard@tuxion.com> | 2016-01-08 07:51:30 -0500 |
commit | 190ee4e82363b3464b0f162681262dccc865dfe6 (patch) | |
tree | a110fc9d253ecd4eb28df0ce8bac5cb9e6df23c9 | |
parent | 7a18aa69c3abe96fb1e919a159145d07aaeb0257 (diff) | |
download | dotfiles-190ee4e82363b3464b0f162681262dccc865dfe6.tar.gz dotfiles-190ee4e82363b3464b0f162681262dccc865dfe6.tar.bz2 dotfiles-190ee4e82363b3464b0f162681262dccc865dfe6.zip |
Add ignore item to skip repository git files
-rw-r--r-- | dotfiles.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/dotfiles.py b/dotfiles.py index cf70da0..e5a81e8 100644 --- a/dotfiles.py +++ b/dotfiles.py @@ -5,8 +5,9 @@ import errno from operator import attrgetter -DEFAULT_HOME = os.path.expanduser('~/') -DEFAULT_REPO = os.path.expanduser('~/Dotfiles') +DEFAULT_HOMEDIR = os.path.expanduser('~/') +DEFAULT_REPO_PATH = os.path.expanduser('~/Dotfiles') +DEFAULT_REPO_IGNORE = ['.git', '.gitignore'] class Repository(object): @@ -14,12 +15,16 @@ class Repository(object): :param repodir: the location of the repository directory :param homedir: the location of the home directory (primarily for testing) + :param ignore: a list of targets to ignore """ - def __init__(self, repodir, homedir): - self.repodir = repodir.ensure(dir=1) + def __init__(self, repodir, homedir, ignore=[]): + self.ignore = ignore self.homedir = homedir + # create repository if needed + self.repodir = repodir.ensure(dir=1) + def __str__(self): """Return human-readable repository contents.""" return ''.join('%s\n' % item for item in self.contents()).rstrip() @@ -64,6 +69,9 @@ class Repository(object): if name.basename[0] != '.': raise Exception('%s is not a dotfile' % name.basename) + if self._name_to_target(name).basename in self.ignore: + raise Exception('%s targets an ignored file' % name.basename) + return Dotfile(name, self._name_to_target(name)) def contents(self): @@ -71,7 +79,8 @@ class Repository(object): contents = [] for target in self.repodir.listdir(): target = py.path.local(target) - contents.append(Dotfile(self._target_to_name(target), target)) + if target.basename not in self.ignore: + contents.append(Dotfile(self._target_to_name(target), target)) return sorted(contents, key=attrgetter('name')) @@ -168,6 +177,7 @@ def cli(ctx, home_directory, repository): """ ctx.obj = Repository(py.path.local(repository), py.path.local(home_directory)) + DEFAULT_REPO_IGNORE) @cli.command() |