suite.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. return json.dumps(ret)
  40. QueryRegister().register_path('/suites', suites)
  41. @bottle.route('/suite/<suite>')
  42. def suite(suite=None):
  43. """
  44. Gives information about a single suite. Note that this routine will look
  45. up a suite first by the main suite_name, but then also by codename if no
  46. suite is initially found. It can therefore be used to canonicalise suite
  47. names.
  48. @type suite: string
  49. @param suite: Name or codename of the suite.
  50. @see: L{I{suites}<dakweb.queries.suite.suites>} on how to receive a list of valid suites.
  51. @maps: name maps to Suite: in the release file
  52. @maps: codename maps to Codename: in the release file.
  53. @maps: dakname is an internal name and should not be relied upon.
  54. @rtype: dictionary
  55. @return: A dictionary of
  56. - name
  57. - codename
  58. - dakname
  59. - archive
  60. - architectures
  61. - components
  62. """
  63. if suite is None:
  64. return bottle.HTTPError(503, 'Suite not specified.')
  65. # TODO: We should probably stick this logic into daklib/dbconn.py
  66. so = None
  67. s = DBConn().session()
  68. q = s.query(Suite)
  69. q = q.filter(Suite.suite_name == suite)
  70. if q.count() > 1:
  71. # This would mean dak is misconfigured
  72. s.close()
  73. return bottle.HTTPError(503, 'Multiple suites found: configuration error')
  74. elif q.count() == 1:
  75. so = q[0]
  76. else:
  77. # Look it up by suite_name
  78. q = s.query(Suite).filter(Suite.codename == suite)
  79. if q.count() > 1:
  80. # This would mean dak is misconfigured
  81. s.close()
  82. return bottle.HTTPError(503, 'Multiple suites found: configuration error')
  83. elif q.count() == 1:
  84. so = q[0]
  85. if so is not None:
  86. so = {'name': so.release_suite_output,
  87. 'codename': so.codename,
  88. 'dakname': so.suite_name,
  89. 'archive': so.archive.archive_name,
  90. 'architectures': [x.arch_string for x in so.architectures],
  91. 'components': [x.component_name for x in so.components]}
  92. s.close()
  93. return json.dumps(so)
  94. QueryRegister().register_path('/suite', suite)