From 92e7a8ead118311086217c983a6747287ec084ff Mon Sep 17 00:00:00 2001 From: Remco Wendt Date: Mon, 24 Oct 2011 00:39:22 +0200 Subject: Added glob style pattern support for the ignore option --- dotfiles/core.py | 9 ++++++++- test_dotfiles.py | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dotfiles/core.py b/dotfiles/core.py index c679039..ae79724 100644 --- a/dotfiles/core.py +++ b/dotfiles/core.py @@ -9,6 +9,7 @@ This module provides the basic functionality of dotfiles. import os import shutil +import fnmatch __version__ = '0.4.2' @@ -83,7 +84,13 @@ class Dotfiles(object): self.dotfiles = list() - for dotfile in list(x for x in os.listdir(self.repo) if x not in self.ignore): + all_repofiles = os.listdir(self.repo) + repofiles_to_symlink = set(all_repofiles) + + for pat in self.ignore: + repofiles_to_symlink.difference_update(fnmatch.filter(all_repofiles, pat)) + + for dotfile in repofiles_to_symlink: self.dotfiles.append(Dotfile(dotfile[len(self.prefix):], os.path.join(self.repo, dotfile), self.home)) diff --git a/test_dotfiles.py b/test_dotfiles.py index d12b5b0..0284ba4 100755 --- a/test_dotfiles.py +++ b/test_dotfiles.py @@ -133,7 +133,7 @@ class DotfilesTestCase(unittest.TestCase): .vimrc -> Dotfiles/vimrc """ - ignore = ['*.swp', '.py?', 'install.sh'] + ignore = ['*.swp', '*.py?', 'install.sh'] all_repo_files = ( ('myscript.py', '.myscript.py'), @@ -162,7 +162,7 @@ class DotfilesTestCase(unittest.TestCase): # exist in the home dir. self.assertEqual( sorted(os.listdir(self.home)), - sorted([f[1] for f in all_dotfiles])) + sorted([f[1] for f in all_dotfiles] + ['Dotfiles'])) for original, symlink in all_dotfiles: original_path = os.path.join(self.repo, original) -- cgit v1.2.3