~ubuntu-branches/ubuntu/saucy/terminator/saucy

« back to all changes in this revision

Viewing changes to terminatorlib/plugins/url_handlers.py

  • Committer: Bazaar Package Importer
  • Author(s): Nicolas Valcárcel Scerpella (Canonical)
  • Date: 2010-04-07 17:10:31 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100407171031-35nsuj0tmbub0bj5
Tags: 0.92-0ubuntu1
* New upstream release
* Remove python-xdg from Recommends. (Closes: #567967)
* Downgrade python-gnome2 to Recommends.
* Update python-gtk2 dependency to (>= 2.14.0)
* Add python-keybinder to Recommends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Terminator by Chris Jones <cmsj@tenshu.net?
 
2
# GPL v2 only
 
3
"""url_handlers.py - Default plugins for URL handling"""
 
4
import re
 
5
import terminatorlib.plugin as plugin
 
6
 
 
7
# Every plugin you want Terminator to load *must* be listed in 'available'
 
8
available = ['LaunchpadBugURLHandler', 'LaunchpadCodeURLHandler', 'APTURLHandler']
 
9
 
 
10
class LaunchpadBugURLHandler(plugin.URLHandler):
 
11
    """Launchpad Bug URL handler. If the URL looks like a Launchpad changelog
 
12
    closure entry... 'LP: #12345' then it should be transformed into a 
 
13
    Launchpad Bug URL"""
 
14
    capabilities = ['url_handler']
 
15
    handler_name = 'launchpad_bug'
 
16
    match = '\\b(lp|LP):?\s?#?[0-9]+(,\s*#?[0-9]+)*\\b'
 
17
 
 
18
    def callback(self, url):
 
19
        """Look for the number in the supplied string and return it as a URL"""
 
20
        for item in re.findall(r'[0-9]+', url):
 
21
            url = 'https://bugs.launchpad.net/bugs/%s' % item
 
22
            return(url)
 
23
 
 
24
class LaunchpadCodeURLHandler(plugin.URLHandler):
 
25
    """Launchpad Code URL handler. If the URL looks like a Launchpad project or
 
26
    branch entry then it should be transformed into a code.launchpad.net URL"""
 
27
    capabilities = ['url_handler']
 
28
    handler_name = 'launchpad_code'
 
29
    lpfilters = {}
 
30
    lpfilters['project'] = '[a-z0-9]{1}[a-z0-9\.\-\+]+'
 
31
    lpfilters['group'] = '~%s' % lpfilters['project']
 
32
    lpfilters['series'] = lpfilters['project']
 
33
    lpfilters['branch'] = '[a-zA-Z0-9]{1}[a-zA-Z0-9_+@.-]+'
 
34
 
 
35
    match = '\\b((lp|LP):%(project)s(/%(series)s)?|(lp|LP):%(group)s/(%(project)s|\+junk)/%(branch)s)\\b' % lpfilters
 
36
 
 
37
    def callback(self, url):
 
38
        """Look for the number in the supplied string and return it as a URL"""
 
39
        if url.startswith('lp:'):
 
40
            url = url[3:]
 
41
        return('https://code.launchpad.net/+branch/%s' % url)
 
42
 
 
43
class APTURLHandler(plugin.URLHandler):
 
44
    """APT URL handler. If there is a URL that looks like an apturl, handle
 
45
    it appropriately"""
 
46
    capabilities = ['url_handler']
 
47
    handler_name = 'apturl'
 
48
    match = '\\bapt:.*\\b'
 
49
 
 
50
    def callback(self, url):
 
51
        """Actually we don't need to do anything for this to work"""
 
52
        return(url)
 
53