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. """
  14. Display information about B{package(s)}.
  15. @since: 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. @see: L{I{suites}<dakweb.queries.suite.suites>} on how to receive a list of valid suites.
  24. @rtype: text/plain or application/json
  25. @return: Text or Json format of the data
  26. """
  27. r = bottle.request
  28. packages = r.query.get('package', '').split()
  29. kwargs = dict()
  30. architectures = r.query.get('a', None)
  31. if architectures is not None:
  32. kwargs['architectures'] = architectures.split(",")
  33. binary_type = r.query.get('b', None)
  34. if binary_type is not None:
  35. kwargs['binary_types'] = [binary_type]
  36. component = r.query.get('c', None)
  37. if component is not None:
  38. kwargs['components'] = component.split(",")
  39. suite = r.query.get('s', None)
  40. if suite is not None:
  41. kwargs['suites'] = suite.split(",")
  42. if 'S' in r.query:
  43. kwargs['source_and_binary'] = True
  44. format = r.query.get('f', None)
  45. if format is not None:
  46. kwargs['format'] = 'python'
  47. result = list_packages(packages, **kwargs)
  48. if format is None:
  49. bottle.response.content_type = 'text/plain; charset=UTF-8'
  50. for row in result:
  51. yield row
  52. yield "\n"
  53. else:
  54. bottle.response.content_type = 'application/json; charset=UTF-8'
  55. yield json.dumps(list(result))
  56. QueryRegister().register_path('/madison', madison)