]> git.donarmstrong.com Git - dak.git/blob - dakweb/queries/suite.py
Add suite function
[dak.git] / dakweb / queries / suite.py
1 #!/usr/bin/python
2
3 import bottle
4 import json
5
6 from daklib.dbconn import DBConn, Suite
7 from dakweb.webregister import QueryRegister
8
9 @bottle.route('/suites')
10 def suites():
11     """
12     suites()
13
14     returns: list of dictionaries
15
16     Give information about all known suites
17     """
18
19     s = DBConn().session()
20     q = s.query(Suite)
21     q = q.order_by(Suite.suite_name)
22     ret = []
23     for p in q:
24         ret.append({'name':       p.suite_name,
25                     'codename':   p.codename,
26                     'archive':    p.archive.archive_name,
27                     'architectures': [x.arch_string for x in p.architectures],
28                     'components': [x.component_name for x in p.components]})
29
30     return json.dumps(ret)
31
32 QueryRegister().register_path('/suites', suites)
33
34 @bottle.route('/suite/<suite>')
35 def suite(suite=None):
36     """
37     suite(suite)
38
39     returns: dictionary
40
41     Gives information about a single suite.  Note that this routine will look
42     up a suite first by the main suite_name, but then also by codename if no
43     suite is initially found.  It can therefore be used to canonicalise suite
44     names
45     """
46
47     if suite is None:
48         return bottle.HTTPError(503, 'Suite not specified.')
49
50     # TODO: We should probably stick this logic into daklib/dbconn.py
51     so = None
52
53     s = DBConn().session()
54     q = s.query(Suite)
55     q = q.filter(Suite.suite_name == suite)
56
57     if q.count() > 1:
58         # This would mean dak is misconfigured
59         return bottle.HTTPError(503, 'Multiple suites found: configuration error')
60     elif q.count() == 1:
61         so = q[0]
62     else:
63         # Look it up by suite_name
64         q = s.query(Suite).filter(Suite.codename == suite)
65         if q.count() > 1:
66             # This would mean dak is misconfigured
67             return bottle.HTTPError(503, 'Multiple suites found: configuration error')
68         elif q.count() == 1:
69             so = q[0]
70
71     if so is not None:
72         so = {'name':       so.suite_name,
73               'codename':   so.codename,
74               'archive':    so.archive.archive_name,
75               'architectures': [x.arch_string for x in so.architectures],
76               'components': [x.component_name for x in so.components]}
77
78     return json.dumps(so)
79
80 QueryRegister().register_path('/suite', suite)
81