]> git.decadent.org.uk Git - dak.git/blob - dakweb/queries/madison.py
023f67d03bcadd64475a0b9c738aa309cc408797
[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 b: only show info for a binary type. I{deb/udeb/dsc}
24     @keyword c: only show info for specified component(s). I{main/contrib/non-free}
25     @keyword s: only show info for this suite.
26     @keyword S: show info for the binary children of source pkgs. I{true/false}
27     @keyword f: output json format. I{json}
28     @see: L{I{suites}<dakweb.queries.suite.suites>} on how to receive a list of valid suites.
29
30     @rtype: text/plain or application/json
31     @return: Text or Json format of the data
32     """
33
34     r = bottle.request
35
36     packages = r.query.get('package', '').split()
37     kwargs = dict()
38
39     binary_type = r.query.get('b', None)
40     if binary_type is not None:
41         kwargs['binary_types'] = [binary_type]
42     component = r.query.get('c', None)
43     if component is not None:
44         kwargs['components'] = component.split(",")
45     suite = r.query.get('s', None)
46     if suite is not None:
47         kwargs['suites'] = suite.split(",")
48     if 'S' in r.query:
49         kwargs['source_and_binary'] = True
50     #if 'r' in r.query:
51     #    kwargs['regex'] = True
52     format = r.query.get('f', None)
53     if format is not None:
54         kwargs['format'] = 'python'
55
56     result = list_packages(packages, **kwargs)
57
58     if format is None:
59         bottle.response.content_type = 'text/plain'
60         for row in result:
61             yield row
62             yield "\n"
63     else:
64         yield json.dumps(list(result))
65
66
67 QueryRegister().register_path('/madison', madison)