Package dakweb :: Module dakwebserver
[hide private]
[frames] | no frames]

Source Code for Module dakweb.dakwebserver

 1  #! /usr/bin/env python3 
 2   
 3  """Main script to run the dakweb server and also 
 4  to 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   
11  import json 
12   
13  import bottle 
14  from bottle import redirect 
15   
16  from daklib.dbconn import DBConn 
17  from dakweb.webregister import QueryRegister 
18 19 20 @bottle.route("/") 21 -def root_path():
22 """Returns a useless welcome message""" 23 return json.dumps("Use the /list_paths path to list all available paths")
24 25 26 QueryRegister().register_path("/", root_path)
27 28 29 @bottle.route("/list_paths") 30 -def 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 37 QueryRegister().register_path("/list_paths", list_paths)
38 39 40 @bottle.route("/path_help/<path>") 41 -def 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 52 QueryRegister().register_path("/path_help", list_paths) 53 54 # Import our other methods 55 from .queries import archive, binary, madison, source, suite # noqa: F401 56 57 # Run the bottle if we're called directly 58 if __name__ == "__main__": 59 # Set up our initial database connection 60 d = DBConn() 61 bottle.run() 62