[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#833623: tracker.d.o: add multiarch hints



On Fri, 2016-08-26 at 11:35 +0200, Raphael Hertzog wrote:

> Has this been tested?

No, I lack any easy way to do that like I did with the PTS.

> Because I have reasons to believe that it doesn't work:

That is quite likely as it was just a first-pass.

> A function transforming severity name into severity value should really be
> implemented as class method in ActionItem directly (and it should have
> proper unit tests).

In this case they are different severity sets being transformed into
one another. There is the ActionItem set and the multiarch hints set.
Currently they match exactly but that might not always be the case.

> I would move the yaml parsing in get_data()

Done.

> That's the part that I would expect to fail with a KeyError. Here you
> really want to check that data['format'] is equal to
> 'multiarch-hints-1.0'. 

Fixed.

> That kind of initialization code can be avoided by defining packages as a
> collections.defaultdict(dict).
...
> packages[package].setdefault('hints', []).append(...)

Thanks for the hints, fixed.

> I don't think that your code can ever return "None" in get_packages()...

Fixed.

> The "severity" variable does not exist here, I assume you wanted to use
> data['severity'] instead.

Indeed, fixed.

> I obviously dislike the lack of unit tests but I would have merged it
> anyway if it's known to be working. But I don't think that this is the case
> currently.

If you are able to test the attached updated patch that would be
appreciated, I'm not able to at this point in time.

-- 
bye,
pabs

https://wiki.debian.org/PaulWise
From aec58e879e28f83ecbb76cf9cc916245703d6d16 Mon Sep 17 00:00:00 2001
From: Paul Wise <pabs@debian.org>
Date: Sun, 7 Aug 2016 14:46:36 +0800
Subject: [PATCH] Add multiarch hints

---
 .../debian/templates/debian/multiarch-hints.html   |  8 +++
 distro_tracker/vendor/debian/tracker_tasks.py      | 71 ++++++++++++++++++++++
 2 files changed, 79 insertions(+)
 create mode 100644 distro_tracker/vendor/debian/templates/debian/multiarch-hints.html

diff --git a/distro_tracker/vendor/debian/templates/debian/multiarch-hints.html b/distro_tracker/vendor/debian/templates/debian/multiarch-hints.html
new file mode 100644
index 0000000..d493ce6
--- /dev/null
+++ b/distro_tracker/vendor/debian/templates/debian/multiarch-hints.html
@@ -0,0 +1,8 @@
+<div>
+There are issues with the <a href="https://wiki.debian.org/MultiArch";>multiarch</a> metadata for this package.
+<ul>
+{% for desc, link in item.extra_data %}
+<li><a href="{{ link }}">{{ desc }}</a></li>
+{% endfor %}
+</ul>
+</div>
diff --git a/distro_tracker/vendor/debian/tracker_tasks.py b/distro_tracker/vendor/debian/tracker_tasks.py
index e142600..a0bfdb2 100644
--- a/distro_tracker/vendor/debian/tracker_tasks.py
+++ b/distro_tracker/vendor/debian/tracker_tasks.py
@@ -2371,3 +2371,74 @@ class UpdateBuildReproducibilityTask(BaseTask):
             ActionItem.objects.delete_obsolete_items([self.action_item_type],
                                                      packages)
             PackageExtractedInfo.objects.bulk_create(extracted_info)
+
+
+class MultiArchHintsTask(BaseTask):
+    ACTIONS_WEB = 'https://wiki.debian.org/MultiArch/Hints'
+    ACTIONS_URL = 'https://dedup.debian.net/static/multiarch-hints.yaml'
+    ACTION_ITEM_TYPE_NAME = 'debian-multiarch-hints'
+    ACTION_ITEM_TEMPLATE = 'debian/multiarch-hints.html'
+    ACTION_ITEM_DESCRIPTION = '<a href="{link}">Multiarch hinter</a> reports {count} issue(s)'
+
+    def __init__(self, force_update=False, *args, **kwargs):
+        super(MultiArchHintsTask, self).__init__(*args, **kwargs)
+        self.force_update = force_update
+        self.action_item_type = ActionItemType.objects.create_or_update(
+            type_name=self.ACTION_ITEM_TYPE_NAME,
+            full_description_template=self.ACTION_ITEM_TEMPLATE)
+        self.SEVERITIES = {}
+        for value, name in ActionItem.SEVERITIES:
+            self.SEVERITIES[name] = value
+
+    def set_parameters(self, parameters):
+        if 'force_update' in parameters:
+            self.force_update = parameters['force_update']
+
+    def get_data(self):
+        data = get_resource_content(self.ACTIONS_URL)
+        data = yaml.safe_load(data)
+        return data
+
+    def get_packages(self):
+        data = self.get_data()
+        if data['format'] != 'multiarch-hints-1.0':
+            return None
+        data = data['hints']
+        packages = collections.defaultdict(dict)
+        for item in data:
+            if 'source' not in item:
+                continue
+            package = item['source']
+            wishlist = ActionItem.SEVERITY_WISHLIST
+            severity = self.SEVERITIES.get(item['severity'], wishlist)
+            packages[package]['severity'] = max(severity, hints[package].get('severity', wishlist))
+            packages[package].setdefault('hints', []).append((item['description'], item['link']))
+        return packages
+
+    def update_action_item(self, package, severity, description, extra_data):
+        action_item = package.get_action_item_for_type(self.action_item_type.type_name)
+        if action_item is None:
+            action_item = ActionItem(
+                package=package,
+                item_type=self.action_item_type)
+        action_item.severity = severity
+        action_item.short_description = description
+        action_item.extra_data = extra_data
+        action_item.save()
+
+    def execute(self):
+        packages = self.get_packages()
+        if not packages:
+            return
+
+        with transaction.atomic():
+            for name, data in packages.items():
+                try:
+                    package = SourcePackageName.objects.get(name=name)
+                except SourcePackageName.DoesNotExist:
+                    continue
+
+                description = ACTION_ITEM_DESCRIPTION.format(count=len(data['hints']), link=self.ACTIONS_WEB)
+                self.update_action_item(package, data['severity'], description, data['hints'])
+
+            ActionItem.objects.delete_obsolete_items([self.action_item_type], packages.keys())
-- 
2.9.3

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: