Port RainCT's LP Code URL handler to a plugin
This commit is contained in:
parent
8141a3496d
commit
6058727cdb
|
@ -5,7 +5,7 @@ import re
|
||||||
import plugin
|
import plugin
|
||||||
|
|
||||||
# Every plugin you want Terminator to load *must* be listed in 'available'
|
# Every plugin you want Terminator to load *must* be listed in 'available'
|
||||||
available = ['LaunchpadBugURLHandler', 'APTURLHandler']
|
available = ['LaunchpadBugURLHandler', 'LaunchpadCodeURLHandler', 'APTURLHandler']
|
||||||
|
|
||||||
class URLHandler(plugin.Plugin):
|
class URLHandler(plugin.Plugin):
|
||||||
"""Base class for URL handlers"""
|
"""Base class for URL handlers"""
|
||||||
|
@ -31,6 +31,25 @@ class LaunchpadBugURLHandler(URLHandler):
|
||||||
url = 'https://bugs.launchpad.net/bugs/%s' % item
|
url = 'https://bugs.launchpad.net/bugs/%s' % item
|
||||||
return(url)
|
return(url)
|
||||||
|
|
||||||
|
class LaunchpadCodeURLHandler(URLHandler):
|
||||||
|
"""Launchpad Code URL handler. If the URL looks like a Launchpad project or
|
||||||
|
branch entry then it should be transformed into a code.launchpad.net URL"""
|
||||||
|
capabilities = ['url_handler']
|
||||||
|
handler_name = 'launchpad_code'
|
||||||
|
lpfilters = {}
|
||||||
|
lpfilters['project'] = '[a-z0-9]{1}[a-z0-9\.\-\+]+'
|
||||||
|
lpfilters['group'] = '~%s' % lpfilters['project']
|
||||||
|
lpfilters['series'] = lpfilters['project']
|
||||||
|
lpfilters['branch'] = '[a-zA-Z0-9]{1}[a-zA-Z0-9_+@.-]+'
|
||||||
|
|
||||||
|
match = '\\b((lp|LP):%(project)s(/%(series)s)?|(lp|LP):%(group)s/(%(project)s|\+junk)/%(branch)s)\\b' % lpfilters
|
||||||
|
|
||||||
|
def callback(self, url):
|
||||||
|
"""Look for the number in the supplied string and return it as a URL"""
|
||||||
|
if url.startswith('lp:'):
|
||||||
|
url = url[3:]
|
||||||
|
return('https://code.launchpad.net/+branch/%s' % url)
|
||||||
|
|
||||||
class APTURLHandler(URLHandler):
|
class APTURLHandler(URLHandler):
|
||||||
"""APT URL handler. If there is a URL that looks like an apturl, handle
|
"""APT URL handler. If there is a URL that looks like an apturl, handle
|
||||||
it appropriately"""
|
it appropriately"""
|
||||||
|
|
Loading…
Reference in New Issue