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 bottle.response.content_type = 'application/json; charset=UTF-8'
52 return json.dumps(ret)
53
54
55 QueryRegister().register_path('/suites', suites)
56
57
58 @bottle.route('/suite/<suite>')
59 -def suite(suite=None):
60 """
61 Gives information about a single suite. Note that this routine will look
62 up a suite first by the main suite_name, but then also by codename if no
63 suite is initially found. It can therefore be used to canonicalise suite
64 names.
65
66 @type suite: string
67 @param suite: Name or codename of the suite.
68 @see: L{I{suites}<dakweb.queries.suite.suites>} on how to receive a list of valid suites.
69
70 @maps: name maps to Suite: in the release file
71 @maps: codename maps to Codename: in the release file.
72 @maps: dakname is an internal name and should not be relied upon.
73
74 @rtype: dictionary
75 @return: A dictionary of
76 - name
77 - codename
78 - dakname
79 - archive
80 - architectures
81 - components
82 """
83
84 if suite is None:
85 return bottle.HTTPError(503, 'Suite not specified.')
86
87
88 so = None
89
90 s = DBConn().session()
91 q = s.query(Suite)
92 q = q.filter(Suite.suite_name == suite)
93
94 if q.count() > 1:
95
96 s.close()
97 return bottle.HTTPError(503, 'Multiple suites found: configuration error')
98 elif q.count() == 1:
99 so = q[0]
100 else:
101
102 q = s.query(Suite).filter(Suite.codename == suite)
103 if q.count() > 1:
104
105 s.close()
106 return bottle.HTTPError(503, 'Multiple suites found: configuration error')
107 elif q.count() == 1:
108 so = q[0]
109
110 if so is not None:
111 so = {'name': so.release_suite_output,
112 'codename': so.codename,
113 'dakname': so.suite_name,
114 'archive': so.archive.archive_name,
115 'architectures': [x.arch_string for x in so.architectures],
116 'components': [x.component_name for x in so.components]}
117
118 s.close()
119
120 bottle.response.content_type = 'application/json; charset=UTF-8'
121 return json.dumps(so)
122
123
124 QueryRegister().register_path('/suite', suite)
125