annotate makeitso/python_package/INSTALL.py @ 142:a203f79c537f

better organization
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 29 Feb 2012 10:59:11 -0800
parents cd51ef9288ea
children 702216c49594
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
133
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
1 #!/usr/bin/env python
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
2
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
3 """
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
4 installation script for {{project}}
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
5 {{description}}
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
6 """
96
cc17537254d2 add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7
133
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
8 import os
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
9 import sys
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
10 import urllib2
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
11 import subprocess
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
12 try:
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
13 from subprocess import check_call as call
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
14 except:
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
15 from subprocess import call
96
cc17537254d2 add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16
cc17537254d2 add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 REPO='{{repo}}'
cc17537254d2 add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 DEST='{{project}}' # name of the virtualenv
133
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
19 VIRTUALENV='https://raw.github.com/pypa/virtualenv/develop/virtualenv.py'
96
cc17537254d2 add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20
133
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
21 def which(binary, path=os.environ['PATH']):
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
22 dirs = path.split(os.pathsep)
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
23 for dir in dirs:
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
24 if os.path.isfile(os.path.join(dir, fileName)):
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
25 return os.path.join(dir, fileName)
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
26 if os.path.isfile(os.path.join(dir, fileName + ".exe")):
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
27 return os.path.join(dir, fileName + ".exe")
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
28
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
29 def main(args=sys.argv[1:]):
96
cc17537254d2 add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30
133
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
31 # create a virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
32 virtualenv = which('virtualenv') or which('virtualenv.py')
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
33 if virtualenv:
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
34 call([virtualenv, DEST])
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
35 else:
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
36 process = subproces.Popen([sys.executable, '-', DEST], stdin=subprocess.PIPE)
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
37 process.communicate(stdin=urllib2.urlopen(VIRTUALENV).read())
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
38
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
39 # create a src directory
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
40 src = os.path.join(DEST, 'src')
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
41 os.mkdir(src)
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
42
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
43 # clone the repository
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
44 call(['hg', 'clone', REPO], cwd=src)
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
45
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
46 """
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
47 XXX unfinished
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
48
96
cc17537254d2 add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
49 hg clone ${REPO}
cc17537254d2 add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50 cd {{project}}
cc17537254d2 add an install script template
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51 python setup.py develop
133
Jeff Hammel <jhammel@mozilla.com>
parents: 96
diff changeset
52 """