Bug#647565: madison.cgi: make it produce an easier to parse output
Sandro Tosi schrieb am Wednesday, den 09. November 2011:
> On Wed, Nov 9, 2011 at 12:48, Jakub Wilk <jwilk@debian.org> wrote:
> > Hi Sandro,
> >
> > * Sandro Tosi <morph@debian.org>, 2011-11-04, 00:41:
> >>
> >> currently madison.cgi (and it's rmadison command friend) doesn't emit an
> >> easy-to-parse output: please enable it. yaml, whatever that's easy from a
> >> programming language to parse and understand.
> >
> > Why parsing the current output is hard?
>
> It's not hard, but it's not even that much easily machine parsable as
> some other formats. Also, every clients needing to parse information,
> needs to implement its own parser, instead of getting data alraedy
> structurated.
>
> It's not i'm stuck if this is not fixed, the parser it's at [1], still
> I won't call it that optimal.
You may want to try the attached patch for madison.cgi. It adds a yaml parameter which produces an output like:
perl madison.cgi package=keepalived yaml=1
Content-Type: text/plain
---
keepalived:
1:1.1.20-1:
squeeze:
- source
- amd64
- armel
- i386
- ia64
- mips
- mipsel
- powerpc
- s390
- sparc
1:1.2.2-1:
sid:
- source
- amd64
- armel
- i386
- ia64
- mips
- mipsel
- powerpc
- s390
- sparc
wheezy:
- source
- amd64
- armel
- i386
- ia64
- mips
- mipsel
- powerpc
- s390
- sparc
Adding other formats like json would be trivial (I just need the relevant libs like libjson-perl installed on quantz).
Alex
--- /org/qa.debian.org/cgi-bin/madison.cgi 2011-09-23 08:09:43.594864460 +0000
+++ madison.cgi 2011-11-09 22:10:18.648982078 +0000
@@ -19,6 +19,7 @@
use DBI;
use List::Util qw(max);
use Dpkg::Version qw(version_compare);
+use YAML::Syck qw (Dump);
my $query = new CGI;
my $distribution = 'debian';
@@ -77,7 +78,8 @@
%s IN (%s)"
;
-if ($query->param('text')) {
+my $nomarkup = ( $query->param('yaml') or $query->param('text') ) ? 1 : 0;
+if ($query->param('text') or $query->param('yaml')) {
print "Content-Type: text/plain\n\n";
} else {
print "Content-Type: text/html\n\n";
@@ -225,10 +227,11 @@
}
+
if ($query->param('package') and $query->param('package') =~ /$token_list/io) {
my $packages = split_n_prep($1);
- if (!$query->param('text')) {
+ if (!$nomarkup) {
print "<h2>dak ls</h2>\n";
print("<pre>\n");
}
@@ -284,6 +287,10 @@
push @{$data{$d->{'package'}}{$d->{'version'}}{$d->{'release'}}}, $d->{'architecture'};
}
+ if (defined($query->param('yaml'))) {
+ print Dump(\%data);
+ exit;
+ }
my $format = " %-$maxl{package}s | %-$maxl{version}s | %-$maxl{release}s | %s\n";
# Output is sorted by:
@@ -314,12 +321,12 @@
}
}
- if (!$query->param('text')) {
+ if (!$nomarkup) {
print "</pre>\n";
}
}
-exit if ($query->param('text'));
+exit if ($nomarkup);
print "<p>
<form action=\"#\" method=\"get\">
Reply to: