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 6import os 7 8from gunicorn.errors import ConfigError 9from gunicorn.app.base import Application 10from gunicorn import util 11 12 13class WSGIApplication(Application): 14 def init(self, parser, opts, args): 15 if opts.paste: 16 app_name = 'main' 17 path = opts.paste 18 if '#' in path: 19 path, app_name = path.split('#') 20 path = os.path.abspath(os.path.normpath( 21 os.path.join(util.getcwd(), path))) 22 23 if not os.path.exists(path): 24 raise ConfigError("%r not found" % path) 25 26 # paste application, load the config 27 self.cfgurl = 'config:%s#%s' % (path, app_name) 28 self.relpath = os.path.dirname(path) 29 30 from .pasterapp import paste_config 31 return paste_config(self.cfg, self.cfgurl, self.relpath) 32 33 if len(args) < 1: 34 parser.error("No application module specified.") 35 36 self.cfg.set("default_proc_name", args[0]) 37 self.app_uri = args[0] 38 39 def load_wsgiapp(self): 40 # load the app 41 return util.import_app(self.app_uri) 42 43 def load_pasteapp(self): 44 # load the paste app 45 from .pasterapp import load_pasteapp 46 return load_pasteapp(self.cfgurl, self.relpath, global_conf=self.cfg.paste_global_conf) 47 48 def load(self): 49 if self.cfg.paste is not None: 50 return self.load_pasteapp() 51 else: 52 return self.load_wsgiapp() 53 54 55def run(): 56 """\ 57 The ``gunicorn`` command line runner for launching Gunicorn with 58 generic WSGI applications. 59 """ 60 from gunicorn.app.wsgiapp import WSGIApplication 61 WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run() 62 63 64if __name__ == '__main__': 65 run() 66