1"""Suite related queries
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
7@newfield maps: Mapping, Mappings
8"""
10import json
11from typing import Optional
13import bottle
15from daklib.dbconn import DBConn, Suite
16from dakweb.webregister import QueryRegister
19@bottle.route("/suites")
20def suites() -> str:
21 """
22 Give information about all known suites.
24 @maps: name maps to Suite: in the release file
25 @maps: codename maps to Codename: in the release file.
26 @maps: dakname is an internal name and should not be relied upon.
28 :return: List of dictionaries made out of
29 - name
30 - codename
31 - dakname
32 - archive
33 - architectures
34 - components
36 """
38 s = DBConn().session()
39 q = s.query(Suite)
40 q = q.order_by(Suite.suite_name)
41 ret = []
42 for p in q:
43 ret.append(
44 {
45 "name": p.release_suite_output,
46 "codename": p.codename,
47 "dakname": p.suite_name,
48 "archive": p.archive.archive_name,
49 "architectures": [x.arch_string for x in p.architectures],
50 "components": [x.component_name for x in p.components],
51 }
52 )
54 s.close()
56 bottle.response.content_type = "application/json; charset=UTF-8"
57 return json.dumps(ret)
60QueryRegister().register_path("/suites", suites)
63@bottle.route("/suite/<suite>")
64def suite(suite: Optional[str] = None) -> str:
65 """
66 Gives information about a single suite. Note that this routine will look
67 up a suite first by the main suite_name, but then also by codename if no
68 suite is initially found. It can therefore be used to canonicalise suite
69 names.
71 :param suite: Name or codename of the suite.
73 :return: A dictionary of
74 - name: maps to `Suite:` in the Release file
75 - codename: maps to `Codename:` in the Release file
76 - dakname: internal name that should not be relied upload
77 - archive
78 - architectures
79 - components
81 .. seealso:: :func:`~dakweb.queries.suite.suites` on how to receive a list of valid suites.
82 """
84 if suite is None:
85 return bottle.HTTPError(503, "Suite not specified.")
87 # TODO: We should probably stick this logic into daklib/dbconn.py
88 so = None
90 s = DBConn().session()
91 q = s.query(Suite)
92 q = q.filter(Suite.suite_name == suite)
94 if q.count() > 1:
95 # This would mean dak is misconfigured
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 # Look it up by suite_name
102 q = s.query(Suite).filter(Suite.codename == suite)
103 if q.count() > 1:
104 # This would mean dak is misconfigured
105 s.close()
106 return bottle.HTTPError(503, "Multiple suites found: configuration error")
107 elif q.count() == 1:
108 so = q[0]
110 if so is not None:
111 so = {
112 "name": so.release_suite_output,
113 "codename": so.codename,
114 "dakname": so.suite_name,
115 "archive": so.archive.archive_name,
116 "architectures": [x.arch_string for x in so.architectures],
117 "components": [x.component_name for x in so.components],
118 }
120 s.close()
122 bottle.response.content_type = "application/json; charset=UTF-8"
123 return json.dumps(so)
126QueryRegister().register_path("/suite", suite)