From 6a30a44f8da256d9bd144c5ed1651b248abe191f Mon Sep 17 00:00:00 2001 From: skyjake Date: Thu, 5 Jan 2012 07:56:01 +0200 Subject: [PATCH] Builder: More readable RSS feed commit list Attempting to make the list more readable by grouping commits and simplifying the output. --- distrib/builder/changes.py | 72 ++++++++++++++++++++++---------------- distrib/builder/event.py | 2 +- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/distrib/builder/changes.py b/distrib/builder/changes.py index f711442440..b05e7b5209 100644 --- a/distrib/builder/changes.py +++ b/distrib/builder/changes.py @@ -139,13 +139,14 @@ def parse(self): self.deduce_tags() def all_tags(self): - tags = ['Cleanup', 'Fixed', 'Added', 'Refactor', 'Performance', 'Optimize'] + # These words are always considered to be valid tags. + tags = ['Cleanup', 'Fixed', 'Added', 'Refactor', 'Performance', 'Optimize', 'merge branch'] for e in self.entries: for t in e.tags + e.guessedTags: if t not in tags: tags.append(t) return tags - + def deduce_tags(self): # Look for known tags in untagged titles. allTags = self.all_tags() @@ -153,9 +154,40 @@ def deduce_tags(self): if entry.tags: continue # This entry has no tags yet. for tag in allTags: - if tag.lower() in entry.subject.lower(): + p = entry.subject.lower().find(tag.lower()) + if p < 0: continue + if p == 0 or entry.subject[p - 1] not in string.ascii_letters + '-_': entry.guessedTags.append(tag) + def form_groups(self, allEntries): + groups = {} + for tag in self.all_tags(): + groups[tag] = [] + for e in allEntries: + if tag in e.tags: + groups[tag].append(e) + for e in allEntries: + if tag in e.guessedTags: + groups[tag].append(e) + + for e in groups[tag]: + allEntries.remove(e) + + groups['Miscellaneous'] = [] + for e in allEntries: + groups['Miscellaneous'].append(e) + + return groups + + def pretty_group_list(self, tags): + listed = '' + if len(tags) > 1: + listed = string.join(tags[:-1], ', ') + listed += ' and ' + tags[-1] + elif len(tags) == 1: + listed = tags[0] + return listed + def generate(self, format): fromTag = self.fromTag toTag = self.toTag @@ -172,24 +204,9 @@ def generate(self, format): (self.entries[-1].link, self.entries[-1].date) # Form groups. - groups = {} - for tag in self.all_tags(): - groups[tag] = [] - for e in entries: - if tag in e.tags: - groups[tag].append(e) - for e in entries: - if tag in e.guessedTags: - groups[tag].append(e) - - for e in groups[tag]: - entries.remove(e) - - groups['Other'] = [] - for e in entries: - groups['Other'].append(e) - + groups = self.form_groups(entries) keys = groups.keys() + # Sort case-insensitively by group name. keys.sort(cmp=lambda a, b: cmp(str(a).lower(), str(b).lower())) for group in keys: if not len(groups[group]): continue @@ -203,19 +220,14 @@ def generate(self, format): for tag in entry.tags + entry.guessedTags: if tag != group: otherGroups.append(tag) - others = '' - if len(otherGroups) > 1: - others = string.join(otherGroups[:-1], ', ') - others += ' and ' + otherGroups[-1] - elif len(otherGroups) == 1: - others = otherGroups[0] - + + others = self.pretty_group_list(otherGroups) if others: others = ' (also %s)' % others - print >> out, '
  • %s%s
    ' % (entry.subject, others) + print >> out, '
  • %s%s' % (entry.subject, others) print >> out, 'by %s on ' % entry.author print >> out, '%s' % (entry.link, entry.date) - print >> out, '
    %s
    ' % entry.message + print >> out, '
    %s
    ' % entry.message print >> out, '' out.close() @@ -233,7 +245,7 @@ def generate(self, format): if entry.tags or entry.guessedTags: print >> out, '' for t in entry.tags: - print >> out, '%s' % t + print >> out, '%s' % t for t in entry.guessedTags: print >> out, '%s' % t print >> out, '' diff --git a/distrib/builder/event.py b/distrib/builder/event.py index 534c51353c..7209aaa2ec 100644 --- a/distrib/builder/event.py +++ b/distrib/builder/event.py @@ -249,7 +249,7 @@ def html_description(self, encoded=True): chgFn = self.file_path('changes.html') if os.path.exists(chgFn): if utils.count_word('
  • ', file(chgFn).read()): - msg += '

    Commits

    ' + file(chgFn, 'rt').read() + msg += '

    Commits

    ' + file(chgFn, 'rt').read() # Enclose it in a CDATA block if needed. if encoded: return ''