annotate INSTALL.py @ 0:c8c2d98afc98

initial commit (stub)
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 18 Mar 2012 20:37:19 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 installation script for lockedfile
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 locked file implementation
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 """
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 import os
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 import sys
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 import urllib2
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 import subprocess
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 try:
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 from subprocess import check_call as call
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 except:
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 from subprocess import call
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 REPO='http://k0s.org/hg/lockedfile'
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 DEST='lockedfile' # name of the virtualenv
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 VIRTUALENV='https://raw.github.com/pypa/virtualenv/develop/virtualenv.py'
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 def which(binary, path=os.environ['PATH']):
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 dirs = path.split(os.pathsep)
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 for dir in dirs:
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 if os.path.isfile(os.path.join(dir, fileName)):
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 return os.path.join(dir, fileName)
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 if os.path.isfile(os.path.join(dir, fileName + ".exe")):
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 return os.path.join(dir, fileName + ".exe")
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 def main(args=sys.argv[1:]):
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 # create a virtualenv
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 virtualenv = which('virtualenv') or which('virtualenv.py')
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 if virtualenv:
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 call([virtualenv, DEST])
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 else:
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 process = subproces.Popen([sys.executable, '-', DEST], stdin=subprocess.PIPE)
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37 process.communicate(stdin=urllib2.urlopen(VIRTUALENV).read())
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 # create a src directory
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40 src = os.path.join(DEST, 'src')
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 os.mkdir(src)
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 # clone the repository
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 call(['hg', 'clone', REPO], cwd=src)
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 # find the virtualenv python
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47 python = None
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
48 for path in (('bin', 'python'), ('Scripts', 'python.exe')):
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
49 _python = os.path.join(DEST, *path)
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50 if os.path.exists(_python)
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51 python = _python
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
52 break
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
53 else:
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
54 raise Exception("Python binary not found in %s" % DEST)
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
55
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
56 # find the clone
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
57 filename = REPO.rstrip('/')
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
58 filename = filename.split('/')[-1]
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
59 clone = os.path.join(src, filename)
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
60 assert os.path.exists(clone), "Clone directory not found in %s" % src
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
61
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
62 # ensure setup.py exists
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
63 assert os.path.exists(os.path.join(clone, 'setup.py')), 'setup.py not found in %s' % clone
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
64
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
65 # install the package in develop mode
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
66 call([python 'setup.py', 'develop'], cwd=clone)
c8c2d98afc98 initial commit (stub)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
67