annotate carton.py @ 10:d1f090c5f291

lets make some more tests
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 08 Jul 2011 13:23:47 -0700
parents 79f332fb3275
children e6a62ba0c24d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 make a self-extracting virtualenv from directories or URLs
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 of packages
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 To package up all files in a virtualenvs source directory (e.g.):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 python path/to/carton.py mozmill mozmill/src/*
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 This will create a self-extracting file, `mozmill.py`, that will unfold
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 a virtualenv
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 """
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 # imports
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 import os
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 import sys
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 import tarfile
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 import tempfile
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 import urllib2
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 from optparse import OptionParser
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 from StringIO import StringIO
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 # global variables
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 usage = "%prog [options] environment_name directory|url [...]"
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 virtualenv_url = 'http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.6.1.tar.gz'
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 template = """#!/usr/bin/env python
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 import os
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 import shutil
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 import subprocess
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 import sys
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 import tarfile
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 import tempfile
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 from optparse import OptionParser
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 from StringIO import StringIO
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38 try:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 call = subprocess.check_call
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40 except AttributeError:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 # old python; boo :(
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42 call = subprocess.call
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 # virtualenv name
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 ENV='''%(ENV)s'''
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47 # packed files
3
75919adb199a use compression, but it doesnt seem to help much
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
48 VIRTUAL_ENV='''%(VIRTUAL_ENV)s'''.decode('base64').decode('zlib')
75919adb199a use compression, but it doesnt seem to help much
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
49 PACKAGE_SOURCES='''%(PACKAGE_SOURCES)s'''.decode('base64').decode('zlib')
0
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51 # unpack virtualenv
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
52 tempdir = tempfile.mkdtemp()
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
53 buffer = StringIO()
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
54 buffer.write(VIRTUAL_ENV)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
55 buffer.seek(0)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
56 tf = tarfile.open(mode='r', fileobj=buffer)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
57 tf.extractall(tempdir)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
58
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
59 # find the virtualenv
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
60 for root, dirs, files in os.walk(tempdir):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
61 if 'virtualenv.py' in files:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
62 virtualenv = os.path.join(root, 'virtualenv.py')
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
63 break
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
64 else:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
65 raise Exception("virtualenv.py not found in " + tempdir)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
66 print virtualenv
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
67
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
68 # create the virtualenv
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
69 call([sys.executable, virtualenv, ENV])
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
70
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
71 # unpack the sources
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
72 srcdir = os.path.join(ENV, 'src')
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
73 os.mkdir(srcdir)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
74 buffer = StringIO()
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
75 buffer.write(PACKAGE_SOURCES)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
76 buffer.seek(0)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
77 tf = tarfile.open(mode='r', fileobj=buffer)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
78 tf.extractall(srcdir)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
79
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
80 # find the bin/scripts directory
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
81 for i in ('bin', 'Scripts'):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
82 scripts_dir = os.path.abspath(os.path.join(ENV, i))
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
83 if os.path.exists(scripts_dir):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
84 break
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
85 else:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
86 raise Exception("Scripts directory not found in " + ENV)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
87
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
88 # find the virtualenv's python
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
89 for i in ('python', 'python.exe'):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
90 python = os.path.join(scripts_dir, i)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
91 if os.path.exists(python):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
92 break
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
93 else:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
94 raise Exception("python not found in " + scripts_dir)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
95
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
96 # activate the virtualenv
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
97 #activate = os.path.join(scripts_dir, 'activate_this.py')
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
98 #assert os.path.exists(activate), activate + " does not exist"
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
99 #execfile(activate, dict(__file__=activate))
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
100
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
101 # setup the sources for development
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
102 for i in os.listdir(srcdir):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
103 subdir = os.path.join(srcdir, i)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
104 if os.path.exists(os.path.join(srcdir, i, 'setup.py')):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
105 call([python, 'setup.py', 'develop'], cwd=subdir)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
106
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
107 # cleanup tempdir
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
108 # shutil.rmtree(tempdir)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
109
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
110 # TODO:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
111 # - add carton to the virtualenv (!)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
112 # - add virtualenv to the virtualenv (!)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
113 """
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
114
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
115 def isURL(path):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
116 return path.startswith('http://') or path.startswith('https://')
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
117
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
118 def main(args=sys.argv[1:]):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
119
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
120 # parse CLI arguments
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
121 parser = OptionParser(usage=usage, description=__doc__)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
122 parser.add_option('-o', dest='outfile',
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
123 help="specify outfile; otherwise it will come from environment_name")
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
124 parser.add_option('--virtualenv', dest='virtualenv',
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
125 help="use virtualenv URL")
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
126 options, args = parser.parse_args(args)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
127 if len(args) < 2:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
128 parser.print_usage()
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
129 parser.exit()
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
130 environment = args[0]
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
131 if environment.endswith('.py'):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
132 # stop on .py; will add it in later
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
133 environment = environment[:-3]
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
134 sources = args[1:]
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
135
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
136 # tar up the sources
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
137 source_buffer = StringIO()
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
138 sources_tar = tarfile.open(mode="w:gz", fileobj=source_buffer)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
139 for source in sources:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
140
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
141 if isURL(source):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
142 # remote tarball
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
143 raise NotImplementedError
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
144 else:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
145 # local directory or tarball
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
146 sources_tar.add(source, arcname=os.path.basename(source))
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
147 # could use git, hg, etc repos. but probably shouldn't
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
148 sources_tar.close()
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
149
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
150 # tar up virtualenv if not available
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
151 if options.virtualenv:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
152 if isURL(options.virtualenv):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
153 globals()['VIRTUAL_ENV'] = urllib2.urlopen(options.virtualenv).read()
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
154 else:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
155 assert os.path.exists(options.virtualenv)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
156 if os.path.isdir(options.virtualenv):
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
157 raise NotImplementedError("Hypothetically you should be able to use a local directory or tarball, but I haven't done this yet")
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
158 else:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
159 # assert a tarfile
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
160 assert tarfile.is_tarfile(options.virtualenv), "%s must be a tar file" % options.virtualenv
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
161 globals()['VIRTUAL_ENV'] = file(options.virtualenv).read()
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
162 else:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
163 globals()['VIRTUAL_ENV'] = urllib2.urlopen(virtualenv_url).read()
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
164 # TODO: used the below hashed value of VIRTUAL_ENV if set
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
165 # (set that with another file)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
166
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
167 # interpolate "template" -> output
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
168 outfile = options.outfile
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
169 if outfile is None:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
170 outfile = environment + '.py'
3
75919adb199a use compression, but it doesnt seem to help much
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
171 variables = {'VIRTUAL_ENV': VIRTUAL_ENV.encode('zlib').encode('base64'),
0
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
172 'ENV': environment,
3
75919adb199a use compression, but it doesnt seem to help much
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
173 'PACKAGE_SOURCES': source_buffer.getvalue().encode('zlib').encode('base64')}
0
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
174 f = file(outfile, 'w')
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
175 f.write(template % variables)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
176 f.close()
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
177 try:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
178 os.chmod(outfile, 0755)
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
179 except:
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
180 # you probably don't have os.chmod
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
181 pass
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
182
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
183 VIRTUAL_ENV = """"""
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
184
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
185 if __name__ == '__main__':
1c7da6388dd9 initial commit of carton
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
186 main()