annotate python/venvit.py @ 701:de7bf9523e21

-
author Jeff Hammel <k0scist@gmail.com>
date Wed, 13 Aug 2014 13:16:56 -0700
parents 0e270a448610
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 """
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 venvit.py -- the equivalent of ez_setup.py for virtualenv, but less intrusive;
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 It wants a one-step installation to install python into a new virtualenv.
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 venvit is meant to be used via e.g. curl, although you can download it as well:
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 curl http://example.com/path/to/venvit.py | python - <package>
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 If <package> is a package name, it tries to install it from the cheeseshop.
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 If it is a svn/hg/git/tgz/etc URL, it should download and install the software
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 in source.
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 Only useful output -- like the scripts installed -- should be output to the
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 user.
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 Ideally, packages could have a venvit__init__.py (or a better name) that
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 will be executed after installation (or a venvit.txt which would just be output
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 to console, maybe falling back to the README
a9110cc98d94 adding notes on a venvit idea
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 """
356
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
21
358
0e270a448610 more partial work
Jeff Hammel <jhammel@mozilla.com>
parents: 356
diff changeset
22 import optparse
356
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
23 import sys
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
24
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
25 # class for VCS
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
26 # TODO: hg, git, ...
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
27
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
28 # usage
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
29
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
30 args = sys.argv[1:]
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
31 if len(args) != 1:
358
0e270a448610 more partial work
Jeff Hammel <jhammel@mozilla.com>
parents: 356
diff changeset
32 print "Usage: %prog <repo-location>"
356
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
33
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
34
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
35 # determine name of the package
358
0e270a448610 more partial work
Jeff Hammel <jhammel@mozilla.com>
parents: 356
diff changeset
36 name = args[0]
0e270a448610 more partial work
Jeff Hammel <jhammel@mozilla.com>
parents: 356
diff changeset
37 for i in ('/trunk', '/branches', '/tag'):
0e270a448610 more partial work
Jeff Hammel <jhammel@mozilla.com>
parents: 356
diff changeset
38 if name.endswith(i):
0e270a448610 more partial work
Jeff Hammel <jhammel@mozilla.com>
parents: 356
diff changeset
39 name = name[:-len(i)]
0e270a448610 more partial work
Jeff Hammel <jhammel@mozilla.com>
parents: 356
diff changeset
40
356
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
41 NAME=${NAME%%/} # remove trailing slash
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
42 NAME=${NAME##*/}
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
43
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
44 if svn info $1 2> /dev/null
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
45 then
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
46 CHECKOUT="svn co"
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
47 else
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
48 CHECKOUT="hg clone"
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
49 fi
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
50
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
51 # create a virtualenv and install the software
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
52 VIRTUAL_ENV_LOCATION="${HOME}/virtualenv/virtualenv.py"
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
53 python ${VIRTUAL_ENV_LOCATION} ${NAME}
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
54 cd ${NAME}
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
55 source bin/activate
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
56 mkdir src/
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
57 cd src/
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
58 $CHECKOUT $1 ${NAME}
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
59 cd ${NAME}
915f88af9624 transition
Jeff Hammel <jhammel@mozilla.com>
parents: 70
diff changeset
60 python setup.py develop