2009-12-17 23:30:12 +00:00
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net?
|
|
|
|
# GPL v2 only
|
|
|
|
"""url_handlers.py - Default plugins for URL handling"""
|
2009-12-17 23:17:03 +00:00
|
|
|
import re
|
2010-01-04 13:46:55 +00:00
|
|
|
import terminatorlib.plugin as plugin
|
2009-12-17 01:09:13 +00:00
|
|
|
|
2010-06-10 15:56:17 +00:00
|
|
|
# Every plugin you want Terminator to load *must* be listed in 'AVAILABLE'
|
|
|
|
AVAILABLE = ['LaunchpadBugURLHandler', 'LaunchpadCodeURLHandler', 'APTURLHandler']
|
2009-12-17 13:51:55 +00:00
|
|
|
|
2010-01-05 22:22:13 +00:00
|
|
|
class LaunchpadBugURLHandler(plugin.URLHandler):
|
2009-12-30 01:50:18 +00:00
|
|
|
"""Launchpad Bug URL handler. If the URL looks like a Launchpad changelog
|
2009-12-17 23:17:03 +00:00
|
|
|
closure entry... 'LP: #12345' then it should be transformed into a
|
2009-12-30 01:50:18 +00:00
|
|
|
Launchpad Bug URL"""
|
2009-12-17 23:17:03 +00:00
|
|
|
capabilities = ['url_handler']
|
2009-12-30 01:50:18 +00:00
|
|
|
handler_name = 'launchpad_bug'
|
|
|
|
match = '\\b(lp|LP):?\s?#?[0-9]+(,\s*#?[0-9]+)*\\b'
|
2012-01-14 20:09:25 +00:00
|
|
|
nameopen = "Open Launchpad bug"
|
|
|
|
namecopy = "Copy bug URL"
|
2009-12-17 23:17:03 +00:00
|
|
|
|
|
|
|
def callback(self, url):
|
2009-12-17 23:30:12 +00:00
|
|
|
"""Look for the number in the supplied string and return it as a URL"""
|
2009-12-17 23:17:03 +00:00
|
|
|
for item in re.findall(r'[0-9]+', url):
|
|
|
|
url = 'https://bugs.launchpad.net/bugs/%s' % item
|
|
|
|
return(url)
|
2009-12-17 01:09:13 +00:00
|
|
|
|
2010-01-05 22:22:13 +00:00
|
|
|
class LaunchpadCodeURLHandler(plugin.URLHandler):
|
2010-01-02 01:40:26 +00:00
|
|
|
"""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'
|
2012-01-14 20:09:25 +00:00
|
|
|
nameopen = "Open Launchpad branch"
|
|
|
|
namecopy = "Copy branch URL"
|
2010-01-02 01:40:26 +00:00
|
|
|
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)
|
|
|
|
|
2010-01-05 22:22:13 +00:00
|
|
|
class APTURLHandler(plugin.URLHandler):
|
2009-12-23 17:30:26 +00:00
|
|
|
"""APT URL handler. If there is a URL that looks like an apturl, handle
|
|
|
|
it appropriately"""
|
|
|
|
capabilities = ['url_handler']
|
2009-12-30 01:50:18 +00:00
|
|
|
handler_name = 'apturl'
|
2012-01-14 20:09:25 +00:00
|
|
|
nameopen = "Open software manager"
|
|
|
|
namecopy = "Copy package URI"
|
2009-12-23 17:30:26 +00:00
|
|
|
match = '\\bapt:.*\\b'
|
|
|
|
|
|
|
|
def callback(self, url):
|
|
|
|
"""Actually we don't need to do anything for this to work"""
|
|
|
|
return(url)
|
|
|
|
|