[Python-checkins] distutils2: Aadd a get_all_projects method for the XML/RPC client.

tarek.ziade python-checkins at python.org
Sun Dec 26 14:21:45 CET 2010


tarek.ziade pushed 555c26193dda to distutils2:
http://hg.python.org/distutils2/rev/555c26193dda
changeset: 851:555c26193dda
user: Alexis Metaireau <alexis at notmyidea.org>
date: Fri Dec 24 17:18:03 2010 +0100
summary:
 Aadd a get_all_projects method for the XML/RPC client.
files:
 distutils2/index/dist.py
 distutils2/index/xmlrpc.py
 distutils2/tests/pypi_server.py
 distutils2/tests/test_index_xmlrpc.py
diff --git a/distutils2/index/dist.py b/distutils2/index/dist.py
--- a/distutils2/index/dist.py
+++ b/distutils2/index/dist.py
@@ -101,7 +101,7 @@
 def is_final(self):
 """proxy to version.is_final"""
 return self.version.is_final
- 
+
 def fetch_distributions(self):
 if self.dists is None:
 self._index.get_distributions(self.name, '%s' % self.version)
@@ -127,7 +127,7 @@
 self.dists[dist_type] = DistInfo(self, dist_type,
 index=self._index, **params)
 if python_version:
- self.dists[dist_type].python_version = python_version 
+ self.dists[dist_type].python_version = python_version
 
 def get_distribution(self, dist_type=None, prefer_source=True):
 """Return a distribution.
@@ -302,7 +302,7 @@
 
 def unpack(self, path=None):
 """Unpack the distribution to the given path.
- 
+
 If not destination is given, creates a temporary location.
 
 Returns the location of the extracted files (root).
@@ -310,10 +310,10 @@
 if not self._unpacked_dir:
 if path is None:
 path = tempfile.mkdtemp()
- 
+
 filename = self.download()
 content_type = mimetypes.guess_type(filename)[0]
- 
+
 if (content_type == 'application/zip'
 or filename.endswith('.zip')
 or filename.endswith('.pybundle')
@@ -351,7 +351,7 @@
 """
 def __init__(self, name, releases=None, contains_hidden=False, index=None):
 self.set_index(index)
- self.releases = [] 
+ self.releases = []
 self.name = name
 self.contains_hidden = contains_hidden
 if releases:
@@ -404,7 +404,7 @@
 raise ValueError("%s is not the same project than %s" %
 (release.name, self.name))
 version = '%s' % release.version
- 
+
 if not version in self.get_versions():
 # append only if not already exists
 self.releases.append(release)
diff --git a/distutils2/index/xmlrpc.py b/distutils2/index/xmlrpc.py
--- a/distutils2/index/xmlrpc.py
+++ b/distutils2/index/xmlrpc.py
@@ -159,8 +159,15 @@
 index=self._index))
 except IrrationalVersionError, e:
 logging.warn("Irrational version error found: %s" % e)
+ return [self._projects[p['name'].lower()] for p in projects]
 
- return [self._projects[p['name'].lower()] for p in projects]
+ def get_all_projects(self):
+ """Return the list of all projects registered in the package index"""
+ projects = self.proxy.list_packages()
+ for name in projects:
+ self.get_releases(name, show_hidden=True)
+
+ return [self._projects[name.lower()] for name in set(projects)]
 
 @property
 def proxy(self):
diff --git a/distutils2/tests/pypi_server.py b/distutils2/tests/pypi_server.py
--- a/distutils2/tests/pypi_server.py
+++ b/distutils2/tests/pypi_server.py
@@ -400,7 +400,7 @@
 self._dists.append(dist)
 return [r.search_result() for r in results]
 
- def list_package(self):
+ def list_packages(self):
 return [d.name for d in self._dists]
 
 def package_releases(self, package_name, show_hidden=False):
diff --git a/distutils2/tests/test_index_xmlrpc.py b/distutils2/tests/test_index_xmlrpc.py
--- a/distutils2/tests/test_index_xmlrpc.py
+++ b/distutils2/tests/test_index_xmlrpc.py
@@ -25,6 +25,24 @@
 invalid="test")
 
 @use_xmlrpc_server()
+ def test_get_all_projects(self, server):
+ client = self._get_client(server)
+ server.xmlrpc.set_distributions([
+ {'name': 'FooBar', 'version': '1.1'},
+ {'name': 'FooBar', 'version': '1.2'},
+ {'name': 'Foo', 'version': '1.1'},
+ ])
+ results = client.get_all_projects()
+ self.assertEqual(2, len(results))
+
+ # check we do have two releases for Foobar's project
+ self.assertEqual(2, len(results[0].releases))
+
+ names = [r.name for r in results]
+ self.assertIn('FooBar', names)
+ self.assertIn('Foo', names)
+
+ @use_xmlrpc_server()
 def test_get_releases(self, server):
 client = self._get_client(server)
 server.xmlrpc.set_distributions([
--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /