1""" "Madison" interface 

2 

3@contact: Debian FTPMaster <ftpmaster@debian.org> 

4@copyright: 2014 Ansgar Burchardt <ansgar@debian.org> 

5@copyright: 2014 Joerg Jaspert <joerg@debian.org> 

6@license: GNU General Public License version 2 or later 

7""" 

8 

9import json 

10 

11import bottle 

12 

13from daklib.ls import list_packages 

14from dakweb.webregister import QueryRegister 

15 

16 

17@bottle.route("/madison") 

18def madison(): 

19 r""" 

20 Display information about `package`\ (s). 

21 

22 .. versionadded:: December 2014 

23 

24 @keyword package: Space separated list of packages. 

25 @keyword a: only show info for specified architectures. 

26 @keyword b: only show info for a binary type. I{deb/udeb/dsc} 

27 @keyword c: only show info for specified component(s). I{main/contrib/non-free} 

28 @keyword s: only show info for this suite. 

29 @keyword S: show info for the binary children of source pkgs. I{true/false} 

30 @keyword f: output json format. I{json} 

31 

32 :return: Text or Json format of the data 

33 

34 .. seealso:: :func:`~dakweb.queries.suite.suites` on how to receive a list of valid suites. 

35 """ 

36 

37 r = bottle.request 

38 

39 packages = r.query.get("package", "").split() 

40 kwargs = dict() 

41 

42 architectures = r.query.get("a", None) 

43 if architectures is not None: 

44 kwargs["architectures"] = architectures.split(",") 

45 binary_type = r.query.get("b", None) 

46 if binary_type is not None: 

47 kwargs["binary_types"] = [binary_type] 

48 component = r.query.get("c", None) 

49 if component is not None: 

50 kwargs["components"] = component.split(",") 

51 suite = r.query.get("s", None) 

52 if suite is not None: 

53 kwargs["suites"] = suite.split(",") 

54 if "S" in r.query: 

55 kwargs["source_and_binary"] = True 

56 format = r.query.get("f", None) 

57 if format is not None: 

58 kwargs["format"] = "python" 

59 

60 result = list_packages(packages, **kwargs) 

61 

62 if format is None: 

63 bottle.response.content_type = "text/plain; charset=UTF-8" 

64 for row in result: 

65 yield row 

66 yield "\n" 

67 else: 

68 bottle.response.content_type = "application/json; charset=UTF-8" 

69 yield json.dumps(list(result)) 

70 

71 

72QueryRegister().register_path("/madison", madison)