control: tags 863322 patch

On Thu, 25 May 2017 Nelson A. de Oliveira wrote:
> While filling a reportbug against wnpp and seleting RFA (package is
> pngnq) I got this:
> 
> =====
> Subject: RFA: pngnq -- 8dc4366236a6a8b60a7651dc12063d65
> Package: wnpp
> Severity: normal
> 
> I request an adopter for the pngnq package.
> 
> The package description is:
>  scope::utility, use::compressing, works-with-format::png,
>  works-with::image, works-with::image:raster
> =====
> 
> ie, the package description in "Subject" is wrong (it's using
> "Description-md5" instead the short description) and the description
> itself is using text from tags.

Thank you for the report. Attaching two patches. Both together should
fix this.
>From 924f153462f456840211ee6ba852a041156ffe02 Mon Sep 17 00:00:00 2001
From: Nis Martensen <nis.marten...@web.de>
Date: Fri, 26 May 2017 19:08:56 +0200
Subject: [PATCH 1/2] utils.get_package_status(): properly capture package
 description

The code trying to capture the package description has two issues:
 1. The regexp used for detecting the description field also matches on
    the Description-md5 field, which it should not.
 2. Lines starting with a space are assumed to belong to the long
    package description, even if they actually belong to another field
    listed after the description.

This can be fixed by only matching a Description field with alphabetic
characters before the colon, and a "descmode" similar to the already
existing "confmode" in the parser.
---
 reportbug/utils.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/reportbug/utils.py b/reportbug/utils.py
index e134bcd..5ff3dbe 100644
--- a/reportbug/utils.py
+++ b/reportbug/utils.py
@@ -338,7 +338,7 @@ def get_package_status(package, avail=False):
     statusre = re.compile('Status: ')
     originre = re.compile('Origin: ')
     bugsre = re.compile('Bugs: ')
-    descre = re.compile('Description(?:-.*)?: ')
+    descre = re.compile('Description(?:-[a-zA-Z]+)?: ')
     fullre = re.compile(' ')
     srcre = re.compile('Source: ')
     sectionre = re.compile('Section: ')
@@ -351,6 +351,7 @@ def get_package_status(package, avail=False):
     recommends = []
     suggests = []
     confmode = False
+    descmode = False
     state = ''
 
     try:
@@ -371,6 +372,12 @@ def get_package_status(package, avail=False):
         if not line:
             continue
 
+        if descmode:
+            if line[0] == ' ':
+                fulldesc.append(line)
+            else:
+                descmode = False
+
         if confmode:
             if line[:2] != ' /':
                 confmode = False
@@ -392,6 +399,7 @@ def get_package_status(package, avail=False):
             (crud, bugs) = line.split(": ", 1)
         elif descre.match(line):
             (crud, desc) = line.split(": ", 1)
+            descmode = True
         elif dependsre.match(line):
             (crud, thisdepends) = line.split(": ", 1)
             # Remove versioning crud
@@ -419,8 +427,6 @@ def get_package_status(package, avail=False):
             src_name = src_name.split()[0]
         elif sectionre.match(line):
             crud, section = line.split(": ", 1)
-        elif desc and line[0] == ' ':
-            fulldesc.append(line)
 
     installed = False
     if status:
-- 
2.1.4

>From d2604f7ea963ec6a2766c427c1e634a183bd96f8 Mon Sep 17 00:00:00 2001
From: Nis Martensen <nis.marten...@web.de>
Date: Fri, 26 May 2017 19:21:30 +0200
Subject: [PATCH 2/2] Use apt instead of dpkg for availability information

"dpkg --print-avail pkg-name" no longer shows the long package
description. Since we want it, so we must get it from somewhere else.
"apt-cache show pkg-name" provides it.

Also, man dpkg-query(1) says:

  Users of APT-based frontends should use "apt-cache show package-name"
  instead [of dpkg --print-avail package-name] as the available file is
  only kept up-to-date when using dselect.

Nowadays APT has many more users than dselect, according to
popcon.debian.org.
---
 reportbug/utils.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/reportbug/utils.py b/reportbug/utils.py
index 5ff3dbe..51c9d23 100644
--- a/reportbug/utils.py
+++ b/reportbug/utils.py
@@ -362,7 +362,7 @@ def get_package_status(package, avail=False):
     packarg = pipes.quote(package)
     if avail:
         output = get_command_output(
-            "COLUMNS=79 dpkg --print-avail %s 2>/dev/null" % packarg)
+            "apt-cache show %s 2>/dev/null" % packarg)
     else:
         output = get_command_output(
             "COLUMNS=79 dpkg --status %s 2>/dev/null" % packarg)
-- 
2.1.4

Reply via email to