X-Git-Url: http://git.veekun.com/zzz-spline-frontpage.git/blobdiff_plain/3e28142ab39f3b4f3080c8e55c76a66d8134bf66..9ea92c689c57bd114c09147238dd3f478c1b05c6:/splinext/frontpage/sources.py diff --git a/splinext/frontpage/sources.py b/splinext/frontpage/sources.py index eaefc57..a65e3e8 100644 --- a/splinext/frontpage/sources.py +++ b/splinext/frontpage/sources.py @@ -4,8 +4,10 @@ implementations. from collections import namedtuple import datetime +import re import subprocess from subprocess import PIPE +from urllib2 import URLError import feedparser import lxml.html @@ -161,6 +163,11 @@ class FeedSource(CachedSource): def _poll(self, limit, max_age): feed = feedparser.parse(self.feed_url) + if feed.bozo and isinstance(feed.bozo_exception, URLError): + # Feed is DOWN. Bail here; otherwise, old entries might be lost + # just because, say, Bulbanews is down yet again + raise feed.bozo_exception + if not self.title: self.title = feed.feed.title @@ -229,7 +236,7 @@ class FeedSource(CachedSource): FrontPageGit = namedtuple('FrontPageGit', ['source', 'time', 'log', 'tag']) FrontPageGitCommit = namedtuple('FrontPageGitCommit', - ['hash', 'author', 'time', 'subject', 'repo']) + ['hash', 'author', 'email', 'time', 'subject', 'repo']) class GitSource(CachedSource): """Represents a git repository. @@ -254,13 +261,20 @@ class GitSource(CachedSource): Base URL to a gitweb installation, so commit ids can be linked to the commit proper. + ``bug_tracker`` + URL to a bug tracker; anything matching "#xxx" will be converted into a + link to this. Should contain a "{0}", which will be replaced by the + bug number. + ``tag_pattern`` Optional. A shell glob pattern used to filter the tags. """ template = '/front_page/git.mako' - def __init__(self, repo_paths, repo_names, gitweb, tag_pattern=None, **kwargs): + def __init__(self, repo_paths, repo_names, gitweb, bug_tracker=None, + tag_pattern=None, **kwargs): + kwargs.setdefault('title', None) super(GitSource, self).__init__(**kwargs) @@ -269,6 +283,7 @@ class GitSource(CachedSource): self.repo_names = repo_names.split() self.gitweb = gitweb + self.bug_tracker = bug_tracker self.tag_pattern = tag_pattern def _cache_key(self): @@ -322,16 +337,25 @@ class GitSource(CachedSource): 'git', '--git-dir=' + repo_path, 'log', - '--pretty=%h%x00%an%x00%at%x00%s', + '--pretty=%h%x00%an%x00%aE%x00%at%x00%s', "{0}..{1}".format(since_tag, tag), ] proc = subprocess.Popen(git_log_args, stdout=PIPE) for line in proc.stdout: - hash, author, time, subject = line.strip().split('\x00') + hash, author, email, time, subject \ + = line.strip().decode('utf8').split('\x00') + + # Convert bug numbers in subject to URLs + if self.bug_tracker: + subject = helpers.literal( + re.sub(u'#(\d+)', self._linkify_bug_number, subject) + ) + commits.append( FrontPageGitCommit( hash = hash, author = author, + email = email, time = datetime.datetime.fromtimestamp(int(time)), subject = subject, repo = repo_name, @@ -347,3 +371,10 @@ class GitSource(CachedSource): updates.append(update) return updates + + def _linkify_bug_number(self, match): + """Regex replace function for changing bug numbers into links.""" + n = match.group(1) + bug_url = self.bug_tracker.format(match.group(1)) + return helpers.literal( + u"""{1}""".format(bug_url, match.group(0)))