Mercurial > hg > carton
comparison carton.py @ 24:bb19d3dac4c5
fix tests
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Sun, 10 Jul 2011 18:17:54 -0700 |
| parents | 987086aad234 |
| children | e6ee0410ceef |
comparison
equal
deleted
inserted
replaced
| 23:987086aad234 | 24:bb19d3dac4c5 |
|---|---|
| 184 # local directory or tarball | 184 # local directory or tarball |
| 185 assert os.path.exists(source), "%s does not exist" % source | 185 assert os.path.exists(source), "%s does not exist" % source |
| 186 | 186 |
| 187 # package up the source if applicable | 187 # package up the source if applicable |
| 188 if options.package and os.path.exists(os.path.join(source, 'setup.py')): | 188 if options.package and os.path.exists(os.path.join(source, 'setup.py')): |
| 189 call([sys.executable, 'setup.py', 'sdist'], cwd=source) | 189 |
| 190 # create a .tar.gz package | |
| 191 call([sys.executable, 'setup.py', 'sdist'], cwd=source, stdout=subprocess.PIPE) | |
| 190 dist_dir = os.path.join(source, 'dist') | 192 dist_dir = os.path.join(source, 'dist') |
| 191 assert os.path.isdir(dist_dir), "dist directory not created in %s" % source | 193 assert os.path.isdir(dist_dir), "dist directory not created in %s" % source |
| 192 tarfiles = [i for i in os.listdir(dist_dir) | 194 tarfiles = [i for i in os.listdir(dist_dir) |
| 193 if i.endswith('.tar.gz')] | 195 if i.endswith('.tar.gz')] |
| 194 assert tarfiles, "no .tar.gz files found in %s" % dist_dir | 196 assert tarfiles, "no .tar.gz files found in %s" % dist_dir |
| 197 | |
| 198 # use the last modified tarball | |
| 195 def last_modified(filename): | 199 def last_modified(filename): |
| 196 return os.path.getmtime(os.path.join(dist_dir, filename)) | 200 return os.path.getmtime(os.path.join(dist_dir, filename)) |
| 197 tarfiles.sort(key=last_modified) | 201 tarfiles.sort(key=last_modified) |
| 198 source = os.path.join(dist_dir, tarfiles[-1]) | 202 source = os.path.join(dist_dir, tarfiles[-1]) |
| 199 | 203 |
| 200 if (not os.path.isdir(source)) and tarfile.is_tarfile(source): | 204 if (not os.path.isdir(source)) and tarfile.is_tarfile(source): |
| 201 # check for a tarball | 205 # check for a tarball |
| 202 buffer = file(source).read() | 206 buffer = file(source).read() |
| 203 else: | 207 else: |
| 208 # add other sources (files and directories) to the archive | |
| 204 source_buffer = StringIO() | 209 source_buffer = StringIO() |
| 205 source_tar = tarfile.open(mode="w:gz", fileobj=source_buffer) | 210 source_tar = tarfile.open(mode="w:gz", fileobj=source_buffer) |
| 206 source_tar.add(source, arcname=os.path.basename(source)) | 211 source_tar.add(source, arcname=os.path.basename(source)) |
| 207 source_tar.close() | 212 source_tar.close() |
| 208 buffer = source_buffer.getvalue() | 213 buffer = source_buffer.getvalue() |
