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 bottle 

12from bottle import redirect 

13from daklib.dbconn import DBConn 

14import json 

15 

16from dakweb.webregister import QueryRegister 

17 

18 

19@bottle.route('/') 

20def root_path(): 

21 """Returns a useless welcome message""" 

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

23 

24 

25QueryRegister().register_path('/', root_path) 

26 

27 

28@bottle.route('/list_paths') 

29def list_paths(): 

30 """Returns a list of available paths""" 

31 redirect("https://ftp-team.pages.debian.net/dak/epydoc/dakweb-module.html#__package__") 

32 

33 

34QueryRegister().register_path('/list_paths', list_paths) 

35 

36 

37@bottle.route('/path_help/<path>') 

38def path_help(path=None): 

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

40 if path is None: 

41 return bottle.HTTPError(503, 'Path not specified.') 

42 

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

44 (QueryRegister().get_path_help(path), path)) 

45 

46 

47QueryRegister().register_path('/path_help', list_paths) 

48 

49# Import our other methods 

50from .queries.archive import * 

51from .queries.madison import * 

52from .queries.source import * 

53from .queries.suite import * 

54from .queries.binary import * 

55 

56# Run the bottle if we're called directly 

57if __name__ == '__main__': 

58 # Set up our initial database connection 

59 d = DBConn() 

60 bottle.run()