]> git.decadent.org.uk Git - dak.git/blob - dakweb/queries/madison.py
Not nice, but some doc
[dak.git] / dakweb / queries / madison.py
1 import bottle
2 import json
3
4 from daklib.ls import list_packages
5 from dakweb.webregister import QueryRegister
6
7 @bottle.route('/madison')
8 def madison():
9     """
10     Display information about packages.
11
12     b=TYPE      only show info for binary TYPE
13     c=COMPONENT only show info for COMPONENT(s)
14     s=SUITE     only show info for this suite
15     S=true      show info for the binary children of source pkgs
16     f=json      output json format
17     """
18
19     r = bottle.request
20
21     packages = r.query.get('package', '').split()
22     kwargs = dict()
23
24     binary_type = r.query.get('b', None)
25     if binary_type is not None:
26         kwargs['binary_types'] = [binary_type]
27     component = r.query.get('c', None)
28     if component is not None:
29         kwargs['components'] = component.split(",")
30     suite = r.query.get('s', None)
31     if suite is not None:
32         kwargs['suites'] = suite.split(",")
33     if 'S' in r.query:
34         kwargs['source_and_binary'] = True
35     #if 'r' in r.query:
36     #    kwargs['regex'] = True
37     format = r.query.get('f', None)
38     if format is not None:
39         kwargs['format'] = 'python'
40
41     result = list_packages(packages, **kwargs)
42
43     if format is None:
44         bottle.response.content_type = 'text/plain'
45         for row in result:
46             yield row
47             yield "\n"
48     else:
49         yield json.dumps(list(result))
50
51
52 QueryRegister().register_path('/madison', madison)