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 

10import bottle 

11import json 

12from typing import Optional 

13 

14from daklib.dbconn import DBConn, Suite 

15from dakweb.webregister import QueryRegister 

16 

17 

18@bottle.route('/suites') 

19def suites() -> str: 

20 """ 

21 Give information about all known suites. 

22 

23 @maps: name maps to Suite: in the release file 

24 @maps: codename maps to Codename: in the release file. 

25 @maps: dakname is an internal name and should not be relied upon. 

26 

27 :return: List of 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 

55QueryRegister().register_path('/suites', suites) 

56 

57 

58@bottle.route('/suite/<suite>') 

59def suite(suite: Optional[str] = None) -> str: 

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 :param suite: Name or codename of the suite. 

67 

68 :return: A dictionary of 

69 - name: maps to `Suite:` in the Release file 

70 - codename: maps to `Codename:` in the Release file 

71 - dakname: internal name that should not be relied upload 

72 - archive 

73 - architectures 

74 - components 

75 

76 .. seealso:: :func:`~dakweb.queries.suite.suites` on how to receive a list of valid suites. 

77 """ 

78 

79 if suite is None: 

80 return bottle.HTTPError(503, 'Suite not specified.') 

81 

82 # TODO: We should probably stick this logic into daklib/dbconn.py 

83 so = None 

84 

85 s = DBConn().session() 

86 q = s.query(Suite) 

87 q = q.filter(Suite.suite_name == suite) 

88 

89 if q.count() > 1: 

90 # This would mean dak is misconfigured 

91 s.close() 

92 return bottle.HTTPError(503, 'Multiple suites found: configuration error') 

93 elif q.count() == 1: 

94 so = q[0] 

95 else: 

96 # Look it up by suite_name 

97 q = s.query(Suite).filter(Suite.codename == suite) 

98 if q.count() > 1: 

99 # This would mean dak is misconfigured 

100 s.close() 

101 return bottle.HTTPError(503, 'Multiple suites found: configuration error') 

102 elif q.count() == 1: 

103 so = q[0] 

104 

105 if so is not None: 

106 so = {'name': so.release_suite_output, 

107 'codename': so.codename, 

108 'dakname': so.suite_name, 

109 'archive': so.archive.archive_name, 

110 'architectures': [x.arch_string for x in so.architectures], 

111 'components': [x.component_name for x in so.components]} 

112 

113 s.close() 

114 

115 bottle.response.content_type = 'application/json; charset=UTF-8' 

116 return json.dumps(so) 

117 

118 

119QueryRegister().register_path('/suite', suite)