dakwebserver.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #! /usr/bin/env python3
  2. """ Main script to run the dakweb server and also
  3. to provide the list_paths and path_help functions
  4. @contact: Debian FTPMaster <ftpmaster@debian.org>
  5. @copyright: 2014 Mark Hymers <mhy@debian.org>
  6. @license: GNU General Public License version 2 or later
  7. """
  8. import bottle
  9. from bottle import redirect
  10. from daklib.dbconn import DBConn
  11. import json
  12. from dakweb.webregister import QueryRegister
  13. @bottle.route('/')
  14. def root_path():
  15. """Returns a useless welcome message"""
  16. return json.dumps('Use the /list_paths path to list all available paths')
  17. QueryRegister().register_path('/', root_path)
  18. @bottle.route('/list_paths')
  19. def list_paths():
  20. """Returns a list of available paths"""
  21. redirect("https://ftp-team.pages.debian.net/dak/epydoc/dakweb-module.html#__package__")
  22. QueryRegister().register_path('/list_paths', list_paths)
  23. @bottle.route('/path_help/<path>')
  24. def path_help(path=None):
  25. """Redirects to the API description containing the path_help"""
  26. if path is None:
  27. return bottle.HTTPError(503, 'Path not specified.')
  28. redirect("https://ftp-team.pages.debian.net/dak/epydoc/%s-module.html#%s" %
  29. (QueryRegister().get_path_help(path), path))
  30. QueryRegister().register_path('/path_help', list_paths)
  31. # Import our other methods
  32. from .queries.archive import *
  33. from .queries.madison import *
  34. from .queries.source import *
  35. from .queries.suite import *
  36. from .queries.binary import *
  37. # Run the bottle if we're called directly
  38. if __name__ == '__main__':
  39. # Set up our initial database connection
  40. d = DBConn()
  41. bottle.run()