From bf6ad3b0b4e7065d1ff1f3f5cdec61cba386813b Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Sat, 27 Aug 2011 10:11:03 -0400 Subject: Make home directory user-definable This paves the way for unit tests to perform operations completely within a sandboxed environment. --- dotfiles/cli.py | 3 +++ dotfiles/core.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dotfiles/cli.py b/dotfiles/cli.py index 2725c06..e9cf19a 100644 --- a/dotfiles/cli.py +++ b/dotfiles/cli.py @@ -43,6 +43,9 @@ def parse_args(): parser.add_option("-C", "--config", type="string", dest="config", help="set configuration file location (default is ~/.dotfilesrc)") + parser.add_option("-H", "--home", type="string", dest="home", + help="set home directory location (default is ~/)") + action_group = OptionGroup(parser, "Actions") action_group.add_option("-a", "--add", action="store_const", dest="action", diff --git a/dotfiles/core.py b/dotfiles/core.py index 5bc472e..22cacb8 100644 --- a/dotfiles/core.py +++ b/dotfiles/core.py @@ -18,11 +18,11 @@ __license__ = "GPL" class Dotfile(object): - def __init__(self, name, target): + def __init__(self, name, target, home): if name.startswith('/'): self.name = name else: - self.name = os.path.expanduser('~/.%s' % name.strip('.')) + self.name = os.path.expanduser(home + '/.%s' % name.strip('.')) self.basename = os.path.basename(self.name) self.target = target.rstrip('/') self.status = '' -- cgit v1.2.3