dakwebserver.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/python
  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. from __future__ import absolute_import
  9. import bottle
  10. from bottle import redirect
  11. from daklib.dbconn import DBConn
  12. import json
  13. from dakweb.webregister import QueryRegister
  14. @bottle.route('/')
  15. def root_path():
  16. """Returns a useless welcome message"""
  17. return json.dumps('Use the /list_paths path to list all available paths')
  18. QueryRegister().register_path('/', root_path)
  19. @bottle.route('/list_paths')
  20. def list_paths():
  21. """Returns a list of available paths"""
  22. redirect("https://ftp-team.pages.debian.net/dak/epydoc/dakweb-module.html#__package__")
  23. QueryRegister().register_path('/list_paths', list_paths)
  24. @bottle.route('/path_help/<path>')
  25. def path_help(path=None):
  26. """Redirects to the API description containing the path_help"""
  27. if path is None:
  28. return bottle.HTTPError(503, 'Path not specified.')
  29. redirect("https://ftp-team.pages.debian.net/dak/epydoc/%s-module.html#%s" %
  30. (QueryRegister().get_path_help(path), path))
  31. QueryRegister().register_path('/path_help', list_paths)
  32. # Import our other methods
  33. from .queries.archive import *
  34. from .queries.madison import *
  35. from .queries.source import *
  36. from .queries.suite import *
  37. from .queries.binary import *
  38. # Set up our initial database connection
  39. d = DBConn()
  40. # Run the bottle if we're called directly
  41. if __name__ == '__main__':
  42. bottle.run()