# HG changeset patch # User Jeff Hammel # Date 1375637471 25200 # Node ID 705dc5cfd68d7f7b4aabacc9bb1645c822c9961d # Parent a8982ae84a9bcb2a222762755331309b28234843 make this modular diff -r a8982ae84a9b -r 705dc5cfd68d python/install_config.py --- a/python/install_config.py Sun Aug 04 08:55:32 2013 -0700 +++ b/python/install_config.py Sun Aug 04 10:31:11 2013 -0700 @@ -6,23 +6,19 @@ curl http://k0s.org/hg/config/raw-file/tip/python/install_config.py | python """ -SRC='http://k0s.org/hg/config' - import imp +import optparse import os import subprocess import sys +# config repository +SRC='http://k0s.org/hg/config' + # go home HOME=os.environ['HOME'] os.chdir(HOME) -commands = [ # make the home directory a repository - ['hg', 'init'], - ['hg', 'pull', SRC], - ['hg', 'update', '-C'], - ] - def execute(*commands): """execute a series of commands""" for command in commands: @@ -31,6 +27,22 @@ if code: sys.exit(code) +class Step(object): + @classmethod + def check(cls): + """checks if the step may be run""" + def __call__(self): + execute(*self.commands) + +class InitializeRepository(Step): + """make the home directory a repository""" + +commands = [ + ['hg', 'init'], + ['hg', 'pull', SRC], + ['hg', 'update', '-C'], + ] + execute(*commands) @@ -85,6 +97,18 @@ print "git not installed" # - ubuntu packages to install: -PACKAGES="mercurial unison fluxbox antiword xclip graphviz python-dev python-lxml curl arandr git emacs irssi" +PACKAGES=["mercurial", "unison", "fluxbox", "antiword", "xclip", + "graphviz", "python-dev", "python-lxml", "curl", "arandr", + "git", "emacs", "irssi"] print "Ensure the following packages are installed:" -print "sudo apt-get install %s" % PACKAGES +print "sudo apt-get install %s" % ' '.join(PACKAGES) + +def main(args=sys.argv[1:]): + usage = '%prog [options]' + parser = optparse.OptionParser(usage=usage, description=__doc__) + options, args = parser.parse_args() + + steps = [InitializeRepository] + +if __name__ == '__main__': + main()