summaryrefslogtreecommitdiff
path: root/distutils2
diff options
context:
space:
mode:
authorTarek Ziade <tarek@ziade.org>2011-01-30 14:49:01 +0100
committerTarek Ziade <tarek@ziade.org>2011-01-30 14:49:01 +0100
commit91bf3f123bf8c3190cef98ccbe9eff1149b287ac (patch)
treee5923ba1f8265ac61dbd28235926d0361efeda4d /distutils2
parent1ced6905e8d5c220f6ec4a76784bdda61f385199 (diff)
parent618dcd5c2dc7df1261279c4f7c68860651f9682d (diff)
downloaddisutils2-91bf3f123bf8c3190cef98ccbe9eff1149b287ac.tar.gz
merged
Diffstat (limited to 'distutils2')
-rw-r--r--distutils2/_backport/shutil.py9
-rw-r--r--distutils2/index/dist.py17
-rw-r--r--distutils2/run.py48
-rw-r--r--distutils2/tests/pypiserver/downloads_with_md5/simple/foobar/foobar-0.1.tar.gzbin0 -> 110 bytes
-rw-r--r--distutils2/tests/test_index_dist.py20
5 files changed, 67 insertions, 27 deletions
diff --git a/distutils2/_backport/shutil.py b/distutils2/_backport/shutil.py
index 802d089..17d6728 100644
--- a/distutils2/_backport/shutil.py
+++ b/distutils2/_backport/shutil.py
@@ -742,6 +742,8 @@ def unpack_archive(filename, extract_dir=None, format=None):
if extract_dir is None:
extract_dir = os.getcwd()
+ func = None
+
if format is not None:
try:
format_info = _UNPACK_FORMATS[format]
@@ -758,4 +760,9 @@ def unpack_archive(filename, extract_dir=None, format=None):
func = _UNPACK_FORMATS[format][1]
kwargs = dict(_UNPACK_FORMATS[format][2])
- raise ValueError('Unknown archive format: %s' % filename)
+ func(filename, extract_dir, **kwargs)
+
+ if func is None:
+ raise ValueError('Unknown archive format: %s' % filename)
+
+ return extract_dir
diff --git a/distutils2/index/dist.py b/distutils2/index/dist.py
index eeb5809..b03a61d 100644
--- a/distutils2/index/dist.py
+++ b/distutils2/index/dist.py
@@ -149,6 +149,16 @@ class ReleaseInfo(IndexReference):
dist = self.dists.values()[0]
return dist
+ def unpack(self, path=None, prefer_source=True):
+ """Unpack the distribution to the given path.
+
+ If not destination is given, creates a temporary location.
+
+ Returns the location of the extracted files (root).
+ """
+ return self.get_distribution(prefer_source=prefer_source)\
+ .unpack(path=path)
+
def download(self, temp_path=None, prefer_source=True):
"""Download the distribution, using the requirements.
@@ -312,7 +322,7 @@ class DistInfo(IndexReference):
if path is None:
path = tempfile.mkdtemp()
- filename = self.download()
+ filename = self.download(path)
content_type = mimetypes.guess_type(filename)[0]
self._unpacked_dir = unpack_archive(filename)
@@ -332,8 +342,11 @@ class DistInfo(IndexReference):
% (hashval.hexdigest(), expected_hashval))
def __repr__(self):
+ if self.release is None:
+ return "<? ? %s>" % self.dist_type
+
return "<%s %s %s>" % (
- self.release.name, self.release.version, self.dist_type or "")
+ self.release.name, self.release.version, self.dist_type or "")
class ReleasesList(IndexReference):
diff --git a/distutils2/run.py b/distutils2/run.py
index 01a654d..aa4f04f 100644
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -83,10 +83,10 @@ def commands_main(**attrs):
dist = distclass(attrs)
except DistutilsSetupError, msg:
if 'name' in attrs:
- raise SystemExit, "error in %s setup command: %s" % \
- (attrs['name'], msg)
+ raise SystemExit("error in %s setup command: %s" % \
+ (attrs['name'], msg))
else:
- raise SystemExit, "error in setup command: %s" % msg
+ raise SystemExit("error in setup command: %s" % msg)
# Find and parse the config file(s): they will override options from
# the setup script, but be overridden by the command line.
@@ -98,22 +98,21 @@ def commands_main(**attrs):
try:
res = dist.parse_command_line()
except DistutilsArgError, msg:
- raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
+ raise SystemExit(gen_usage(dist.script_name) + "\nerror: %s" % msg)
# And finally, run all the commands found on the command line.
if res:
try:
dist.run_commands()
except KeyboardInterrupt:
- raise SystemExit, "interrupted"
+ raise SystemExit("interrupted")
except (IOError, os.error), exc:
error = grok_environment_error(exc)
- raise SystemExit, error
+ raise SystemExit(error)
except (DistutilsError,
CCompilerError), msg:
- raise
- raise SystemExit, "error: " + str(msg)
+ raise SystemExit("error: " + str(msg))
return dist
@@ -127,7 +126,10 @@ def _set_logger():
def main():
- """Main entry point for Distutils2"""
+ """Main entry point for Distutils2
+
+ Execute an action or delegate to the commands system.
+ """
_set_logger()
parser = OptionParser()
parser.disable_interspersed_args()
@@ -164,7 +166,7 @@ def main():
options, args = parser.parse_args()
if options.version:
print('Distutils2 %s' % __version__)
-# sys.exit(0)
+ return 0
if len(options.metadata):
from distutils2.dist import Distribution
@@ -178,18 +180,18 @@ def main():
keys = options.metadata
if len(keys) == 1:
print metadata[keys[0]]
- sys.exit(0)
+ return
for key in keys:
if key in metadata:
- print(metadata._convert_name(key)+':')
+ print(metadata._convert_name(key) + ':')
value = metadata[key]
if isinstance(value, list):
for v in value:
- print(' '+v)
+ print(' ' + v)
else:
- print(' '+value.replace('\n', '\n '))
- sys.exit(0)
+ print(' ' + value.replace('\n', '\n '))
+ return 0
if options.search is not None:
search = options.search.lower()
@@ -199,7 +201,7 @@ def main():
print('%s %s at %s' % (dist.name, dist.metadata['version'],
dist.path))
- sys.exit(0)
+ return 0
if options.graph is not None:
name = options.graph
@@ -211,25 +213,25 @@ def main():
graph = generate_graph(dists)
print(graph.repr_node(dist))
- sys.exit(0)
+ return 0
if options.fgraph:
dists = get_distributions(use_egg_info=True)
graph = generate_graph(dists)
print(graph)
- sys.exit(0)
+ return 0
if options.install is not None:
install(options.install)
- sys.exit(0)
+ return 0
if len(args) == 0:
parser.print_help()
- sys.exit(0)
+ return 0
- return commands_main()
-# sys.exit(0)
+ commands_main()
+ return 0
if __name__ == '__main__':
- main()
+ sys.exit(main())
diff --git a/distutils2/tests/pypiserver/downloads_with_md5/simple/foobar/foobar-0.1.tar.gz b/distutils2/tests/pypiserver/downloads_with_md5/simple/foobar/foobar-0.1.tar.gz
index e69de29..333961e 100644
--- a/distutils2/tests/pypiserver/downloads_with_md5/simple/foobar/foobar-0.1.tar.gz
+++ b/distutils2/tests/pypiserver/downloads_with_md5/simple/foobar/foobar-0.1.tar.gz
Binary files differ
diff --git a/distutils2/tests/test_index_dist.py b/distutils2/tests/test_index_dist.py
index c09e661..dcc8648 100644
--- a/distutils2/tests/test_index_dist.py
+++ b/distutils2/tests/test_index_dist.py
@@ -127,7 +127,7 @@ class TestDistInfo(TempdirManager, unittest.TestCase):
url = "%s/simple/foobar/foobar-0.1.tar.gz" % server.full_address
# check md5 if given
dist = Dist(url=url, hashname="md5",
- hashval="d41d8cd98f00b204e9800998ecf8427e")
+ hashval="fe18804c5b722ff024cabdf514924fc4")
dist.download(self.mkdtemp())
# a wrong md5 fails
@@ -157,6 +157,24 @@ class TestDistInfo(TempdirManager, unittest.TestCase):
hashname="invalid_hashname",
hashval="value")
+ @use_pypi_server('downloads_with_md5')
+ def test_unpack(self, server):
+ url = "%s/simple/foobar/foobar-0.1.tar.gz" % server.full_address
+ dist = Dist(url=url)
+ # doing an unpack
+ here = self.mkdtemp()
+ there = dist.unpack(here)
+ result = os.listdir(there)
+ self.assertIn('paf', result)
+
+ def test_hashname(self):
+ # Invalid hashnames raises an exception on assignation
+ Dist(hashname="md5", hashval="value")
+
+ self.assertRaises(UnsupportedHashName, Dist,
+ hashname="invalid_hashname",
+ hashval="value")
+
class TestReleasesList(unittest.TestCase):