changeset 98:9ba5c3df5e30

automagically install buildbotcustom
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 13 Jan 2011 11:20:57 -0800
parents b41d58e93b2d
children 34b1d30503fa
files setup.py
diffstat 1 files changed, 39 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Wed Jan 12 15:24:01 2011 -0800
+++ b/setup.py	Thu Jan 13 11:20:57 2011 -0800
@@ -1,5 +1,5 @@
+import os, sys
 from setuptools import setup, find_packages
-import sys, os
 
 version = '0.0'
 
@@ -33,3 +33,41 @@
       create-autobot-project = autobot.template:create_project
       """,
       )
+
+def install_hg(sources):
+    """
+    - sources : dict of hg sources to install: {'package': 'http://hg...'}
+    """
+    try:
+        from subprocess import check_call as call
+    except:
+        from subprocess import call
+
+    # see if you can find site-packages
+    import site
+    site_dir = os.path.abspath(os.path.dirname(site.__file__))
+    site_packages = os.path.join(site_dir, 'site-packages')
+    if not (os.path.exists(site_packages) and os.path.isdir(site_packages)):
+        raise IOError("Cannot find site-packages directory")
+
+    # figure out what you need to install
+    missing = set()
+    for source in sources:
+        try:
+            __import__(source)
+        except ImportError:
+            missing.add(source)
+
+    # install it
+    for source in missing:
+        call(['hg', 'clone', sources[source],
+              os.path.join(site_packages, source)])
+
+### install unpackaged dependencies
+source = {'buildbotcustom': 'http://hg.mozilla.org/build/buildbotcustom'}
+if set(['install', 'develop']).intersection(sys.argv[1:]):
+    try:
+        install_hg(source)
+    except:
+        print 'Please make sure the source is installed:'
+        print source