suite.py 3.6 KB

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