1#! /usr/bin/env python3 

2 

3"""Main script to run the dakweb server and also 

4to provide the list_paths and path_help functions 

5 

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

7@copyright: 2014 Mark Hymers <mhy@debian.org> 

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

9""" 

10 

11import json 

12 

13import bottle 

14from bottle import redirect 

15 

16from daklib.dbconn import DBConn 

17from dakweb.webregister import QueryRegister 

18 

19 

20@bottle.route("/") 

21def root_path(): 

22 """Returns a useless welcome message""" 

23 return json.dumps("Use the /list_paths path to list all available paths") 

24 

25 

26QueryRegister().register_path("/", root_path) 

27 

28 

29@bottle.route("/list_paths") 

30def list_paths(): 

31 """Returns a list of available paths""" 

32 redirect( 

33 "https://ftp-team.pages.debian.net/dak/epydoc/dakweb-module.html#__package__" 

34 ) 

35 

36 

37QueryRegister().register_path("/list_paths", list_paths) 

38 

39 

40@bottle.route("/path_help/<path>") 

41def path_help(path=None): 

42 """Redirects to the API description containing the path_help""" 

43 if path is None: 

44 return bottle.HTTPError(503, "Path not specified.") 

45 

46 redirect( 

47 "https://ftp-team.pages.debian.net/dak/epydoc/%s-module.html#%s" 

48 % (QueryRegister().get_path_help(path), path) 

49 ) 

50 

51 

52QueryRegister().register_path("/path_help", list_paths) 

53 

54# Import our other methods 

55from .queries import archive, binary, madison, source, suite # noqa: F401 

56 

57# Run the bottle if we're called directly 

58if __name__ == "__main__": 

59 # Set up our initial database connection 

60 d = DBConn() 

61 bottle.run()