Add initial support for changelog links for upgrade package diffs

definitely still just playing around so far...
This commit is contained in:
Lance Edgar 2017-08-13 00:24:58 -05:00
parent 4360d263e4
commit 55f96c4730
3 changed files with 25 additions and 2 deletions

View file

@ -35,11 +35,12 @@ class Diff(object):
Core diff class. In sore need of documentation.
"""
def __init__(self, old_data, new_data, columns=None, fields=None, render_value=None, monospace=False):
def __init__(self, old_data, new_data, columns=None, fields=None, render_field=None, render_value=None, monospace=False):
self.old_data = old_data
self.new_data = new_data
self.columns = columns or ["field name", "old value", "new value"]
self.fields = fields or self.make_fields()
self._render_field = render_field or self.render_field_default
self.render_value = render_value or self.render_value_default
self.monospace = monospace
@ -60,6 +61,12 @@ class Diff(object):
context['diff'] = self
return HTML.literal(render(template, context))
def render_field(self, field):
return self._render_field(field, self)
def render_field_default(self, field, diff):
return field
def render_value_default(self, field, value):
return repr(value)

View file

@ -10,7 +10,7 @@
<tbody>
% for field in diff.fields:
<tr${' class="diff"' if diff.values_differ(field) else ''|n}>
<td class="field">${field}</td>
<td class="field">${diff.render_field(field)}</td>
<td class="old-value">${diff.render_old_value(field)}</td>
<td class="new-value">${diff.render_new_value(field)}</td>
</tr>

View file

@ -204,6 +204,7 @@ class UpgradeView(MasterView):
after = self.parse_requirements(upgrade, 'after')
diff = self.make_diff(before, after,
columns=["package", "old version", "new version"],
render_field=self.render_diff_field,
render_value=self.render_diff_value,
)
showing = HTML.tag('div',
@ -216,6 +217,21 @@ class UpgradeView(MasterView):
except:
return "(not available for this upgrade)"
def render_diff_field(self, field, diff):
if field == 'rattail':
# TODO: use changelog from latest docs *unless* running from src
# url = 'https://rattailproject.org/buildbot/docs/rattail/changelog.html'
url = 'https://rattailproject.org/trac/log/rattail/?rev={}&stop_rev={}&limit=100'.format(
diff.new_value(field), diff.old_value(field))
return tags.link_to(field, url, target='_blank')
if field == 'Tailbone':
# TODO: use changelog from latest docs *unless* running from src
# url = 'https://rattailproject.org/buildbot/docs/tailbone/changelog.html'
url = 'https://rattailproject.org/trac/log/tailbone/?rev={}&stop_rev={}&limit=100'.format(
diff.new_value(field), diff.old_value(field))
return tags.link_to(field, url, target='_blank')
return field
def render_diff_value(self, field, value):
if value.startswith("u'") and value.endswith("'"):
return value[2:1]