summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--contrib/dotfilesrc12
-rw-r--r--dotfiles/cli.py40
-rw-r--r--dotfiles/core.py15
3 files changed, 55 insertions, 12 deletions
diff --git a/contrib/dotfilesrc b/contrib/dotfilesrc
new file mode 100644
index 0000000..fe1de3e
--- /dev/null
+++ b/contrib/dotfilesrc
@@ -0,0 +1,12 @@
+[dotfiles]
+repository = ~/Dotfiles
+prefix =
+ignore = [
+ '.metadata',
+ '.git',
+ '.gitignore']
+externals = {
+ '.adobe': '/tmp',
+ '.bzr.log': '/dev/null',
+ '.macromedia': '/tmp',
+ '.uml': '/tmp'}
diff --git a/dotfiles/cli.py b/dotfiles/cli.py
index 910dcdc..fadca25 100644
--- a/dotfiles/cli.py
+++ b/dotfiles/cli.py
@@ -2,6 +2,7 @@
import os
from . import core
+import ConfigParser
from optparse import OptionParser, OptionGroup
@@ -13,23 +14,37 @@ def method_list(object):
def parse_args():
parser = OptionParser(usage="Usage: %prog ACTION [OPTION...] [FILE...]")
+ parser.set_defaults(config=os.path.expanduser("~/.dotfilesrc"))
parser.set_defaults(repo=os.path.expanduser("~/Dotfiles"))
+ parser.set_defaults(prefix='')
+ 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("-R", "--repo", type="string", dest="repo",
help="set repository location (default is ~/Dotfiles)")
action_group = OptionGroup(parser, "Actions")
+
action_group.add_option("-a", "--add", action="store_const", dest="action",
const="add", help="add dotfile(s) to the repository")
+
action_group.add_option("-c", "--check", action="store_const",
dest="action", const="check", help="check dotfiles repository")
+
action_group.add_option("-l", "--list", action="store_const",
dest="action", const="list",
help="list currently managed dotfiles")
+
action_group.add_option("-r", "--remove", action="store_const",
dest="action", const="remove",
help="remove dotfile(s) from the repository")
+
action_group.add_option("-s", "--sync", action="store_const",
dest="action", const="sync", help="update dotfile symlinks")
+
parser.add_option_group(action_group)
(opts, args) = parser.parse_args()
@@ -47,5 +62,28 @@ def parse_args():
def main():
+
(opts, args) = parse_args()
- getattr(core.Dotfiles(location=opts.repo), opts.action)(files=args)
+
+ config_defaults = {
+ 'repository': opts.repo,
+ 'prefix': opts.prefix,
+ 'ignore': opts.ignore,
+ 'externals': opts.externals}
+
+ parser = ConfigParser.SafeConfigParser(config_defaults)
+
+ if opts.config:
+
+ parser.read(opts.config)
+
+ if 'dotfiles' in parser.sections():
+ opts.repo = os.path.expanduser(parser.get('dotfiles', 'repository'))
+ opts.prefix = parser.get('dotfiles', 'prefix')
+ opts.ignore = eval(parser.get('dotfiles', 'ignore'))
+ opts.externals = eval(parser.get('dotfiles', 'externals'))
+
+ getattr(core.Dotfiles(location=opts.repo,
+ prefix=opts.prefix,
+ ignore=opts.ignore,
+ externals=opts.externals), opts.action)(files=args)
diff --git a/dotfiles/core.py b/dotfiles/core.py
index 3a60865..b04892f 100644
--- a/dotfiles/core.py
+++ b/dotfiles/core.py
@@ -47,23 +47,16 @@ class Dotfile(object):
class Dotfiles(object):
- IGNORES = ['.metadata', '.git', '.gitignore']
-
- EXTRAS = {'adobe': '/tmp',
- 'bzr.log': '/dev/null',
- 'macromedia': '/tmp',
- 'uml': '/tmp'}
-
- def __init__(self, location):
+ def __init__(self, location, prefix, ignore, externals):
self.location = location
self.dotfiles = []
contents = [x for x in os.listdir(self.location)
- if x not in Dotfiles.IGNORES]
+ if x not in ignore]
for file in contents:
self.dotfiles.append(Dotfile(file,
os.path.join(self.location, file)))
- for file in self.EXTRAS.keys():
- self.dotfiles.append(Dotfile(file, self.EXTRAS[file]))
+ for file in externals.keys():
+ self.dotfiles.append(Dotfile(file, externals[file]))
def list(self, **kwargs):
for dotfile in sorted(self.dotfiles,