[Pypi-checkins] r999 - trunk/pypi
martin.von.loewis
python-checkins at python.org
Mon Dec 12 19:31:13 CET 2011
Author: martin.von.loewis
Date: Mon Dec 12 19:31:13 2011
New Revision: 999
Modified:
trunk/pypi/rpc.py
trunk/pypi/store.py
Log:
Add browse RPC.
Modified: trunk/pypi/rpc.py
==============================================================================
--- trunk/pypi/rpc.py (original)
+++ trunk/pypi/rpc.py Mon Dec 12 19:31:13 2011
@@ -21,6 +21,7 @@
self.register_function(release_data)
self.register_function(release_data, name='package_data') # Deprecated
self.register_function(search)
+ self.register_function(browse)
self.register_function(updated_releases)
self.register_function(changelog)
self.register_function(changed_packages)
@@ -119,6 +120,19 @@
spec['_pypi_hidden'] = 'FALSE'
return [row.as_dict() for row in store.query_packages(spec, operator)]
+def browse(store, categories):
+ if not isinstance(categories, list):
+ raise TypeError, "Parameter categories must be a list"
+ classifier_ids = store.get_classifier_ids(categories)
+ print classifier_ids
+ if len(classifier_ids) != len(categories):
+ for c in categories:
+ if c not in classifier_ids:
+ raise ValueError, 'Unknown category "%s"' % c
+ ids = classifier_ids.values()
+ packages, tally = store.browse(ids)
+ return [(name, version) for name, version, desc in packages]
+
def updated_releases(store, since):
result = store.updated_releases(since)
return [(row['name'], row['version']) for row in result]
Modified: trunk/pypi/store.py
==============================================================================
--- trunk/pypi/store.py (original)
+++ trunk/pypi/store.py Mon Dec 12 19:31:13 2011
@@ -705,6 +705,15 @@
' order by classifier')
return Result(None, cursor.fetchall(), self._Classifiers)
+ _ClassifierID = FastResultRow('classifier id')
+ def get_classifier_ids(self, classifiers):
+ '''Map list of classifiers to classifier IDs'''
+ cursor = self.get_cursor()
+ placeholders = ','.join(['%s'] * len(classifiers))
+ safe_execute(cursor, 'select classifier, id from trove_classifiers '
+ 'where classifier in (%s)' % placeholders, classifiers)
+ return dict(cursor.fetchall())
+
_Release_Classifiers = FastResultRow('classifier trove_id!')
def get_release_classifiers(self, name, version):
''' Fetch the list of classifiers for the release.
More information about the Pypi-checkins
mailing list