try to use cwd() + gunicorn.conf.py as default config if no file is specified . see #52

This commit is contained in:
Jorge Niedbalski 2013-06-17 16:44:02 -03:00
parent e77d47cb97
commit 54b4ffb68e
2 changed files with 17 additions and 11 deletions

View File

@ -52,6 +52,15 @@ class Application(object):
for k, v in cfg.items(): for k, v in cfg.items():
self.cfg.set(k.lower(), v) self.cfg.set(k.lower(), v)
# Lastly, update the configuration with any command line
# settings.
for k, v in args.__dict__.items():
if v is None:
continue
if k == "args":
continue
self.cfg.set(k.lower(), v)
# Load up the config file if its found. # Load up the config file if its found.
if args.config: if args.config:
if not os.path.exists(args.config): if not os.path.exists(args.config):
@ -81,14 +90,6 @@ class Application(object):
sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v)) sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
raise raise
# Lastly, update the configuration with any command line
# settings.
for k, v in args.__dict__.items():
if v is None:
continue
if k == "args":
continue
self.cfg.set(k.lower(), v)
def init(self, parser, opts, args): def init(self, parser, opts, args):
raise NotImplementedError raise NotImplementedError

View File

@ -199,7 +199,7 @@ class Setting(object):
"dest": self.name, "dest": self.name,
"action": self.action or "store", "action": self.action or "store",
"type": self.type or str, "type": self.type or str,
"default": None, "default": self.default or None,
"help": help_txt "help": help_txt
} }
@ -367,6 +367,12 @@ def validate_post_request(val):
else: else:
raise TypeError("Value must have an arity of: 4") raise TypeError("Value must have an arity of: 4")
def get_default_config_file():
config_path = os.path.join(os.path.abspath(os.getcwd()), 'gunicorn.conf.py')
if os.path.exists(config_path):
return config_path
return None
class ConfigFile(Setting): class ConfigFile(Setting):
name = "config" name = "config"
@ -374,7 +380,7 @@ class ConfigFile(Setting):
cli = ["-c", "--config"] cli = ["-c", "--config"]
meta = "FILE" meta = "FILE"
validator = validate_string validator = validate_string
default = None default = get_default_config_file()
desc = """\ desc = """\
The path to a Gunicorn config file. The path to a Gunicorn config file.
@ -382,7 +388,6 @@ class ConfigFile(Setting):
application specific configuration. application specific configuration.
""" """
class Bind(Setting): class Bind(Setting):
name = "bind" name = "bind"
action = "append" action = "append"