Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wsgiapp.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # -*- coding: utf-8 -
  2. #
  3. # This file is part of gunicorn released under the MIT license.
  4. # See the NOTICE for more information.
  5. import os
  6. import sys
  7. from gunicorn.errors import ConfigError
  8. from gunicorn.app.base import Application
  9. from gunicorn import util
  10. class WSGIApplication(Application):
  11. def init(self, parser, opts, args):
  12. if opts.paste and opts.paste is not None:
  13. app_name = 'main'
  14. path = opts.paste
  15. if '#' in path:
  16. path, app_name = path.split('#')
  17. path = os.path.abspath(os.path.normpath(
  18. os.path.join(util.getcwd(), path)))
  19. if not os.path.exists(path):
  20. raise ConfigError("%r not found" % path)
  21. # paste application, load the config
  22. self.cfgurl = 'config:%s#%s' % (path, app_name)
  23. self.relpath = os.path.dirname(path)
  24. from .pasterapp import paste_config
  25. return paste_config(self.cfg, self.cfgurl, self.relpath)
  26. if len(args) < 1:
  27. parser.error("No application module specified.")
  28. self.cfg.set("default_proc_name", args[0])
  29. self.app_uri = args[0]
  30. def chdir(self):
  31. # chdir to the configured path before loading,
  32. # default is the current dir
  33. os.chdir(self.cfg.chdir)
  34. # add the path to sys.path
  35. sys.path.insert(0, self.cfg.chdir)
  36. def load_wsgiapp(self):
  37. self.chdir()
  38. # load the app
  39. return util.import_app(self.app_uri)
  40. def load_pasteapp(self):
  41. self.chdir()
  42. # load the paste app
  43. from .pasterapp import load_pasteapp
  44. return load_pasteapp(self.cfgurl, self.relpath, global_conf=None)
  45. def load(self):
  46. if self.cfg.paste is not None:
  47. return self.load_pasteapp()
  48. else:
  49. return self.load_wsgiapp()
  50. def run():
  51. """\
  52. The ``gunicorn`` command line runner for launching Gunicorn with
  53. generic WSGI applications.
  54. """
  55. from gunicorn.app.wsgiapp import WSGIApplication
  56. WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  57. if __name__ == '__main__':
  58. run()