From 201bec5135f885c3ca93585c9dcbb69f22007694 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Mon, 22 Dec 2014 07:49:05 -0500 Subject: Add no_dot_prefix option This utility can easily be used for synchronizing arbitrary configuration folders with symlinks that may not necessarily be the home directory. I have encountered several use cases where the files that I want to manage with 'dotfiles' should not/can not be prefixed with a '.'. Fixes #47 --- dotfiles/cli.py | 5 +++++ dotfiles/core.py | 4 +++- tests/test_basic.py | 21 ++++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dotfiles/cli.py b/dotfiles/cli.py index 285f002..89966cc 100644 --- a/dotfiles/cli.py +++ b/dotfiles/cli.py @@ -89,6 +89,10 @@ def add_global_flags(parser): action="store_true", default=False, help="don't modify anything, just print commands") + parser.add_option("-n", "--no-dot-prefix", + action="store_true", default=False, + help="don't prefix symlinks in target directory with a '.'") + def add_action_group(parser): action_group = OptionGroup(parser, "Actions") @@ -237,6 +241,7 @@ def main(): repo_config_opts.get('prefix') or config_opts.get('prefix') or repo_settings['prefix']) + repo_settings['no_dot_prefix'] = cli_opts.no_dot_prefix update_settings(repo_config_opts, 'ignore') update_settings(repo_config_opts, 'externals') diff --git a/dotfiles/core.py b/dotfiles/core.py index 84b383e..42ae5bc 100644 --- a/dotfiles/core.py +++ b/dotfiles/core.py @@ -110,6 +110,7 @@ class Dotfiles(object): 'ignore': set(['.dotfilesrc']), 'homedir': os.path.expanduser('~/'), 'path': os.path.expanduser('~/Dotfiles'), + 'no_dot_prefix': False } def __init__(self, **kwargs): @@ -156,9 +157,10 @@ class Dotfiles(object): if pkg_path in self.packages: self._load_recursive(pkg_path) else: + add_dot = False if self.no_dot_prefix else not bool(sub_dir) self.dotfiles.append(Dotfile(dotfile[len(self.prefix):], os.path.join(src_dir, dotfile), dst_dir, - add_dot=not bool(sub_dir), dry_run=self.dry_run)) + add_dot=add_dot, dry_run=self.dry_run)) # Externals are top-level only if not sub_dir: diff --git a/tests/test_basic.py b/tests/test_basic.py index 07646af..41d1c0e 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -266,7 +266,6 @@ class DotfilesTestCase(unittest.TestCase): dotfiles.add([os.path.join(self.homedir, package_file)]) - def test_single_sync(self): """ Test syncing a single file in the repo @@ -361,6 +360,26 @@ class DotfilesTestCase(unittest.TestCase): dotfiles.add(['.config']) self.assertFalse(os.path.islink(os.path.join(self.homedir, '.config'))) + def test_no_dot_prefix(self): + # define the repository contents + repo_files = ('bashrc', 'netrc', 'vimrc') + + # populate the repository + for dotfile in repo_files: + touch(os.path.join(self.repository, dotfile)) + + dotfiles = Dotfiles( + homedir=self.homedir, path=self.repository, + prefix='', ignore=[], externals={}, packages=[], + dry_run=False, no_dot_prefix=True) + + dotfiles.sync() + + # verify home directory contents + for dotfile in repo_files: + self.assertPathEqual( + os.path.join(self.repository, dotfile), + os.path.join(self.homedir, dotfile)) @pytest.mark.xfail() def test_add_package_file(self): -- cgit v1.2.3