source.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. """ Queries related to source packages
  2. @contact: Debian FTPMaster <ftpmaster@debian.org>
  3. @copyright: 2014 Mark Hymers <mhy@debian.org>
  4. @copyright: 2014 Joerg Jaspert <joerg@debian.org>
  5. @license: GNU General Public License version 2 or later
  6. """
  7. from sqlalchemy import or_
  8. import bottle
  9. import json
  10. from daklib.dbconn import DBConn, DBSource, Suite, DSCFile, PoolFile
  11. from dakweb.webregister import QueryRegister
  12. @bottle.route('/dsc_in_suite/<suite>/<source>')
  13. def dsc_in_suite(suite=None, source=None):
  14. """
  15. Find all dsc files for a given source package name in a given suite.
  16. @since: December 2014
  17. @type suite: string
  18. @param suite: Name of the suite.
  19. @see: L{I{suites}<dakweb.queries.suite.suites>} on how to receive a list of valid suites.
  20. @type source: string
  21. @param source: Source package to query for.
  22. @rtype: list of dictionaries
  23. @return: Dictionaries made out of
  24. - version
  25. - component
  26. - filename
  27. - filesize
  28. - sha256sum
  29. """
  30. if suite is None:
  31. return bottle.HTTPError(503, 'Suite not specified.')
  32. if source is None:
  33. return bottle.HTTPError(503, 'Source package not specified.')
  34. s = DBConn().session()
  35. q = s.query(DSCFile).join(PoolFile)
  36. q = q.join(DBSource).join(Suite, DBSource.suites)
  37. q = q.filter(or_(Suite.suite_name == suite, Suite.codename == suite))
  38. q = q.filter(DBSource.source == source)
  39. q = q.filter(PoolFile.filename.endswith('.dsc'))
  40. ret = []
  41. for p in q:
  42. ret.append({'version': p.source.version,
  43. 'component': p.poolfile.component.component_name,
  44. 'filename': p.poolfile.filename,
  45. 'filesize': p.poolfile.filesize,
  46. 'sha256sum': p.poolfile.sha256sum})
  47. s.close()
  48. return json.dumps(ret)
  49. QueryRegister().register_path('/dsc_in_suite', dsc_in_suite)
  50. @bottle.route('/sources_in_suite/<suite>')
  51. def sources_in_suite(suite=None):
  52. """
  53. Returns all source packages and their versions in a given suite.
  54. @since: December 2014
  55. @type suite: string
  56. @param suite: Name of the suite.
  57. @see: L{I{suites}<dakweb.queries.suite.suites>} on how to receive a list of valid suites.
  58. @rtype: list of dictionaries
  59. @return: Dictionaries made out of
  60. - source
  61. - version
  62. """
  63. if suite is None:
  64. return bottle.HTTPError(503, 'Suite not specified.')
  65. s = DBConn().session()
  66. q = s.query(DBSource).join(Suite, DBSource.suites)
  67. q = q.filter(or_(Suite.suite_name == suite, Suite.codename == suite))
  68. ret = []
  69. for p in q:
  70. ret.append({'source': p.source,
  71. 'version': p.version})
  72. s.close()
  73. return json.dumps(ret)
  74. QueryRegister().register_path('/sources_in_suite', sources_in_suite)
  75. @bottle.route('/all_sources')
  76. def all_sources():
  77. """
  78. Returns all source packages and their versions known to the archive
  79. (this includes NEW).
  80. @rtype: list of dictionaries
  81. @return: Dictionaries made out of
  82. - source
  83. - version
  84. """
  85. s = DBConn().session()
  86. q = s.query(DBSource)
  87. ret = []
  88. for p in q:
  89. ret.append({'source': p.source,
  90. 'version': p.version})
  91. s.close()
  92. return json.dumps(ret)
  93. QueryRegister().register_path('/all_sources', all_sources)