aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jon Bernard <jbernard@tuxion.com> 2011-06-29 13:41:17 -0400
committerGravatar Jon Bernard <jbernard@tuxion.com> 2011-06-29 13:41:17 -0400
commit4afa72a4cdcde4745c6ff5d5f81f2596088d8a99 (patch)
tree0b1f26dd043277e90ee85c51545cfdf26733da85
parent3b8a0024df391e005e5c4dfd224bda5263e69858 (diff)
downloaddotfiles-4afa72a4cdcde4745c6ff5d5f81f2596088d8a99.tar.gz
dotfiles-4afa72a4cdcde4745c6ff5d5f81f2596088d8a99.tar.bz2
dotfiles-4afa72a4cdcde4745c6ff5d5f81f2596088d8a99.zip
Add an option to override unmanaged files during sync
-rw-r--r--dotfiles/cli.py10
-rw-r--r--dotfiles/core.py15
2 files changed, 18 insertions, 7 deletions
diff --git a/dotfiles/cli.py b/dotfiles/cli.py
index fadca25..2ce55bb 100644
--- a/dotfiles/cli.py
+++ b/dotfiles/cli.py
@@ -20,12 +20,15 @@ def parse_args():
parser.set_defaults(ignore=[])
parser.set_defaults(externals={})
- parser.add_option("-C", "--config", type="string", dest="config",
- help="set configuration file location (default is ~/.dotfilesrc)")
+ parser.add_option("-f", "--force", action="store_true", dest="force",
+ default=False, help="ignore unmanaged dotfiles (use with --sync)")
parser.add_option("-R", "--repo", type="string", dest="repo",
help="set repository location (default is ~/Dotfiles)")
+ parser.add_option("-C", "--config", type="string", dest="config",
+ help="set configuration file location (default is ~/.dotfilesrc)")
+
action_group = OptionGroup(parser, "Actions")
action_group.add_option("-a", "--add", action="store_const", dest="action",
@@ -86,4 +89,5 @@ def main():
getattr(core.Dotfiles(location=opts.repo,
prefix=opts.prefix,
ignore=opts.ignore,
- externals=opts.externals), opts.action)(files=args)
+ externals=opts.externals,
+ force=opts.force), opts.action)(files=args)
diff --git a/dotfiles/core.py b/dotfiles/core.py
index b04892f..3a13fd3 100644
--- a/dotfiles/core.py
+++ b/dotfiles/core.py
@@ -17,11 +17,17 @@ class Dotfile(object):
if not os.path.lexists(self.name):
self.status = 'missing'
elif os.path.realpath(self.name) != self.target:
- self.status = 'unmanged'
+ self.status = 'unmanaged'
- def sync(self):
+ def sync(self, force):
if self.status == 'missing':
os.symlink(self.target, self.name)
+ elif self.status == 'unmanaged':
+ if not force:
+ print "Skipping \"%s\", use --force to override" % self.basename
+ return
+ os.remove(self.name)
+ os.symlink(self.target, self.name)
def add(self):
if self.status == 'missing':
@@ -47,8 +53,9 @@ class Dotfile(object):
class Dotfiles(object):
- def __init__(self, location, prefix, ignore, externals):
+ def __init__(self, location, prefix, ignore, externals, force):
self.location = location
+ self.force = force
self.dotfiles = []
contents = [x for x in os.listdir(self.location)
if x not in ignore]
@@ -69,7 +76,7 @@ class Dotfiles(object):
def sync(self, **kwargs):
for dotfile in self.dotfiles:
- dotfile.sync()
+ dotfile.sync(self.force)
def add(self, **kwargs):
for file in kwargs.get('files', None):