doapfiend.plugins.pypi

Package doapfiend :: Package plugins :: Module pypi |
[hide private]
[frames] | no frames]

# Source Code for Module doapfiend.plugins.pypi

     1  #!/usr/bin/env python
     2
     3  # pylint: disable-msg=W0221,R0201
     4
     5  """
     6  pypi
     7  ====
     8
     9  Currently this plugin uses http://doapspace.org/ to fetch DOAP for PyPI
    10  (The Python Package Index)
    11
    12  """
    13
    14  __docformat__ = 'epytext'
    15
    16
    17  from doapfiend.utils import NotFoundError
    18  from doapfiend.plugins.base import Plugin
    19  from doapfiend.plugins.pkg_index import get_by_pkg_index
    20
    21
    22 -class PyPIPlugin(Plugin):
    23
    24      """Get DOAP from PyPI package index"""
    25
    26      #This will be the opt_parser option (--pypy) in the output group
    27      name = 'pypi'
    28      enabled = False
    29      enable_opt = name
    30      prefix = 'py'
    31
    32 -    def __init__(self):
    33          '''Setup RDF/XML OutputPlugin class'''
    34          super(PyPIPlugin, self).__init__()
    35          self.options = None
    36          self.query = None
    37
    38 -    def add_options(self, parser, output, search):
    39          """Add plugin's options to doapfiend's opt parser"""
    40          search.add_option('-p', '--%s' % self.name,
    41                  action='store',
    42                  dest=self.enable_opt,
    43                  help='Get DOAP by its PyPI project name.',
    44                  metavar='PROJECT_NAME')
    45          return parser, output, search
    46
    47 -    def search(self, proxy=None):
    48          '''
    49          Get PyPI DOAP
    50
    51          @param proxy: URL of optional HTTP proxy
    52          @type proxy: string
    53
    54          @rtype: unicode
    55          @returns: Single DOAP
    56
    57          '''
    58          if hasattr(self.options, self.name):
    59              self.query = getattr(self.options, self.name)
    60          #Else self.query was set directly, someone not using the CLI
    61          try:
    62              return get_by_pkg_index(self.prefix, self.query, proxy)
    63          except NotFoundError:
    64              print "Not found: %s" % self.query
    65