Commits

Gregory Petukhov committed 2c9ed66

Initial commit

  • Participants

Comments (0)

Files changed (4)

+syntax: glob
+*.pyc
+*.swp
+*.egg-info/
+dist/
+update_pypi.sh
+global-exclude *.pyc
+#!/usr/bin/env python
+"""
+Command line interface to Python Package Index
+"""
+from xmlrpclib import ServerProxy
+from optparse import OptionParser
+
+VERSION = '0.0.1'
+
+FILTERS = (
+    'name', 'version', 'author', 'author_email', 'maintainer',
+    'maintainer_email', 'home_page', 'license', 'summary',
+    'description', 'keywords', 'platform', 'download_url')
+
+PACKAGE_FIELDS = (
+    'name', 'summary',
+    'version', 'stable_version', 'author', 'author_email', 'maintainer',
+    'maintainer_email', 'license', 'description',
+    'keywords', 'platform', 'download_url', 'classifiers',
+    'requires', 'requires_dist', 'provides', 'provides_dist', 'requires_external',
+    'requires_python', 'obsoletes', 'obsoletes_dist', 'project_url',
+    'home_page', 'package_url', 'release_url',
+    '_pypi_hidden', '_pypi_ordering')
+
+def main():
+    parser = OptionParser()
+    for fname in FILTERS:
+        parser.add_option('--%s' % fname)
+    parser.add_option('-s', dest='show', action='store_true', default=False,
+                      help='Show package info')
+    parser.add_option('-V', dest='show_version', action='store_true', default=False,
+                      help='Show pypi util version')
+    kwargs, args = parser.parse_args()
+    if kwargs.show:
+        action = 'show'
+    elif kwargs.show_version:
+        action = 'version'
+    else:
+        action = 'search'
+
+
+    if action == 'search':
+        client = ServerProxy('http://pypi.python.org/pypi')
+        query = {}
+        for key in FILTERS:
+            value = getattr(kwargs, key)
+            if value:
+                query[key] = value
+        if args:
+            query['name'] = query.get('name', '') + ' '.join(args)
+        resp = client.search(query)
+        for item in resp:
+            print '%-30s - %s' % (item['name'], item['summary'])
+
+    if action == 'show':
+        client = ServerProxy('http://pypi.python.org/pypi')
+        package = args[0]
+        version = client.package_releases(package)[0]
+        data = client.release_data(package, version)
+        def key_func(x):
+            try:
+                return PACKAGE_FIELDS.index(x[0])
+            except ValueError:
+                return 100
+        for key, value in sorted(data.items(), key=key_func):
+            if value is not None and not key.startswith('_') and value != 'UNKNOWN':
+                if isinstance(value, bool):
+                    value =  'yes' if value else 'no'
+                if isinstance(value, int):
+                    value = str(value)
+                if isinstance(value, list):
+                    value = '\n'.join(value)
+                value = value.splitlines()
+                value = '\n'.join(value[:1] + [' ' * 22 + x for x in value[1:]])
+                print ' %-20s %s' % ('%s:' % key, value)
+
+    if action == 'version':
+        print VERSION
+
+
+if __name__ == '__main__':
+    main()
+#!/usr/bin/env python
+import os
+from setuptools import setup
+
+PACKAGE = 'pypi-tools'
+from pypi import VERSION
+
+setup(
+    name = 'pypi-tools',
+    version = VERSION,
+    description = 'Command line PyPI search tool',
+    author = 'Grigoriy Petukhov',
+    author_email = 'lorien@lorien.name',
+    url = 'http://bitbucket.org/lorien/pypi-tools',
+    py_modules = ['pypi'],
+    scripts = ['pypi'],
+    license = "BSD",
+    keywords = "django application development shortcuts helpers",
+    classifiers=[
+        'Development Status :: 4 - Beta',
+        'Environment :: Web Environment',
+        'Framework :: Django',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: BSD License',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Topic :: Software Development :: Libraries :: Python Modules',
+    ],
+)