| 10 | |
| 11 | |
| 12 | class WSGIApplication(Application): |
| 13 | def init(self, parser, opts, args): |
| 14 | self.app_uri = None |
| 15 | |
| 16 | if opts.paste: |
| 17 | from .pasterapp import has_logging_config |
| 18 | |
| 19 | config_uri = os.path.abspath(opts.paste) |
| 20 | config_file = config_uri.split('#')[0] |
| 21 | |
| 22 | if not os.path.exists(config_file): |
| 23 | raise ConfigError("%r not found" % config_file) |
| 24 | |
| 25 | self.cfg.set("default_proc_name", config_file) |
| 26 | self.app_uri = config_uri |
| 27 | |
| 28 | if has_logging_config(config_file): |
| 29 | self.cfg.set("logconfig", config_file) |
| 30 | |
| 31 | return |
| 32 | |
| 33 | if len(args) > 0: |
| 34 | self.cfg.set("default_proc_name", args[0]) |
| 35 | self.app_uri = args[0] |
| 36 | |
| 37 | def load_config(self): |
| 38 | super().load_config() |
| 39 | |
| 40 | if self.app_uri is None: |
| 41 | if self.cfg.wsgi_app is not None: |
| 42 | self.app_uri = self.cfg.wsgi_app |
| 43 | else: |
| 44 | raise ConfigError("No application module specified.") |
| 45 | |
| 46 | def load_wsgiapp(self): |
| 47 | return util.import_app(self.app_uri) |
| 48 | |
| 49 | def load_pasteapp(self): |
| 50 | from .pasterapp import get_wsgi_app |
| 51 | return get_wsgi_app(self.app_uri, defaults=self.cfg.paste_global_conf) |
| 52 | |
| 53 | def load(self): |
| 54 | if self.cfg.paste is not None: |
| 55 | return self.load_pasteapp() |
| 56 | else: |
| 57 | return self.load_wsgiapp() |
| 58 | |
| 59 | |
| 60 | def run(prog=None): |