views:

124

answers:

2

Currently I'm using a very ugly approach based on a regex for finding links and taking them apart.

I'm unhappy with the code, so I'm asking for nicer solutions, preferably using only the stdlib.

Edit

The task at hand has 2 parts:

  1. Find all distributions that match a certain criteria (like prefix of the name).
  2. Find all versions available in each found distribution.

The expected result is a mapping of distribution -> versions -> files.

A: 

In a buildout which access pypi i pin versions like this:

Products.PloneFormGen==1.2.5

Here it searches for version 1.2.5 an uses this..

Dont know if it is this what u looking for...

Gomez
no, im interested in finding sets of distributions + all availiable versions of those
Ronny
+1  A: 

There is an XML-RPC interface. See the Python.org wiki page on Cheese Shop (old name for PyPi) API.

Excerpt from that wiki:

>>> import xmlrpclib
>>> server = xmlrpclib.Server('http://pypi.python.org/pypi')
>>> server.package_releases('roundup')
['1.1.2']
>>> server.package_urls('roundup', '1.1.2')
[{'has_sig': True, 'comment_text': '', 'python_version': 'source', 'url': 'http://pypi.python.org/packages/source/r/roundup/roundup-1.1.2.tar.gz', 'md5_digest': '7c395da56412e263d7600fa7f0afa2e5', 'downloads': 2989, 'filename': 'roundup-1.1.2.tar.gz', 'packagetype': 'sdist', 'size': 876455}, {'has_sig': True, 'comment_text': '', 'python_version': 'any', 'url': 'http://pypi.python.org/packages/any/r/roundup/roundup-1.1.2.win32.exe', 'md5_digest': '983d565b0b87f83f1b6460e54554a845', 'downloads': 2020, 'filename': 'roundup-1.1.2.win32.exe', 'packagetype': 'bdist_wininst', 'size': 614270}]

list_packages and package_releases seem to be exactly what you're looking for.

@Ronny's Comment

You just have to write some code in Python to determine which of the listed packages satisfy the criterion; i.e. if the package name must start with foo:

>>> packages = server.list_packages()
>>> match_foo = [package for package in packages if package.startswith('foo')]
>>> print len(match_foo)
2
cdleary
that locks nice once i found the packages that matterbut how do find n packages matching certain criteria?unfortunately other python package indexes (ie inofficial ones) lack the xmlrpc interface
Ronny
Updated per your comment -- unofficial ones will probably have to be analyzed on a case-by-case basis. Feel free to update your question to mention what they are!
cdleary