madison.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. """ "Madison" interface
  2. @contact: Debian FTPMaster <ftpmaster@debian.org>
  3. @copyright: 2014 Ansgar Burchardt <ansgar@debian.org>
  4. @copyright: 2014 Joerg Jaspert <joerg@debian.org>
  5. @license: GNU General Public License version 2 or later
  6. """
  7. import bottle
  8. import json
  9. from daklib.ls import list_packages
  10. from dakweb.webregister import QueryRegister
  11. @bottle.route('/madison')
  12. def madison():
  13. r"""
  14. Display information about `package`\ (s).
  15. .. versionadded:: December 2014
  16. @keyword package: Space separated list of packages.
  17. @keyword a: only show info for specified architectures.
  18. @keyword b: only show info for a binary type. I{deb/udeb/dsc}
  19. @keyword c: only show info for specified component(s). I{main/contrib/non-free}
  20. @keyword s: only show info for this suite.
  21. @keyword S: show info for the binary children of source pkgs. I{true/false}
  22. @keyword f: output json format. I{json}
  23. :return: Text or Json format of the data
  24. .. seealso:: :func:`~dakweb.queries.suite.suites` on how to receive a list of valid suites.
  25. """
  26. r = bottle.request
  27. packages = r.query.get('package', '').split()
  28. kwargs = dict()
  29. architectures = r.query.get('a', None)
  30. if architectures is not None:
  31. kwargs['architectures'] = architectures.split(",")
  32. binary_type = r.query.get('b', None)
  33. if binary_type is not None:
  34. kwargs['binary_types'] = [binary_type]
  35. component = r.query.get('c', None)
  36. if component is not None:
  37. kwargs['components'] = component.split(",")
  38. suite = r.query.get('s', None)
  39. if suite is not None:
  40. kwargs['suites'] = suite.split(",")
  41. if 'S' in r.query:
  42. kwargs['source_and_binary'] = True
  43. format = r.query.get('f', None)
  44. if format is not None:
  45. kwargs['format'] = 'python'
  46. result = list_packages(packages, **kwargs)
  47. if format is None:
  48. bottle.response.content_type = 'text/plain; charset=UTF-8'
  49. for row in result:
  50. yield row
  51. yield "\n"
  52. else:
  53. bottle.response.content_type = 'application/json; charset=UTF-8'
  54. yield json.dumps(list(result))
  55. QueryRegister().register_path('/madison', madison)