From e64ac4043d6a6d0b4d3921a88e6aa2c53436da29 Mon Sep 17 00:00:00 2001 From: Remco Wendt Date: Sun, 23 Oct 2011 22:55:34 +0200 Subject: Fixed unit tests for use on mac, since /tmp is a symlink to /private/tmp --- test_dotfiles.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test_dotfiles.py b/test_dotfiles.py index bb54578..f82f3ae 100755 --- a/test_dotfiles.py +++ b/test_dotfiles.py @@ -49,7 +49,8 @@ class DotfilesTestCase(unittest.TestCase): dotfiles.sync(force=True) self.assertEqual( - os.path.realpath(os.path.join(self.home, '.lastpass')), '/tmp') + os.path.realpath(os.path.join(self.home, '.lastpass')), + os.path.realpath('/tmp')) def test_move_repository(self): """Test the move() method for a Dotfiles repository.""" @@ -65,7 +66,7 @@ class DotfilesTestCase(unittest.TestCase): # Make sure sync() did the right thing. self.assertEqual( os.path.realpath(os.path.join(self.home, '.bashrc')), - os.path.join(self.repo, 'bashrc')) + os.path.realpath(os.path.join(self.repo, 'bashrc'))) target = os.path.join(self.home, 'MyDotfiles') @@ -74,7 +75,7 @@ class DotfilesTestCase(unittest.TestCase): self.assertTrue(os.path.exists(os.path.join(target, 'bashrc'))) self.assertEqual( os.path.realpath(os.path.join(self.home, '.bashrc')), - os.path.join(target, 'bashrc')) + os.path.realpath(os.path.join(target, 'bashrc'))) def test_sync_unmanaged_directory_symlink(self): """Test a forced sync on a directory symlink. @@ -98,7 +99,7 @@ class DotfilesTestCase(unittest.TestCase): # Make sure the symlink points to the correct location. self.assertEqual( os.path.realpath(os.path.join(self.home, '.vim')), - os.path.join(self.home, 'vim')) + os.path.realpath(os.path.join(self.home, 'vim'))) dotfiles = core.Dotfiles( home=self.home, repo=self.repo, prefix='', @@ -109,7 +110,7 @@ class DotfilesTestCase(unittest.TestCase): # The symlink should now point to the directory in the repository. self.assertEqual( os.path.realpath(os.path.join(self.home, '.vim')), - os.path.join(self.repo, 'vim')) + os.path.realpath(os.path.join(self.repo, 'vim'))) def suite(): -- cgit v1.2.3 From 3afcd23254661162f6ae12ff4ef82ef26d533065 Mon Sep 17 00:00:00 2001 From: Remco Wendt Date: Sun, 23 Oct 2011 23:00:07 +0200 Subject: Made import relative --- dotfiles/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotfiles/__init__.py b/dotfiles/__init__.py index fcb882b..63e0d2b 100644 --- a/dotfiles/__init__.py +++ b/dotfiles/__init__.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -from core import * +from .core import * -- cgit v1.2.3 From fe9996bf08c93d9b22fbed3b70c2fe19e670a8fd Mon Sep 17 00:00:00 2001 From: Remco Wendt Date: Sun, 23 Oct 2011 23:05:56 +0200 Subject: PEP8ified some code --- dotfiles/core.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/dotfiles/core.py b/dotfiles/core.py index f3241c9..c679039 100644 --- a/dotfiles/core.py +++ b/dotfiles/core.py @@ -78,7 +78,6 @@ class Dotfiles(object): self._load() - def _load(self): """Load each dotfile in the repository.""" @@ -91,14 +90,12 @@ class Dotfiles(object): for dotfile in self.externals.keys(): self.dotfiles.append(Dotfile(dotfile, self.externals[dotfile], self.home)) - def _fqpn(self, dotfile): """Return the fully qualified path to a dotfile.""" return os.path.join(self.repo, self.prefix + os.path.basename(dotfile).strip('.')) - def list(self, verbose=True): """List the contents of this repository.""" @@ -106,13 +103,11 @@ class Dotfiles(object): if dotfile.status or verbose: print dotfile - def check(self): """List only unmanaged and/or missing dotfiles.""" self.list(verbose=False) - def sync(self, force=False): """Synchronize this repository, creating and updating the necessary @@ -121,19 +116,16 @@ class Dotfiles(object): for dotfile in self.dotfiles: dotfile.sync(force) - def add(self, files): """Add dotfile(s) to the repository.""" self._perform_action('add', files) - def remove(self, files): """Remove dotfile(s) from the repository.""" self._perform_action('remove', files) - def _perform_action(self, action, files): for file in files: if os.path.basename(file).startswith('.'): @@ -141,7 +133,6 @@ class Dotfiles(object): else: print "Skipping \"%s\", not a dotfile" % file - def move(self, target): """Move the repository to another location.""" -- cgit v1.2.3 From 1c9d0a6641863de75e6c218882dfcdce051c1471 Mon Sep 17 00:00:00 2001 From: Remco Wendt Date: Sun, 23 Oct 2011 23:53:09 +0200 Subject: Added unit test for glob pattern, which fail horribly yay! --- test_dotfiles.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test_dotfiles.py b/test_dotfiles.py index f82f3ae..d12b5b0 100755 --- a/test_dotfiles.py +++ b/test_dotfiles.py @@ -112,6 +112,66 @@ class DotfilesTestCase(unittest.TestCase): os.path.realpath(os.path.join(self.home, '.vim')), os.path.realpath(os.path.join(self.repo, 'vim'))) + def test_glob_ignore_pattern(self): + """ Test that the use of glob pattern matching works in the ignores list. + + The following repo dir exists: + + myscript.py + myscript.pyc + myscript.pyo + bashrc + bashrc.swp + vimrc + vimrc.swp + install.sh + + Using the glob pattern dotfiles should have the following sync result in home: + + .myscript.py -> Dotfiles/myscript.py + .bashrc -> Dotfiles/bashrc + .vimrc -> Dotfiles/vimrc + + """ + ignore = ['*.swp', '.py?', 'install.sh'] + + all_repo_files = ( + ('myscript.py', '.myscript.py'), + ('myscript.pyc', None), + ('myscript.pyo', None), + ('bashrc', '.bashrc'), + ('bashrc.swp', None), + ('vimrc', '.vimrc'), + ('vimrc.swp', None), + ('install.sh', None) + ) + + all_dotfiles = [f for f in all_repo_files if f[1] is not None] + + for original, symlink in all_repo_files: + touch(os.path.join(self.repo, original)) + + dotfiles = core.Dotfiles( + home=self.home, repo=self.repo, prefix='', + ignore=ignore, externals={}) + + dotfiles.sync() + + # Now check that the files that should have a symlink + # point to the correct file and are the only files that + # exist in the home dir. + self.assertEqual( + sorted(os.listdir(self.home)), + sorted([f[1] for f in all_dotfiles])) + + for original, symlink in all_dotfiles: + original_path = os.path.join(self.repo, original) + symlink_path = os.path.join(self.home, symlink) + + self.assertEqual( + os.path.realpath(original_path), + os.path.realpath(symlink_path)) + def suite(): suite = unittest.TestLoader().loadTestsFromTestCase(DotfilesTestCase) -- cgit v1.2.3 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 From 4fb4c7999ffaed3bd9bbc2587d17bcfd5504987c Mon Sep 17 00:00:00 2001 From: Remco Wendt Date: Mon, 24 Oct 2011 00:45:21 +0200 Subject: Added myself to authors --- AUTHORS.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index 4bdcc0b..a183cc8 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -10,3 +10,4 @@ Patches and Suggestions ``````````````````````` - Anaƫl Beutot +- Remco Wendt -- cgit v1.2.3 From b473ca7e58a618bcf09417914c036e21ae4ce3f8 Mon Sep 17 00:00:00 2001 From: Remco Wendt Date: Mon, 24 Oct 2011 00:45:32 +0200 Subject: Updated documentation to include glob option for ignore --- README.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index d717ff9..1c39637 100644 --- a/README.rst +++ b/README.rst @@ -81,7 +81,8 @@ example configuration file might look like: :: repository = ~/Dotfiles ignore = [ '.git', - '.gitignore'] + '.gitignore', + '*.swp'] externals = { '.bzr.log': '/dev/null', '.uml': '/tmp'} @@ -124,9 +125,11 @@ I have the following in my ``~/.dotfilesrc``: :: [dotfiles] ignore = [ '.git', - '.gitignore'] + '.gitignore', + '*.swp] -Any file you list in ``ignore`` will be skipped. +Any file you list in ``ignore`` will be skipped. The ``ignore`` option supports +glob file patterns. License ------- -- cgit v1.2.3 From 43372591599c05f59370b67fb5104f9a483038be Mon Sep 17 00:00:00 2001 From: Remco Wendt Date: Mon, 24 Oct 2011 00:59:57 +0200 Subject: Refactored tests to use an assertPathEquals --- test_dotfiles.py | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/test_dotfiles.py b/test_dotfiles.py index 0284ba4..f9d6fcf 100755 --- a/test_dotfiles.py +++ b/test_dotfiles.py @@ -30,6 +30,11 @@ class DotfilesTestCase(unittest.TestCase): shutil.rmtree(self.home) + def assertPathEqual(self, path1, path2): + self.assertEqual( + os.path.realpath(path1), + os.path.realpath(path2)) + def test_force_sync_directory(self): """Test forced sync when the dotfile is a directory. @@ -48,9 +53,9 @@ class DotfilesTestCase(unittest.TestCase): dotfiles.sync(force=True) - self.assertEqual( - os.path.realpath(os.path.join(self.home, '.lastpass')), - os.path.realpath('/tmp')) + self.assertPathEqual( + os.path.join(self.home, '.lastpass'), + '/tmp') def test_move_repository(self): """Test the move() method for a Dotfiles repository.""" @@ -64,18 +69,18 @@ class DotfilesTestCase(unittest.TestCase): dotfiles.sync() # Make sure sync() did the right thing. - self.assertEqual( - os.path.realpath(os.path.join(self.home, '.bashrc')), - os.path.realpath(os.path.join(self.repo, 'bashrc'))) + self.assertPathEqual( + os.path.join(self.home, '.bashrc'), + os.path.join(self.repo, 'bashrc')) target = os.path.join(self.home, 'MyDotfiles') dotfiles.move(target) self.assertTrue(os.path.exists(os.path.join(target, 'bashrc'))) - self.assertEqual( - os.path.realpath(os.path.join(self.home, '.bashrc')), - os.path.realpath(os.path.join(target, 'bashrc'))) + self.assertPathEqual( + os.path.join(self.home, '.bashrc'), + os.path.join(target, 'bashrc')) def test_sync_unmanaged_directory_symlink(self): """Test a forced sync on a directory symlink. @@ -97,9 +102,9 @@ class DotfilesTestCase(unittest.TestCase): os.mkdir(os.path.join(self.repo, 'vim')) # Make sure the symlink points to the correct location. - self.assertEqual( - os.path.realpath(os.path.join(self.home, '.vim')), - os.path.realpath(os.path.join(self.home, 'vim'))) + self.assertPathEqual( + os.path.join(self.home, '.vim'), + os.path.join(self.home, 'vim')) dotfiles = core.Dotfiles( home=self.home, repo=self.repo, prefix='', @@ -108,9 +113,9 @@ class DotfilesTestCase(unittest.TestCase): dotfiles.sync(force=True) # The symlink should now point to the directory in the repository. - self.assertEqual( - os.path.realpath(os.path.join(self.home, '.vim')), - os.path.realpath(os.path.join(self.repo, 'vim'))) + self.assertPathEqual( + os.path.join(self.home, '.vim'), + os.path.join(self.repo, 'vim')) def test_glob_ignore_pattern(self): """ Test that the use of glob pattern matching works in the ignores list. @@ -165,13 +170,9 @@ class DotfilesTestCase(unittest.TestCase): sorted([f[1] for f in all_dotfiles] + ['Dotfiles'])) for original, symlink in all_dotfiles: - original_path = os.path.join(self.repo, original) - symlink_path = os.path.join(self.home, symlink) - - self.assertEqual( - os.path.realpath(original_path), - os.path.realpath(symlink_path)) - + self.assertPathEqual( + os.path.join(self.repo, original), + os.path.join(self.home, symlink)) def suite(): suite = unittest.TestLoader().loadTestsFromTestCase(DotfilesTestCase) -- cgit v1.2.3 From 754811cd53319a7107c4f0cca801f64501614ef5 Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Sun, 23 Oct 2011 23:58:48 -0400 Subject: Remove extra whitespace --- dotfiles/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotfiles/core.py b/dotfiles/core.py index ae79724..f0d7db4 100644 --- a/dotfiles/core.py +++ b/dotfiles/core.py @@ -86,7 +86,7 @@ class Dotfiles(object): 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)) -- cgit v1.2.3 From d2d0ffc3cf4cddd9c285aaf41aa45d25eb4c62a4 Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Sun, 23 Oct 2011 23:58:59 -0400 Subject: Fix incorrect AUTHORS url --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 1c39637..7546373 100644 --- a/README.rst +++ b/README.rst @@ -159,4 +159,4 @@ changes to the **develop** branch (or branch off of it), and send a pull request. Make sure you add yourself to AUTHORS_. .. _`the repository`: https://github.com/jbernard/dotfiles -.. _AUTHORS: https://github.com/jbernard/dotfiles/blob/master/AUTHORS +.. _AUTHORS: https://github.com/jbernard/dotfiles/blob/master/AUTHORS.rst -- cgit v1.2.3 From e7d316c530928469f90a55f549c7dba7b7edcfe4 Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Mon, 24 Oct 2011 00:11:42 -0400 Subject: Update history for version 0.4.3 release --- HISTORY.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index 64c4346..e69970c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,11 @@ History ------- +0.4.3 ++++++ + +* Add glob style pattern support for the ignore option + 0.4.2 +++++ -- cgit v1.2.3 From 8a22c0b1514d281b83fdb55a82f328c190562efe Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Mon, 24 Oct 2011 00:12:22 -0400 Subject: Bump version number for version 0.4.3 release --- dotfiles/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotfiles/core.py b/dotfiles/core.py index f0d7db4..60bfc1e 100644 --- a/dotfiles/core.py +++ b/dotfiles/core.py @@ -12,7 +12,7 @@ import shutil import fnmatch -__version__ = '0.4.2' +__version__ = '0.4.3' __author__ = "Jon Bernard" __license__ = "GPL" -- cgit v1.2.3