On Thu, Nov 3, 2011 at 7:41 PM, Sandro Tosi <mo...@debian.org> wrote: > Package: qa.debian.org > Severity: normal > > Hello, > currently madison.cgi (and it's rmadison command friend) doesn't emit an > easy-to-parse output: please enable it. Something like xml, json, yaml, > whatever > that's easy from a programming language to parse and understand.
I'd kindly invite you to reconsider that - as far as this stuff goes, that's much easier for a machine to parse then JSON, YAML or XML. However, I can understand why you'd need that, for instance if you don't want to write your own parser. It's early-o-clock here, but I whipped up a script in python for you, that will take stdin from rmadion and translate it to JSON. Keep in mind, it's early, I don't have coffee and I spent about 4 minutes on this. If there are bugs, I'll try to fix them when I have some time, but I can't be supporting this mess. Debts payable in Scotch. Find script attached, Cheers (and good luck) -Paul > > Regards, > Sandro > > -- System Information: > Debian Release: wheezy/sid > APT prefers unstable > APT policy: (500, 'unstable'), (1, 'experimental') > Architecture: amd64 (x86_64) > > Kernel: Linux 3.0.0-1-amd64 (SMP w/4 CPU cores) > Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) > Shell: /bin/sh linked to /bin/bash > > > > -- > To UNSUBSCRIBE, email to debian-qa-requ...@lists.debian.org > with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org > Archive: > http://lists.debian.org/20111103234109.22862.54402.report...@zion.matrix.int > > -- All programmers are playwrights, and all computers are lousy actors. #define sizeof(x) rand() :wq
#!/usr/bin/env python import json import sys routput = sys.stdin.read().split('\n') info_order = [ "pkg", "version", "suite", "arches" ] key_fld = 2 # suite arch_fld = 3 output = {} for line in routput: if line == "": break; information = line.split("|") parse = {} for i in range(len(info_order)): information[i] = information[i].strip() if i == arch_fld: information[i] = information[i].split(", ") parse[info_order[i]] = information[i] output[information[key_fld]] = information print output