Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit ac1af72

Browse files
committed
s/optparse/argparse
1 parent 20cd495 commit ac1af72

File tree

7 files changed

+2435
-53
lines changed

7 files changed

+2435
-53
lines changed

gunicorn/app/base.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ class Application(object):
2020
the various necessities for any given web framework.
2121
"""
2222

23-
def __init__(self, usage=None):
23+
def __init__(self, usage=None, prog=None):
2424
self.usage = usage
2525
self.cfg = None
2626
self.callable = None
27+
self.prog = prog
2728
self.logger = None
2829
self.do_load_config()
2930

@@ -32,38 +33,39 @@ def do_load_config(self):
3233
self.load_config()
3334
except Exception as e:
3435
sys.stderr.write("\nError: %s\n" % str(e))
36+
traceback.print_exc()
3537
sys.stderr.flush()
3638
sys.exit(1)
3739

3840
def load_config(self):
3941
# init configuration
40-
self.cfg = Config(self.usage)
42+
self.cfg = Config(self.usage, prog=self.prog)
4143

4244
# parse console args
4345
parser = self.cfg.parser()
44-
opts, args = parser.parse_args()
46+
args = parser.parse_args()
4547

4648
# optional settings from apps
47-
cfg = self.init(parser, opts, args)
49+
cfg = self.init(parser, args, args.args)
4850

4951
# Load up the any app specific configuration
5052
if cfg and cfg is not None:
5153
for k, v in cfg.items():
5254
self.cfg.set(k.lower(), v)
5355

5456
# Load up the config file if its found.
55-
if opts.config and os.path.exists(opts.config):
57+
if args.config and os.path.exists(args.config):
5658
cfg = {
5759
"__builtins__": __builtins__,
5860
"__name__": "__config__",
59-
"__file__": opts.config,
61+
"__file__": args.config,
6062
"__doc__": None,
6163
"__package__": None
6264
}
6365
try:
64-
execfile_(opts.config, cfg, cfg)
66+
execfile_(args.config, cfg, cfg)
6567
except Exception:
66-
print("Failed to read config file: %s" % opts.config)
68+
print("Failed to read config file: %s" % args.config)
6769
traceback.print_exc()
6870
sys.exit(1)
6971

@@ -79,9 +81,11 @@ def load_config(self):
7981

8082
# Lastly, update the configuration with any command line
8183
# settings.
82-
for k, v in opts.__dict__.items():
84+
for k, v in args.__dict__.items():
8385
if v is None:
8486
continue
87+
if k == "args":
88+
continue
8589
self.cfg.set(k.lower(), v)
8690

8791
def init(self, parser, opts, args):

gunicorn/app/djangoapp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ class DjangoApplicationCommand(Application):
105105

106106
def __init__(self, options, admin_media_path):
107107
self.usage = None
108+
self.prog = None
108109
self.cfg = None
109110
self.config_file = options.get("config") or ""
110111
self.options = options
111112
self.admin_media_path = admin_media_path
112113
self.callable = None
113114
self.project_path = None
114-
115115
self.do_load_config()
116116

117117
def init(self, *args):
@@ -139,4 +139,4 @@ def run():
139139
applications.
140140
"""
141141
from gunicorn.app.djangoapp import DjangoApplication
142-
DjangoApplication("%prog [OPTIONS] [SETTINGS_PATH]").run()
142+
DjangoApplication("%(prog)s [OPTIONS] [SETTINGS_PATH]").run()

gunicorn/app/pasterapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def run():
147147
apllications like Pylons or Turbogears2
148148
"""
149149
from gunicorn.app.pasterapp import PasterApplication
150-
PasterApplication("%prog [OPTIONS] pasteconfig.ini").run()
150+
PasterApplication("%(prog)s [OPTIONS] pasteconfig.ini").run()
151151

152152

153153
def paste_server(app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):

gunicorn/app/wsgiapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ def run():
3131
generic WSGI applications.
3232
"""
3333
from gunicorn.app.wsgiapp import WSGIApplication
34-
WSGIApplication("%prog [OPTIONS] APP_MODULE").run()
34+
WSGIApplication("%(prog)s [OPTIONS] APP_MODULE").run()

0 commit comments

Comments
 (0)