changeset 408:705dc5cfd68d

make this modular
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 04 Aug 2013 10:31:11 -0700
parents a8982ae84a9b
children dc64beded724
files python/install_config.py
diffstat 1 files changed, 34 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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()