Commit 221be7b3 authored by Raphaël Hertzog's avatar Raphaël Hertzog

Merge branch 'fix_excuses' into 'master'

Fix excuses behaviour See merge request !29
parents da243bc3 e22f673a
Pipeline #6420 passed with stages
in 12 minutes 12 seconds
......@@ -780,7 +780,11 @@ class PackageUtilsTests(SimpleTestCase):
def test_html_package_list(self):
"""Tests the output of html_package_list function"""
list_of_packages = ['dummy-package', 'other-dummy-package']
list_of_packages = [
'dummy-package',
'other-dummy-package',
'last-dummy-package/amd64',
]
output = html_package_list(list_of_packages)
......@@ -794,11 +798,17 @@ class PackageUtilsTests(SimpleTestCase):
'other-dummy-package',
)
third_url = '<a href="%s">%s</a>/amd64' % (
package_url('last-dummy-package'),
'last-dummy-package',
)
self.assertEqual(
output,
"%s, %s" % (
"%s, %s, %s" % (
first_url,
second_url,
third_url,
),
)
......
......@@ -706,8 +706,13 @@ class AptCache(object):
def html_package_list(packages):
packages_html = []
for package in packages:
html = '<a href="{}">{}</a>'.format(
package_url(package), package)
if "/" in package:
(source_package_name, remain) = package.split("/", 1)
remain = "/%s" % (remain,)
else:
(source_package_name, remain) = (package, "")
html = '<a href="{}">{}</a>{}'.format(
package_url(source_package_name), source_package_name, remain)
packages_html.append(html)
return ', '.join(packages_html)
......@@ -851,6 +851,30 @@ class UpdateExcusesTask(BaseTask):
if verdict == self.AgeVerdict.PKG_TOO_OLD:
return (source['item-name'], {'age': age, 'limit': limit})
@staticmethod
def _make_excuses_check_dependencies(source):
"""Checks the dependencies of the package (blocked-by and
migrate-after) and returns a list to display."""
addendum = []
if 'dependencies' in source:
blocked_by = source['dependencies'].get('blocked-by', [])
after = source['dependencies'].get('migrate-after', [])
after = [
element
for element in after
if element not in blocked_by
]
addendum.append("Blocked by: %s" % (
html_package_list(blocked_by),
))
addendum.append("Migrates after: %s" % (
html_package_list(after),
))
return addendum
@staticmethod
def _make_excuses_check_verdict(source):
"""Checks the migration policy verdict of the package and builds an
......@@ -861,20 +885,10 @@ class UpdateExcusesTask(BaseTask):
if 'migration-policy-verdict' in source:
verdict = source['migration-policy-verdict']
if verdict == 'REJECTED_BLOCKED_BY_ANOTHER_ITEM':
addendum.append((
"Migration status: Blocked. Can't migrate due to a "
"non-migrable dependency. Check status below."
))
if 'dependencies' in source:
blocked_by = source['dependencies'].get('blocked-by', [])
after = source['dependencies'].get('migrate-after', [])
deps = list({
element
for element in blocked_by + after
})
addendum.append("Blocked by: %s" % (
html_package_list(deps),
))
addendum.append("Migration status: Blocked. Can't migrate "
"due to a non-migrable dependency. Check "
"status below."
)
return addendum
......@@ -916,6 +930,7 @@ class UpdateExcusesTask(BaseTask):
addendum = []
addendum.extend(self._make_excuses_check_verdict(source))
addendum.extend(self._make_excuses_check_dependencies(source))
addendum.extend(self._make_excuses_check_age(source))
excuses = addendum + excuses
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment