]> git.decadent.org.uk Git - dak.git/blob - dakweb/queries/madison.py
dakweb: add -a option for madison
[dak.git] / dakweb / queries / madison.py
1 """ "Madison" interface
2
3 @contact: Debian FTPMaster <ftpmaster@debian.org>
4 @copyright: 2014  Ansgar Burchardt <ansgar@debian.org>
5 @copyright: 2014  Joerg Jaspert <joerg@debian.org>
6 @license: GNU General Public License version 2 or later
7 """
8
9 import bottle
10 import json
11
12 from daklib.ls import list_packages
13 from dakweb.webregister import QueryRegister
14
15 @bottle.route('/madison')
16 def madison():
17     """
18     Display information about B{package(s)}.
19
20     @since: December 2014
21
22     @keyword package: Space seperated list of packages.
23     @keyword a: only show info for specified architectures.
24     @keyword b: only show info for a binary type. I{deb/udeb/dsc}
25     @keyword c: only show info for specified component(s). I{main/contrib/non-free}
26     @keyword s: only show info for this suite.
27     @keyword S: show info for the binary children of source pkgs. I{true/false}
28     @keyword f: output json format. I{json}
29     @see: L{I{suites}<dakweb.queries.suite.suites>} on how to receive a list of valid suites.
30
31     @rtype: text/plain or application/json
32     @return: Text or Json format of the data
33     """
34
35     r = bottle.request
36
37     packages = r.query.get('package', '').split()
38     kwargs = dict()
39
40     architectures = r.query.get('a', None)
41     if architectures is not None:
42         kwargs['architectures'] = architectures.split(",")
43     binary_type = r.query.get('b', None)
44     if binary_type is not None:
45         kwargs['binary_types'] = [binary_type]
46     component = r.query.get('c', None)
47     if component is not None:
48         kwargs['components'] = component.split(",")
49     suite = r.query.get('s', None)
50     if suite is not None:
51         kwargs['suites'] = suite.split(",")
52     if 'S' in r.query:
53         kwargs['source_and_binary'] = True
54     #if 'r' in r.query:
55     #    kwargs['regex'] = True
56     format = r.query.get('f', None)
57     if format is not None:
58         kwargs['format'] = 'python'
59
60     result = list_packages(packages, **kwargs)
61
62     if format is None:
63         bottle.response.content_type = 'text/plain'
64         for row in result:
65             yield row
66             yield "\n"
67     else:
68         yield json.dumps(list(result))
69
70
71 QueryRegister().register_path('/madison', madison)