Commits

Gregory Petukhov committed 73a2e0a

Morning fixes

  • Participants
  • Parent commits 2c9ed66

Comments (0)

Files changed (4)

+==========
+pypi-tools
+==========
+
+Package pypi-tools contains now only one script called ``pypi``.
+It is command line utility for searching in Python Package Index.
+For further help please install pypi-tools and run ``pypi -h`` command.
+VERSION = '0.0.1'
 Command line interface to Python Package Index
 """
 from xmlrpclib import ServerProxy
-from optparse import OptionParser
-
-VERSION = '0.0.1'
+from optparse import OptionParser, OptionGroup
+import sys
 
 FILTERS = (
     'name', 'version', 'author', 'author_email', 'maintainer',
     'home_page', 'package_url', 'release_url',
     '_pypi_hidden', '_pypi_ordering')
 
+USAGE = """%prog [OPTION] [SEARCH_QUERY] - to search in PyPI database
+       %prog -s <package_name> - to show package details
+Try `%prog -h` for full option list"""
+
 def main():
-    parser = OptionParser()
-    for fname in FILTERS:
-        parser.add_option('--%s' % fname)
+    parser = OptionParser(usage=USAGE)
     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')
+    group = OptionGroup(parser, 'Search mode options')
+    for fname in FILTERS:
+        group.add_option('--%s' % fname)
+    parser.add_option_group(group)
+    #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'
+    #elif kwargs.show_version:
+        #action = 'version'
     else:
         action = 'search'
 
                 query[key] = value
         if args:
             query['name'] = query.get('name', '') + ' '.join(args)
+        if not query:
+            parser.print_usage()
+            sys.exit()
         resp = client.search(query)
         for item in resp:
             print '%-30s - %s' % (item['name'], item['summary'])
                 value = '\n'.join(value[:1] + [' ' * 22 + x for x in value[1:]])
                 print ' %-20s %s' % ('%s:' % key, value)
 
-    if action == 'version':
-        print VERSION
+    #if action == 'version':
+        #print VERSION
 
 
 if __name__ == '__main__':
 from setuptools import setup
 
 PACKAGE = 'pypi-tools'
-from pypi import VERSION
+VERSION = '0.0.1'
 
 setup(
     name = 'pypi-tools',