Mercurial > hg > carton
comparison carton.py @ 18:c6a03199d4bf
stub out package creation; next: to test this
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 08 Jul 2011 17:19:25 -0700 |
parents | b05f5f1ec26e |
children | 46882eaebb59 |
comparison
equal
deleted
inserted
replaced
17:b05f5f1ec26e | 18:c6a03199d4bf |
---|---|
13 """ | 13 """ |
14 | 14 |
15 # imports | 15 # imports |
16 import os | 16 import os |
17 import sys | 17 import sys |
18 import subprocess | |
18 import tarfile | 19 import tarfile |
19 import tempfile | 20 import tempfile |
20 import urllib2 | 21 import urllib2 |
21 from optparse import OptionParser | 22 from optparse import OptionParser |
22 from StringIO import StringIO | 23 from StringIO import StringIO |
71 if 'virtualenv.py' in files: | 72 if 'virtualenv.py' in files: |
72 virtualenv = os.path.join(root, 'virtualenv.py') | 73 virtualenv = os.path.join(root, 'virtualenv.py') |
73 break | 74 break |
74 else: | 75 else: |
75 raise Exception("virtualenv.py not found in " + tempdir) | 76 raise Exception("virtualenv.py not found in " + tempdir) |
76 print virtualenv | |
77 | 77 |
78 # create the virtualenv | 78 # create the virtualenv |
79 os.environ.pop('PYTHONHOME', None) | 79 os.environ.pop('PYTHONHOME', None) |
80 call([sys.executable, virtualenv, ENV]) | 80 call([sys.executable, virtualenv, ENV]) |
81 | 81 |
126 """ | 126 """ |
127 | 127 |
128 def isURL(path): | 128 def isURL(path): |
129 return path.startswith('http://') or path.startswith('https://') | 129 return path.startswith('http://') or path.startswith('https://') |
130 | 130 |
131 try: | |
132 call = subprocess.check_call | |
133 except AttributeError: | |
134 # old python; boo :( | |
135 call = subprocess.call | |
136 | |
131 def main(args=sys.argv[1:]): | 137 def main(args=sys.argv[1:]): |
132 | 138 |
133 # parse CLI arguments | 139 # parse CLI arguments |
134 parser = OptionParser(usage=usage, description=__doc__) | 140 parser = OptionParser(usage=usage, description=__doc__) |
135 parser.add_option('-o', dest='outfile', | 141 parser.add_option('-o', dest='outfile', |
136 help="specify outfile; otherwise it will come from environment_name") | 142 help="specify outfile; otherwise it will come from environment_name") |
143 parser.add_option('-p', '--package', dest='package', | |
144 action='store_true', default=False, | |
145 help="create python packages from sources; do not take entire subdirectory") | |
137 parser.add_option('--virtualenv', dest='virtualenv', | 146 parser.add_option('--virtualenv', dest='virtualenv', |
138 help="use this virtualenv URL or file tarball") | 147 help="use this virtualenv URL or file tarball") |
139 options, args = parser.parse_args(args) | 148 options, args = parser.parse_args(args) |
140 if len(args) < 2: | 149 if len(args) < 2: |
141 parser.print_usage() | 150 parser.print_usage() |
153 | 162 |
154 if isURL(source): | 163 if isURL(source): |
155 # remote tarball or resource | 164 # remote tarball or resource |
156 buffer = urllib2.urlopen(source).read() | 165 buffer = urllib2.urlopen(source).read() |
157 else: | 166 else: |
167 # local directory or tarball | |
158 assert os.path.exists(source), "%s does not exist" % source | 168 assert os.path.exists(source), "%s does not exist" % source |
169 | |
170 # package up the source if applicable | |
171 if options.package and os.path.exists(os.path.join(source, 'setup.py')): | |
172 call([sys.executable, 'setup.py', 'sdist'], cwd=source) | |
173 dist_dir = os.path.join(source, 'dist') | |
174 assert os.path.isdir(dist_dir), "dist directory not created in %s" % source | |
175 tarfiles = [i for i in os.listdir(dist_dir) | |
176 if i.endswith('.tar.gz')] | |
177 assert tarfiles, "no .tar.gz files found in %s" % dist_dir | |
178 def last_modified(filename): | |
179 return os.path.getmtime(os.path.join(dist_dir, filename)) | |
180 tarfiles.sort(key=last_modified) | |
181 source = os.path.join(dist_dir, tarfiles[-1]) | |
159 | 182 |
160 # local directory or tarball | |
161 if (not os.path.isdir(source)) and tarfile.is_tarfile(source): | 183 if (not os.path.isdir(source)) and tarfile.is_tarfile(source): |
162 # check for a tarball | 184 # check for a tarball |
163 buffer = file(source).read() | 185 buffer = file(source).read() |
164 else: | 186 else: |
165 source_buffer = StringIO() | 187 source_buffer = StringIO() |