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