Mercurial > hg > PaInt
comparison paint/package.py @ 19:c54db80d6e7f
fix test
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Mon, 27 Feb 2012 12:58:08 -0800 |
| parents | 4c4d1e194bf7 |
| children | 11bc01a089e7 |
comparison
equal
deleted
inserted
replaced
| 18:4c4d1e194bf7 | 19:c54db80d6e7f |
|---|---|
| 2 package model for python PAckage INTrospection | 2 package model for python PAckage INTrospection |
| 3 """ | 3 """ |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import shutil | 6 import shutil |
| 7 import subprocess | |
| 8 import sys | |
| 7 import tarfile | 9 import tarfile |
| 8 import tempfile | 10 import tempfile |
| 9 import urllib2 | 11 import urllib2 |
| 10 import utils | 12 import utils |
| 13 | |
| 14 try: | |
| 15 from subprocess import check_call as call | |
| 16 except ImportError: | |
| 17 from subporcess import call | |
| 11 | 18 |
| 12 __all__ = ['Package'] | 19 __all__ = ['Package'] |
| 13 | 20 |
| 14 class Package(object): | 21 class Package(object): |
| 15 # XXX much of this is generic resource stuff and should be split off | 22 # XXX much of this is generic resource stuff and should be split off |
| 58 # TODO: should handle zipfile additionally at least | 65 # TODO: should handle zipfile additionally at least |
| 59 # Ideally, this would be pluggable, etc | 66 # Ideally, this would be pluggable, etc |
| 60 assert tarfile.is_tarfile(archive), "%s is not an archive" % self.src | 67 assert tarfile.is_tarfile(archive), "%s is not an archive" % self.src |
| 61 tf = tarfile.TarFile.open(archive) | 68 tf = tarfile.TarFile.open(archive) |
| 62 self._tmppath = tempfile.mkdtemp() | 69 self._tmppath = tempfile.mkdtemp() |
| 63 tf.extractall(path=self._tmppath) | 70 members = tf.getmembers() |
| 71 | |
| 72 # cut off the top level directory | |
| 73 assert not [i for i in members if not os.path.sep in i.name] | |
| 74 tld = set() | |
| 75 for member in members: | |
| 76 directory, member.name = member.name.split(os.path.sep, 1) | |
| 77 tld.add(directory) | |
| 78 assert len(tld) == 1 | |
| 79 | |
| 80 # extract | |
| 81 for member in members: | |
| 82 tf.extract(member, path=self._tmppath) | |
| 83 tf.close() | |
| 64 | 84 |
| 65 def is_archive(self, path): | 85 def is_archive(self, path): |
| 66 """returns if the filesystem path is an archive""" | 86 """returns if the filesystem path is an archive""" |
| 67 # TODO: should handle zipfile additionally at least | 87 # TODO: should handle zipfile additionally at least |
| 68 # Ideally, this would be pluggable, etc | 88 # Ideally, this would be pluggable, etc |
| 88 setup_py = os.path.join(directory, 'setup.py') | 108 setup_py = os.path.join(directory, 'setup.py') |
| 89 if not os.path.exists(setup_py): | 109 if not os.path.exists(setup_py): |
| 90 raise AssertionError("%s does not exist" % setup_py) | 110 raise AssertionError("%s does not exist" % setup_py) |
| 91 | 111 |
| 92 # setup the egg info | 112 # setup the egg info |
| 93 call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=PIPE) | 113 call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=subprocess.PIPE) |
| 94 | 114 |
| 95 # get the .egg-info directory | 115 # get the .egg-info directory |
| 96 egg_info = [i for i in os.listdir(directory) | 116 egg_info = [i for i in os.listdir(directory) |
| 97 if i.endswith('.egg-info')] | 117 if i.endswith('.egg-info')] |
| 98 assert len(egg_info) == 1, 'Expected one .egg-info directory in %s, got: %s' % (directory, egg_info) | 118 assert len(egg_info) == 1, 'Expected one .egg-info directory in %s, got: %s' % (directory, egg_info) |
