From 23d8a721bf84c2b531bca0b9babc6359a7803092 Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Sat, 28 May 2011 19:31:17 -0400 Subject: Add configuration file support --- contrib/dotfilesrc | 12 ++++++++++++ dotfiles/cli.py | 40 +++++++++++++++++++++++++++++++++++++++- dotfiles/core.py | 15 ++++----------- 3 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 contrib/dotfilesrc 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, -- cgit v1.2.3 From 0de25186f02b089b024d47414a82351d03c28350 Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Sat, 4 Jun 2011 19:05:39 -0400 Subject: Update documentation to mention config file syntax --- README.rst | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 6e71871..f8b9f9d 100644 --- a/README.rst +++ b/README.rst @@ -4,10 +4,10 @@ Dotfile management made easy ``dotfiles`` is a tool to make managing your dotfile symlinks in ``$HOME`` easy, allowing you to keep all your dotfiles in a single directory. -Hosting is left to you. Yes, I've seen ``_ and I don't -believe in that model. If you're advanced enough to need dotfile management, -then you probably already know how you want to host them. Using whatever VCS -you prefer, or even rsync, you can easily distribute your dotfiles repository +Hosting is left to you. Yes, I've seen ``_ but I don't +like that model. If you're advanced enough to need dotfile management, then you +probably already know how you want to host them. Using whatever VCS you +prefer, or even rsync, you can easily distribute your dotfiles repository across multiple hosts. Installation @@ -51,6 +51,22 @@ To make it available to all your hosts: :: You get the idea. +Configuration +------------- + +You can choose to create a configuration file to store personal +customizations. By default, ``dotfiles`` will look in ``~/.dotfilesrc``. An +example configuration file might look like: :: + + [dotfiles] + repository = ~/Dotfiles + ignore = [ + '.git', + '.gitignore'] + externals = { + '.bzr.log': '/dev/null', + '.uml': '/tmp'} + License ------- -- cgit v1.2.3