annotate INSTALL.py @ 6:a1e06f4a8076

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