changeset 579:f894bd779943

STUB: python/install_config.py
author Jeff Hammel <k0scist@gmail.com>
date Mon, 20 Jan 2014 19:19:10 -0800
parents c16238544fca
children b563a9c1f2b7
files python/install_config.py
diffstat 1 files changed, 91 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/python/install_config.py	Mon Jan 20 16:35:03 2014 -0800
+++ b/python/install_config.py	Mon Jan 20 19:19:10 2014 -0800
@@ -6,14 +6,21 @@
 curl http://k0s.org/hg/config/raw-file/tip/python/install_config.py | python
 """
 
+# TODO:
+# - dl and get ~/web/sync.ini :
+#   ln -s /home/jhammel/web/sync.ini /home/jhammel/.silvermirror
+# - handle cases where config is autogenerated BUT you still want
+#   to have some base (e.g. .gkrellm2/user_config)
+
+# imports
 import imp
 import optparse
 import os
 import subprocess
 import sys
 
-# config repository
-SRC='http://k0s.org/hg/config'
+# globals
+SRC='http://k0s.org/hg/config' # config repository
 HOME=os.environ['HOME']
 
 ### standalone functions
@@ -70,73 +77,81 @@
         Step.__call__(self)
         self.write_hgrc()
 
-#
-#
+
 #@requires(Command('git'))
 #class GitInstall
 
-### legacy -v
-
-commands = [
-    ['hg', 'init'],
-    ['hg', 'pull', SRC],
-    ['hg', 'update', '-C'],
-    ]
-
-os.chdir(HOME) # go home
-
-execute(*commands)
-
-# make a (correct) .hg/hgrc file for $HOME
-hgrc = """[paths]
-default = http://k0s.org/hg/config
-default-push = ssh://k0s.org/hg/config
-"""
-with file(os.path.join(HOME, '.hg/hgrc', 'w')) as f:
-    f.write(hgrc)
-
-# get the which command
-sys.path.append(os.path.join(HOME, 'python'))
-from which import which
-
-
-# do git stuff
-git = which('git')
-if git:
-    # get virtual env
-    virtualenv_commands = [['git', 'clone', 'https://github.com/pypa/virtualenv.git'],
-                           ['ln', '-s', HOME + '/virtualenv/virtualenv.py', HOME + '/bin/']]
-    execute(*virtualenv_commands)
-
-    # setup git's global ignore, since git is silly about this
-    # and doesn't look for the file in the right place
-    execute(['git', 'config', '--global', 'core.excludesfile', os.path.join(HOME, '.gitignore')])
-
-    # install some python
-    install_develop('smartopen')
-    install_develop('silvermirror') # XXX this won't actually work since python-dev isn't installed; install it first
-
-    postinstall_commands = [ ['ln', '-s', os.path.join(HOME, 'smartopen', 'bin', 'smartopen'), os.path.join(HOME, 'bin', 'smartopen') ],
-                             ['ln', '-s', os.path.join(HOME, 'silvermirror', 'bin', 'silvermirror'), os.path.join(HOME, 'bin', 'silvermirror') ],
-                             ]
-    execute(*postinstall_commands)
-else:
-    print "git not installed"
-
 class UbuntuPackages(Step):
     """ubuntu packages to install"""
 
-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" % ' '.join(PACKAGES)
+    PACKAGES=["mercurial",
+              "unison",
+              "fluxbox",
+              "antiword",
+              "xclip",
+              "graphviz",
+              "python-dev",
+              "python-lxml",
+              "curl",
+              "arandr",
+              "git",
+              "emacs",
+              "irssi"]
+    def __call__(self):
+        print "Ensure the following packages are installed:"
+        print "sudo apt-get install %s" % ' '.join(PACKAGES)
+
+
+### legacy -v-
+
+def legacy():
+    """legacy : TO DEPRECATE!"""
+    commands = [
+        ['hg', 'init'],
+        ['hg', 'pull', SRC],
+        ['hg', 'update', '-C'],
+        ]
+    os.chdir(HOME) # go home
+
+    execute(*commands)
 
-# TODO:
-# - dl and get ~/web/sync.ini :
-#   ln -s /home/jhammel/web/sync.ini /home/jhammel/.silvermirror
-# - handle cases where config is autogenerated BUT you still want
-#   to have some base (e.g. .gkrellm2/user_config)
+    # make a (correct) .hg/hgrc file for $HOME
+    hgrc = """[paths]
+default = http://k0s.org/hg/config
+default-push = ssh://k0s.org/hg/config
+"""
+    with file(os.path.join(HOME, '.hg/hgrc', 'w')) as f:
+        f.write(hgrc)
+
+    # get the which command
+    sys.path.append(os.path.join(HOME, 'python'))
+    from which import which
+
+    # do git stuff
+    git = which('git')
+    if git:
+
+        # get virtual env
+        virtualenv_commands = [['git', 'clone', 'https://github.com/pypa/virtualenv.git'],
+                               ['ln', '-s', HOME + '/virtualenv/virtualenv.py', HOME + '/bin/']]
+        execute(*virtualenv_commands)
+
+        # setup git's global ignore, since git is silly about this
+        # and doesn't look for the file in the right place
+        execute(['git', 'config', '--global', 'core.excludesfile', os.path.join(HOME, '.gitignore')])
+
+        # install some python
+        install_develop('smartopen')
+        install_develop('silvermirror') # XXX this won't actually work since python-dev isn't installed; install it first
+
+        postinstall_commands = [['ln', '-s', os.path.join(HOME, 'smartopen', 'bin', 'smartopen'), os.path.join(HOME, 'bin', 'smartopen') ],
+                                ['ln', '-s', os.path.join(HOME, 'silvermirror', 'bin', 'silvermirror'), os.path.join(HOME, 'bin', 'silvermirror') ],
+                             ]
+        execute(*postinstall_commands)
+    else:
+        print "git not installed"
+
+
 
 def main(args=sys.argv[1:]):
 
@@ -150,14 +165,26 @@
                       dest='debian_packages',
                       action='store_true', default=False,
                       help="display debian packages to install")
+    parser.add_option('-l', '--list', '--list-steps',
+                      dest='list_steps',
+                      action='store_true', default=False,
+                      help="list steps to be run")
     options, args = parser.parse_args()
 
     # plan steps
-    steps = [InitializeRepository]
+    steps = [InitializeRepository, UbuntuPackages]
+    if options.debian_packages:
+        steps = [DebianPackages]
+
+    if options.list_steps:
+        # list steps if specified
+        for step in steps:
+            print step
 
     # execute steps
     for step in steps:
-        pass # TODO
+        instance = step()
+        instance()
 
 if __name__ == '__main__':
     main()