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

Source Code for Module doapfiend.plugins.homepage

 1  #!/usr/bin/env python 
 2   
 3  # pylint: disable-msg=W0221,R0201 
 4   
 5  """ 
 6   
 7  homepage 
 8  ======== 
 9   
10  Fetches DOAP by searching doapspace.org by a project's homepage. 
11   
12  """ 
13   
14  __docformat__ = 'epytext' 
15   
16  import logging 
17   
18  from doapfiend.plugins.base import Plugin 
19  from doapfiend.doaplib import fetch_doap, query_by_homepage 
20   
21   
22 -class OutputPlugin(Plugin):
23 24 """Class for formatting DOAP output""" 25 26 #This will be the opt_parser option (--xml) in the output group 27 name = "homepage" 28 enabled = False 29 enable_opt = name 30
31 - def __init__(self):
32 '''Setup RDF/XML OutputPlugin class''' 33 super(OutputPlugin, self).__init__() 34 self.log = logging.getLogger("doapfiend") 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('-o', '--%s' % self.name, 40 action='store', 41 dest=self.enable_opt, 42 help="Search for DOAP by a project's homepage", 43 metavar='HOMEPAGE_URL') 44 return parser, output, search
45
46 - def search(self):
47 ''' 48 Get DOAP given a project's homepage 49 50 @rtype: unicode 51 @return: DOAP 52 ''' 53 resp = query_by_homepage(self.options.homepage) 54 self.log.debug(resp) 55 if len(resp) == 0: 56 self.log.error("Not found: %s" % self.options.homepage) 57 return 58 elif len(resp) == 1: 59 url = resp[0][1] 60 else: 61 #Multiple, send warning and use first 'external' if any 62 self.log.error("Warning: Multiple DOAP found.") 63 url = None 64 for this in resp: 65 self.log.error(this) 66 if not url: 67 #Keep first one if there is no external DOAP 68 url = this[1] 69 if this[0] == 'ex': 70 url = this[1] 71 self.log.error("Using %s" % url) 72 return fetch_doap(url, self.options.proxy)
73