doapfiend.plugins.url

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

# Source Code for Module doapfiend.plugins.url

     1  #!/usr/bin/env python
     2
     3  # pylint: disable-msg=W0221,R0201
     4
     5  """
     6
     7  url.py
     8  ======
     9
    10  This plugin loads DOAP by its URL or path to a filename.
    11
    12
    13  """
    14
    15  __docformat__ = 'epytext'
    16
    17
    18  from doapfiend.plugins.base import Plugin
    19  from doapfiend.utils import NotFoundError
    20  from doapfiend.doaplib import fetch_doap
    21
    22
    23 -class UrlPlugin(Plugin):
    24
    25      """Class for formatting DOAP output"""
    26
    27      #This will be the opt_parser option (--url) in the 'search' group
    28      name = 'url'
    29      enabled = False
    30      enable_opt = name
    31
    32 -    def __init__(self):
    33          '''Setup RDF/XML OutputPlugin class'''
    34          super(UrlPlugin, self).__init__()
    35          self.options = None
    36
    37 -    def add_options(self, parser, output, search):
    38          """Add plugin's options to doapfiend's opt parser"""
    39          search.add_option('-u', '--%s' % self.name,
    40                  action='store',
    41                  dest=self.enable_opt,
    42                  help='Get DOAP by its URL or by filename.',
    43                  metavar='URL')
    44          return parser, output, search
    45
    46 -    def search(self):
    47          '''
    48          Get DOAP by its URL or file path
    49          This can be any RDF as long as it has the DOAP namespace.
    50
    51          @rtype: unicode
    52          @return: DOAP
    53          '''
    54          try:
    55              return fetch_doap(self.options.url, self.options.proxy)
    56          except NotFoundError:
    57              print "Not found: %s" % self.options.url
    58