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

Bug#753733: tracker.debian.org: Learn about auto-removals



The previous patch missed checking if get_resource_content returns data.

Sorry for the noise,
Christophe
>From fbdb2bfecaeddfde68035282de04676195e1108a Mon Sep 17 00:00:00 2001
From: Christophe Siraut <d@tobald.eu.org>
Date: Mon, 18 Aug 2014 16:57:25 +0200
Subject: [PATCH] Add an action item for auto-removals

---
 .../templates/debian/autoremoval-action-item.html  | 23 ++++++
 distro_tracker/vendor/debian/tracker_tasks.py      | 84 ++++++++++++++++++++++
 2 files changed, 107 insertions(+)
 create mode 100644 distro_tracker/vendor/debian/templates/debian/autoremoval-action-item.html

diff --git a/distro_tracker/vendor/debian/templates/debian/autoremoval-action-item.html b/distro_tracker/vendor/debian/templates/debian/autoremoval-action-item.html
new file mode 100644
index 0000000..e0d8752
--- /dev/null
+++ b/distro_tracker/vendor/debian/templates/debian/autoremoval-action-item.html
@@ -0,0 +1,23 @@
+{% spaceless %}
+{% with bugs=item.extra_data.bugs %}
+{% with bugs_dependencies=item.extra_data.bugs_dependencies %}
+{% with buggy_dependencies=item.extra_data.buggy_dependencies %}
+
+<div>
+    <span>Version {{ item.extra_data.version }} of {{ item.package.name }} is marked for autoremoval from testing on {{ item.extra_data.removal_date }}. </span>
+
+    {% if bugs %}
+    <span>It is affected by {{ bugs|safe }}. </span>
+    {% endif %}  
+
+    {% if bugs_dependencies %}
+    <span>It depends (transitively) on {{ buggy_dependencies|safe }}, affected by {{ bugs_dependencies|safe }}. </span>
+    {% endif %}  
+
+    </span>You should try to prevent the removal by fixing these RC bugs.</span>
+</div>
+
+{% endwith %}
+{% endwith %}
+{% endwith %}
+{% endspaceless %}
diff --git a/distro_tracker/vendor/debian/tracker_tasks.py b/distro_tracker/vendor/debian/tracker_tasks.py
index 920ac62..06428c0 100644
--- a/distro_tracker/vendor/debian/tracker_tasks.py
+++ b/distro_tracker/vendor/debian/tracker_tasks.py
@@ -1686,6 +1686,90 @@ class UpdateUbuntuStatsTask(BaseTask):
                     patch_diff=diff)
 
 
+class UpdateAutoRemovalsStatsTask(BaseTask):
+    """
+    A task for updating autoremovals information on all packages.
+    """
+    ACTION_ITEM_TYPE_NAME = 'debian-autoremoval'
+    ACTION_ITEM_TEMPLATE = 'debian/autoremoval-action-item.html'
+    ITEM_DESCRIPTION = 'Marked for autoremoval on {removal_date}: {bugs}'
+
+    def __init__(self, force_update=False, *args, **kwargs):
+        super(UpdateAutoRemovalsStatsTask, 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)
+
+    def set_parameters(self, parameters):
+        if 'force_update' in parameters:
+            self.force_update = parameters['force_update']
+
+    def get_autoremovals_stats(self):
+        """
+        Retrieves and parses the autoremoval stats for all packages.
+        Autoremoval stats include the BTS bugs id.
+
+        :returns: A dict mapping package names to autoremoval stats.
+        """
+        content = get_resource_content(
+            'http://udd.debian.org/cgi-bin/autoremovals.yaml.cgi')
+        if content:
+            return yaml.safe_load(six.BytesIO(content))
+
+    def update_action_item(self, package, stats):
+        """
+        Creates an :class:`ActionItem <distro_tracker.core.models.ActionItem>`
+        instance for the given type indicating that the package has an
+        autoremoval issue.
+        """
+        action_item = package.get_action_item_for_type(self.action_item_type)
+        if not action_item:
+            action_item = ActionItem(
+                package=package,
+                item_type=self.action_item_type)
+
+        bugs_dependencies, buggy_dependencies = [], []
+        if 'bugs_dependencies' in stats:
+            bugs_dependencies = stats['bugs_dependencies']
+        if 'buggy_dependencies' in stats:
+            buggy_dependencies = stats['buggy_dependencies']
+        all_bugs = stats['bugs'] + bugs_dependencies
+        link = '<a href="http://bugs.debian.org/{}";>{}</a>'
+
+        action_item.short_description = self.ITEM_DESCRIPTION.format(
+            removal_date=stats['removal_date'].strftime('%d %B'),
+            bugs=', '.join(link.format(bug, bug) for bug in all_bugs))
+
+        action_item.extra_data = {
+            'stats': stats,
+            'removal_date': stats['removal_date'].strftime('%a %d %b %Y'),
+            'bugs': ', '.join(link.format(bug, bug) for bug in stats['bugs']),
+            'bugs_dependencies': ', '.join(
+                link.format(bug, bug) for bug in bugs_dependencies),
+            'buggy_dependencies': ' and '.join(
+                ['<a href="/pkg/{}">{}</a>'.format(p, p)
+                 for p in buggy_dependencies])
+        }
+        action_item.save()
+
+    def execute(self):
+        autoremovals_stats = self.get_autoremovals_stats()
+        if autoremovals_stats is None:
+            # Nothing to do: cached content up to date
+            return
+
+        ActionItem.objects.delete_obsolete_items(
+            item_types=[self.action_item_type],
+            non_obsolete_packages=autoremovals_stats.keys())
+
+        packages = SourcePackageName.objects.filter(name__in=autoremovals_stats.keys())
+        packages = packages.prefetch_related('action_items')
+
+        for package in packages:
+            self.update_action_item(package, autoremovals_stats[package.name])
+
+
 class UpdateWnppStatsTask(BaseTask):
     """
     The task updates the WNPP bugs for all packages.
-- 
2.0.1


Reply to: