def init(self, parser, opts, args): # PasteDeploy config file if opts.paste: from .pasterapp import has_logging_config config_uri = os.path.abspath(opts.paste) config_file = config_uri.split('#')[0] if not os.path.exists(config_file): raise ConfigError("%r not found" % config_file) self.cfg.set("default_proc_name", config_file) self.app_uri = config_uri if has_logging_config(config_file): self.cfg.set("logconfig", config_file) return if not args: parser.error("No application module specified.") # ``args[0]`` 如: ``app.wsgi:app`` self.cfg.set("default_proc_name", args[0]) self.app_uri = args[0]
def init(self, parser, opts, args): if opts.paste: app_name = "main" path = opts.paste if "#" in path: path, app_name = path.split("#") path = os.path.abspath( os.path.normpath(os.path.join(util.getcwd(), path))) if not os.path.exists(path): raise ConfigError("%r not found" % path) # paste application, load the config self.cfgurl = "config:%s#%s" % (path, app_name) self.relpath = os.path.dirname(path) from .pasterapp import paste_config return paste_config(self.cfg, self.cfgurl, self.relpath) if len(args) < 1: parser.error("No application module specified.") self.cfg.set("default_proc_name", args[0]) self.app_uri = args[0]
def load_config(self): super().load_config() if self.app_uri is None: if self.cfg.wsgi_app is not None: self.app_uri = self.cfg.wsgi_app else: raise ConfigError("No application module specified.")
def validate_reloader(val): if val is None: val = 'default' choices = ['poll', 'inotify', 'default'] if val not in choices: raise ConfigError('Invalid reloader type. Must be one of: %s' % choices)
def validate_reloader(val): if val is None: val = 'auto' choices = ['auto', 'poll', 'inotify', 'off'] if val not in choices: raise ConfigError('Invalid reloader type. Must be one of: %s' % choices) return val
def validate_chdir(val): # valid if the value is a string val = validate_string(val) # transform relative paths path = os.path.abspath(os.path.normpath(os.path.join(util.getcwd(), val))) # test if the path exists if not os.path.exists(path): raise ConfigError("can't chdir to %r" % val) return path
def validate_user(val): if val is None: return os.geteuid() if isinstance(val, int): return val elif val.isdigit(): return int(val) else: try: return pwd.getpwnam(val).pw_uid except KeyError: raise ConfigError("No such user: '******'" % val)
def validate_group(val): if val is None: return os.getegid() if isinstance(val, int): return val elif val.isdigit(): return int(val) else: try: return grp.getgrnam(val).gr_gid except KeyError: raise ConfigError("No such group: '%s'" % val)
def validate_file(val): if val is None: return None # valid if the value is a string val = validate_string(val) # transform relative paths path = os.path.abspath(os.path.normpath(os.path.join(util.getcwd(), val))) # test if the path exists if not os.path.exists(path): raise ConfigError("%r not found" % val) return path
def validate_config_dir(val): if val is None: return val else: # valid if the value is a string val = validate_string(val) # transform relative paths path = os.path.abspath(os.path.normpath(os.path.join(util.getcwd(), val))) # test if the path exists if not os.path.exists(path): raise ConfigError("can't find a config directory in %r" % val) return path
def init(self, parser, opts, args): if opts.paste and opts.paste is not None: path = os.path.abspath( os.path.normpath(os.path.join(util.getcwd(), opts.paste))) if not os.path.exists(path): raise ConfigError("%r not found" % val) # paste application, load the config self.cfgurl = 'config:%s' % path self.relpath = os.path.dirname(path) from .pasterapp import paste_config return paste_config(self.cfg, self.cfgurl, self.relpath) if len(args) != 1: parser.error("No application module specified.") self.cfg.set("default_proc_name", args[0]) self.app_uri = args[0]
def init(self, parser, opts, args): self.app_uri = None if opts.paste: from .pasterapp import has_logging_config config_uri = os.path.abspath(opts.paste) config_file = config_uri.split("#")[0] if not os.path.exists(config_file): raise ConfigError("%r not found" % config_file) self.cfg.set("default_proc_name", config_file) self.app_uri = config_uri if has_logging_config(config_file): self.cfg.set("logconfig", config_file) return if len(args) > 0: self.cfg.set("default_proc_name", args[0]) self.app_uri = args[0]
def validate_reload_engine(val): if val not in reloader_engines: raise ConfigError("Invalid reload_engine: %r" % val) return val