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
|
2009-12-17 01:09:13 +00:00
|
|
|
import plugin
|
|
|
|
|
2009-12-17 23:30:12 +00:00
|
|
|
# Every plugin you want Terminator to load *must* be listed in 'available'
|
2009-12-23 17:30:26 +00:00
|
|
|
available = ['LaunchpadURLHandler', 'APTURLHandler']
|
2009-12-17 13:51:55 +00:00
|
|
|
|
2009-12-17 23:17:03 +00:00
|
|
|
class URLHandler(plugin.Plugin):
|
|
|
|
"""Base class for URL handlers"""
|
2009-12-17 01:09:13 +00:00
|
|
|
capabilities = ['url_handler']
|
2009-12-17 23:17:03 +00:00
|
|
|
handler_name = None
|
|
|
|
match = None
|
|
|
|
|
|
|
|
def callback(self, url):
|
2009-12-17 23:30:12 +00:00
|
|
|
"""Callback to transform the enclosed URL"""
|
2009-12-17 23:17:03 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
class LaunchpadURLHandler(URLHandler):
|
|
|
|
"""Launchpad URL handler. If the URL looks like a Launchpad changelog
|
|
|
|
closure entry... 'LP: #12345' then it should be transformed into a
|
|
|
|
Launchpad URL"""
|
|
|
|
capabilities = ['url_handler']
|
|
|
|
handler_name = 'launchpad'
|
|
|
|
match = '\\bLP:? #?[0-9]+\\b'
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-12-23 17:30:26 +00:00
|
|
|
class APTURLHandler(URLHandler):
|
|
|
|
"""APT URL handler. If there is a URL that looks like an apturl, handle
|
|
|
|
it appropriately"""
|
|
|
|
capabilities = ['url_handler']
|
|
|
|
handler_hane = 'apturl'
|
|
|
|
match = '\\bapt:.*\\b'
|
|
|
|
|
|
|
|
def callback(self, url):
|
|
|
|
"""Actually we don't need to do anything for this to work"""
|
|
|
|
return(url)
|
|
|
|
|