def search(self, spec, operator='and'): """ Search the package database using the indicated search spec. The spec may include any of the keywords described in the above list (except 'stable_version' and 'classifiers'), for example: {'description': 'spam'} will search description fields. Within the spec, a field's value can be a string or a list of strings (the values within the list are combined with an OR), for example: {'name': ['foo', 'bar']}. Valid keys for the spec dict are listed here. Invalid keys are ignored: name version author author_email maintainer maintainer_email home_page license summary description keywords platform download_url Arguments for different fields are combined using either "and" (the default) or "or". Example: search({'name': 'foo', 'description': 'bar'}, 'or'). The results are returned as a list of dicts {'name': package name, 'version': package release version, 'summary': package release summary} """ api = pypi.proxy rv = [] # search in proxy for k, v in spec.items(): rv += api.search({k: v}, True) # search in local session = DBSession() release = Release.search(session, spec, operator) session.rollback() rv += [ { 'name': r.package.name, 'version': r.version, 'summary': r.summary, # hack https://mail.python.org/pipermail/catalog-sig/2012-October/004633.html '_pypi_ordering': '', } for r in release ] return rv
def search(self, spec, operator='and'): """ Search the package database using the indicated search spec. The spec may include any of the keywords described in the above list (except 'stable_version' and 'classifiers'), for example: {'description': 'spam'} will search description fields. Within the spec, a field's value can be a string or a list of strings (the values within the list are combined with an OR), for example: {'name': ['foo', 'bar']}. Valid keys for the spec dict are listed here. Invalid keys are ignored: name version author author_email maintainer maintainer_email home_page license summary description keywords platform download_url Arguments for different fields are combined using either "and" (the default) or "or". Example: search({'name': 'foo', 'description': 'bar'}, 'or'). The results are returned as a list of dicts {'name': package name, 'version': package release version, 'summary': package release summary} """ api = pypi.proxy rv = [] # search in proxy for k, v in spec.items(): rv += api.search({k: v}, True) # search in local session = DBSession() release = Release.search(session, spec, operator) session.rollback() rv += [{'name': r.package.name, 'version': r.version, 'summary': r.summary, # hack https://mail.python.org/pipermail/catalog-sig/2012-October/004633.html '_pypi_ordering':'', } for r in release] return rv
def search(self, spec, operator='and'): """ Search the package database using the indicated search spec. The spec may include any of the keywords described in the above list (except 'stable_version' and 'classifiers'), for example: {'description': 'spam'} will search description fields. Within the spec, a field's value can be a string or a list of strings (the values within the list are combined with an OR), for example: {'name': ['foo', 'bar']}. Valid keys for the spec dict are listed here. Invalid keys are ignored: name version author author_email maintainer maintainer_email home_page license summary description keywords platform download_url Arguments for different fields are combined using either "and" (the default) or "or". Example: search({'name': 'foo', 'description': 'bar'}, 'or'). The results are returned as a list of dicts {'name': package name, 'version': package release version, 'summary': package release summary} """ session = DBSession() release = Release.search(session, spec, operator) session.rollback() rv = [{'name': r.package.name, 'version': r.version, 'summary': r.summary} for r in release] return rv
def test_search_by_author(self): from pyshop.models import Release releases = Release.search(self.session, {'author': 'janedoe'}, 'and') self.assertIsInstance(releases, list) releases = [(r.package.name, r.version) for r in releases] self.assertEqual(releases, [(u'mirrored_package1', u'0.1')])