From 97edd822ef1738e396ca583adcd79d4251450034 Mon Sep 17 00:00:00 2001 From: Siegfried-Angel Gevatter Pujals Date: Tue, 29 Dec 2009 22:52:13 +0100 Subject: [PATCH 1/5] Recognize lp: links Initial attempt at fixing bug #501461, not working 100%. --- terminatorlib/terminatorterm.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/terminatorlib/terminatorterm.py b/terminatorlib/terminatorterm.py index 94a9cd50..1e9b0de0 100755 --- a/terminatorlib/terminatorterm.py +++ b/terminatorlib/terminatorterm.py @@ -381,10 +381,13 @@ class TerminatorTerm (gtk.VBox): url = 'ftp://' + url elif match == self.matches['addr_only']: url = 'http://' + url - elif match == self.matches['launchpad']: + elif match == self.matches['launchpad-bug']: for item in re.findall(r'[0-9]+',url): url = 'https://bugs.launchpad.net/bugs/%s' % item return url + elif match == self.matches['launchpad-branch']: + url = url[3:] if url.startswith('lp:') else url + url = 'https://code.launchpad.net/+branch/%s' % url elif match == self.matches['apturl']: # xdg-open will work as-is with apt: URLs pass @@ -634,8 +637,14 @@ text/plain self.matches['nntp'] = self._vte.match_add (lboundry + '''news:[-A-Z\^_a-z{|}~!"#$%&'()*+,./0-9;:=?`]+@[-A-Za-z0-9.]+(:[0-9]+)?''' + rboundry) # if the url looks like a Launchpad changelog closure entry LP: #92953 - make it a url to http://bugs.launchpad.net # the regular expression is similar to the perl one specified in the Ubuntu Policy Manual - /lp:\s+\#\d+(?:,\s*\#\d+)*/i - self.matches['launchpad'] = self._vte.match_add ('\\b(lp|LP):?\s?#?[0-9]+(,\s*#?[0-9]+)*\\b') - + self.matches['launchpad-bug'] = self._vte.match_add ('\\b(lp|LP):?\s?#?[0-9]+(,\s*#?[0-9]+)*\\b') + # if it looks like a Launchpad Bazaar branch, make it a url too + 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\.\-\+_@]+' + self.matches['launchpad-branch'] = self._vte.match_add ('\\b(lp|LP):(%(project)s(/%(series)s)?|%(group)s/%(project)s/%(branch)s)\\b' % lpfilters) self.matches['apturl'] = self._vte.match_add ('\\bapt.*\\b') def _path_lookup(self, command): From 9d49e9ade319e5173500e9ddc370257ec238f174 Mon Sep 17 00:00:00 2001 From: Siegfried-Angel Gevatter Pujals Date: Wed, 30 Dec 2009 01:46:38 +0100 Subject: [PATCH 2/5] Fix both problems my previous commit had, and fix some indenting issues in the code because of which LP URIs would not be recognized when the 'full_uri' regex is used (iiuc). --- terminatorlib/terminatorterm.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/terminatorlib/terminatorterm.py b/terminatorlib/terminatorterm.py index 1e9b0de0..5f1ab52b 100755 --- a/terminatorlib/terminatorterm.py +++ b/terminatorlib/terminatorterm.py @@ -635,17 +635,17 @@ text/plain self.matches['addr_only'] = self._vte.match_add (lboundry + "(www|ftp)[" + hostchars + "]*\.[" + hostchars + ".]+(:[0-9]+)?(" + urlpath + ")?" + rboundry + "/?") self.matches['email'] = self._vte.match_add (lboundry + "(mailto:)?[a-zA-Z0-9][a-zA-Z0-9.+-]*@[a-zA-Z0-9][a-zA-Z0-9-]*\.[a-zA-Z0-9][a-zA-Z0-9-]+[.a-zA-Z0-9-]*" + rboundry) self.matches['nntp'] = self._vte.match_add (lboundry + '''news:[-A-Z\^_a-z{|}~!"#$%&'()*+,./0-9;:=?`]+@[-A-Za-z0-9.]+(:[0-9]+)?''' + rboundry) - # if the url looks like a Launchpad changelog closure entry LP: #92953 - make it a url to http://bugs.launchpad.net - # the regular expression is similar to the perl one specified in the Ubuntu Policy Manual - /lp:\s+\#\d+(?:,\s*\#\d+)*/i - self.matches['launchpad-bug'] = self._vte.match_add ('\\b(lp|LP):?\s?#?[0-9]+(,\s*#?[0-9]+)*\\b') - # if it looks like a Launchpad Bazaar branch, make it a url too - 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\.\-\+_@]+' - self.matches['launchpad-branch'] = self._vte.match_add ('\\b(lp|LP):(%(project)s(/%(series)s)?|%(group)s/%(project)s/%(branch)s)\\b' % lpfilters) self.matches['apturl'] = self._vte.match_add ('\\bapt.*\\b') + # if the url looks like a Launchpad changelog closure entry LP: #92953 - make it a url to http://bugs.launchpad.net + # the regular expression is similar to the perl one specified in the Ubuntu Policy Manual - /lp:\s+\#\d+(?:,\s*\#\d+)*/i + self.matches['launchpad-bug'] = self._vte.match_add ('\\b(lp|LP):?\s?#?[0-9]+(,\s*#?[0-9]+)*\\b') + # same for Bazaar branches hosted on Launchpad + 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_+@.-]+' + self.matches['launchpad-branch'] = self._vte.match_add ('\\b((lp|LP):%(project)s(/%(series)s)?|(lp|LP):%(group)s/%(project)s/%(branch)s)\\b' % lpfilters) def _path_lookup(self, command): if os.path.isabs (command): From 708eaaa2a684f1af3411692d83abefa973cf734e Mon Sep 17 00:00:00 2001 From: Siegfried-Angel Gevatter Pujals Date: Wed, 30 Dec 2009 01:50:47 +0100 Subject: [PATCH 3/5] Undo my indentation changes, I misunderstood the code. --- terminatorlib/terminatorterm.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/terminatorlib/terminatorterm.py b/terminatorlib/terminatorterm.py index 5f1ab52b..1f200ecb 100755 --- a/terminatorlib/terminatorterm.py +++ b/terminatorlib/terminatorterm.py @@ -636,16 +636,16 @@ text/plain self.matches['email'] = self._vte.match_add (lboundry + "(mailto:)?[a-zA-Z0-9][a-zA-Z0-9.+-]*@[a-zA-Z0-9][a-zA-Z0-9-]*\.[a-zA-Z0-9][a-zA-Z0-9-]+[.a-zA-Z0-9-]*" + rboundry) self.matches['nntp'] = self._vte.match_add (lboundry + '''news:[-A-Z\^_a-z{|}~!"#$%&'()*+,./0-9;:=?`]+@[-A-Za-z0-9.]+(:[0-9]+)?''' + rboundry) self.matches['apturl'] = self._vte.match_add ('\\bapt.*\\b') - # if the url looks like a Launchpad changelog closure entry LP: #92953 - make it a url to http://bugs.launchpad.net - # the regular expression is similar to the perl one specified in the Ubuntu Policy Manual - /lp:\s+\#\d+(?:,\s*\#\d+)*/i - self.matches['launchpad-bug'] = self._vte.match_add ('\\b(lp|LP):?\s?#?[0-9]+(,\s*#?[0-9]+)*\\b') - # same for Bazaar branches hosted on Launchpad - 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_+@.-]+' - self.matches['launchpad-branch'] = self._vte.match_add ('\\b((lp|LP):%(project)s(/%(series)s)?|(lp|LP):%(group)s/%(project)s/%(branch)s)\\b' % lpfilters) + # if the url looks like a Launchpad changelog closure entry LP: #92953 - make it a url to http://bugs.launchpad.net + # the regular expression is similar to the perl one specified in the Ubuntu Policy Manual - /lp:\s+\#\d+(?:,\s*\#\d+)*/i + self.matches['launchpad-bug'] = self._vte.match_add ('\\b(lp|LP):?\s?#?[0-9]+(,\s*#?[0-9]+)*\\b') + # same for Bazaar branches hosted on Launchpad + 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_+@.-]+' + self.matches['launchpad-branch'] = self._vte.match_add ('\\b((lp|LP):%(project)s(/%(series)s)?|(lp|LP):%(group)s/%(project)s/%(branch)s)\\b' % lpfilters) def _path_lookup(self, command): if os.path.isabs (command): From b9805a5fbd91686f44524e607b2884c3b7136316 Mon Sep 17 00:00:00 2001 From: Siegfried-Angel Gevatter Pujals Date: Wed, 30 Dec 2009 02:02:42 +0100 Subject: [PATCH 4/5] Add support for +junk branches. --- terminatorlib/terminatorterm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminatorlib/terminatorterm.py b/terminatorlib/terminatorterm.py index 1f200ecb..8f674f29 100755 --- a/terminatorlib/terminatorterm.py +++ b/terminatorlib/terminatorterm.py @@ -645,7 +645,7 @@ text/plain lpfilters['group'] = '~%s' % lpfilters['project'] lpfilters['series'] = lpfilters['project'] lpfilters['branch'] = '[a-zA-Z0-9]{1}[a-zA-Z0-9_+@.-]+' - self.matches['launchpad-branch'] = self._vte.match_add ('\\b((lp|LP):%(project)s(/%(series)s)?|(lp|LP):%(group)s/%(project)s/%(branch)s)\\b' % lpfilters) + self.matches['launchpad-branch'] = self._vte.match_add ('\\b((lp|LP):%(project)s(/%(series)s)?|(lp|LP):%(group)s/(%(project)s|\+junk)/%(branch)s)\\b' % lpfilters) def _path_lookup(self, command): if os.path.isabs (command): From d82733d6a365343f6e884cc5c407d106135424ef Mon Sep 17 00:00:00 2001 From: Siegfried-Angel Gevatter Pujals Date: Wed, 30 Dec 2009 02:25:05 +0100 Subject: [PATCH 5/5] Improve the apturl regex to avoid bad matches. --- terminatorlib/terminatorterm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminatorlib/terminatorterm.py b/terminatorlib/terminatorterm.py index 8f674f29..a56474f0 100755 --- a/terminatorlib/terminatorterm.py +++ b/terminatorlib/terminatorterm.py @@ -635,7 +635,7 @@ text/plain self.matches['addr_only'] = self._vte.match_add (lboundry + "(www|ftp)[" + hostchars + "]*\.[" + hostchars + ".]+(:[0-9]+)?(" + urlpath + ")?" + rboundry + "/?") self.matches['email'] = self._vte.match_add (lboundry + "(mailto:)?[a-zA-Z0-9][a-zA-Z0-9.+-]*@[a-zA-Z0-9][a-zA-Z0-9-]*\.[a-zA-Z0-9][a-zA-Z0-9-]+[.a-zA-Z0-9-]*" + rboundry) self.matches['nntp'] = self._vte.match_add (lboundry + '''news:[-A-Z\^_a-z{|}~!"#$%&'()*+,./0-9;:=?`]+@[-A-Za-z0-9.]+(:[0-9]+)?''' + rboundry) - self.matches['apturl'] = self._vte.match_add ('\\bapt.*\\b') + self.matches['apturl'] = self._vte.match_add ('\\bapt:/?/?\w+\\b') # apt+http isn't supported # if the url looks like a Launchpad changelog closure entry LP: #92953 - make it a url to http://bugs.launchpad.net # the regular expression is similar to the perl one specified in the Ubuntu Policy Manual - /lp:\s+\#\d+(?:,\s*\#\d+)*/i self.matches['launchpad-bug'] = self._vte.match_add ('\\b(lp|LP):?\s?#?[0-9]+(,\s*#?[0-9]+)*\\b')