]> git.decadent.org.uk Git - dak.git/blob - dakweb/queries/suite.py
Instead of doing our own (bad) help, simply use existing epydoc foo and redirect...
[dak.git] / dakweb / queries / suite.py
1 """ Suite related queries
2
3 @contact: Debian FTPMaster <ftpmaster@debian.org>
4 @copyright: 2014  Mark Hymers <mhy@debian.org>
5 @license: GNU General Public License version 2 or later
6
7 @newfield maps: Mapping, Mappings
8 """
9
10 import bottle
11 import json
12
13 from daklib.dbconn import DBConn, Suite
14 from dakweb.webregister import QueryRegister
15
16
17 @bottle.route('/suites')
18 def suites():
19     """
20     Give information about all known suites.
21
22     @maps: name maps to Suite: in the release file
23     @maps: codename maps to Codename: in the release file.
24     @maps: dakname is an internal name and should not be relied upon.
25
26     @rtype: list of dictionaries
27     @return: Dictionaries made out of
28              - name
29              - codename
30              - dakname
31              - archive
32              - architectures
33              - components
34
35     """
36
37     s = DBConn().session()
38     q = s.query(Suite)
39     q = q.order_by(Suite.suite_name)
40     ret = []
41     for p in q:
42         ret.append({'name':       p.release_suite_output,
43                     'codename':   p.codename,
44                     'dakname':    p.suite_name,
45                     'archive':    p.archive.archive_name,
46                     'architectures': [x.arch_string for x in p.architectures],
47                     'components': [x.component_name for x in p.components]})
48
49     s.close()
50
51     return json.dumps(ret)
52
53 QueryRegister().register_path('/suites', suites)
54
55 @bottle.route('/suite/<suite>')
56 def suite(suite=None):
57     """
58     Gives information about a single suite.  Note that this routine will look
59     up a suite first by the main suite_name, but then also by codename if no
60     suite is initially found.  It can therefore be used to canonicalise suite
61     names.
62
63     @type suite: string
64     @param suite: Name or codename of the suite.
65     @see: L{I{suites}<dakweb.queries.suite.suites>} on how to receive a list of valid suites.
66
67     @maps: name maps to Suite: in the release file
68     @maps: codename maps to Codename: in the release file.
69     @maps: dakname is an internal name and should not be relied upon.
70
71     @rtype: dictionary
72     @return: A dictionary of
73              - name
74              - codename
75              - dakname
76              - archive
77              - architectures
78              - components
79     """
80
81     if suite is None:
82         return bottle.HTTPError(503, 'Suite not specified.')
83
84     # TODO: We should probably stick this logic into daklib/dbconn.py
85     so = None
86
87     s = DBConn().session()
88     q = s.query(Suite)
89     q = q.filter(Suite.suite_name == suite)
90
91     if q.count() > 1:
92         # This would mean dak is misconfigured
93         s.close()
94         return bottle.HTTPError(503, 'Multiple suites found: configuration error')
95     elif q.count() == 1:
96         so = q[0]
97     else:
98         # Look it up by suite_name
99         q = s.query(Suite).filter(Suite.codename == suite)
100         if q.count() > 1:
101             # This would mean dak is misconfigured
102             s.close()
103             return bottle.HTTPError(503, 'Multiple suites found: configuration error')
104         elif q.count() == 1:
105             so = q[0]
106
107     if so is not None:
108         so = {'name':       so.release_suite_output,
109               'codename':   so.codename,
110               'dakname':    so.suite_name,
111               'archive':    so.archive.archive_name,
112               'architectures': [x.arch_string for x in so.architectures],
113               'components': [x.component_name for x in so.components]}
114
115     s.close()
116
117     return json.dumps(so)
118
119 QueryRegister().register_path('/suite', suite)