mirror of
https://github.com/jazzband/django-configurations.git
synced 2026-04-29 03:04:49 +00:00
Backported LaxOptionParser from Django 1.7 to make it work on 1.8
This commit is contained in:
parent
5ece107044
commit
f89ffbd1cd
2 changed files with 62 additions and 1 deletions
|
|
@ -9,7 +9,7 @@ from django.conf import ENVIRONMENT_VARIABLE as SETTINGS_ENVIRONMENT_VARIABLE
|
|||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.management import base
|
||||
|
||||
from .utils import uppercase_attributes, reraise
|
||||
from .utils import uppercase_attributes, reraise, LaxOptionParser
|
||||
from .values import Value, setup_value
|
||||
|
||||
installed = False
|
||||
|
|
|
|||
|
|
@ -137,3 +137,64 @@ else: # 2.6, 2.7
|
|||
except IndexError:
|
||||
pass
|
||||
return inspect.ArgSpec(args, varargs, varkw, func_defaults)
|
||||
|
||||
try:
|
||||
from django.core.management import LaxOptionParser
|
||||
except ImportError:
|
||||
from optparse import OptionParser
|
||||
|
||||
class LaxOptionParser(OptionParser):
|
||||
"""
|
||||
An option parser that doesn't raise any errors on unknown options.
|
||||
|
||||
This is needed because the --settings and --pythonpath options affect
|
||||
the commands (and thus the options) that are available to the user.
|
||||
|
||||
Backported from Django 1.7.x
|
||||
|
||||
"""
|
||||
def error(self, msg):
|
||||
pass
|
||||
|
||||
def print_help(self):
|
||||
"""Output nothing.
|
||||
|
||||
The lax options are included in the normal option parser, so under
|
||||
normal usage, we don't need to print the lax options.
|
||||
"""
|
||||
pass
|
||||
def print_lax_help(self):
|
||||
"""Output the basic options available to every command.
|
||||
|
||||
This just redirects to the default print_help() behavior.
|
||||
"""
|
||||
OptionParser.print_help(self)
|
||||
|
||||
def _process_args(self, largs, rargs, values):
|
||||
"""
|
||||
Overrides OptionParser._process_args to exclusively handle default
|
||||
options and ignore args and other options.
|
||||
|
||||
This overrides the behavior of the super class, which stop parsing
|
||||
at the first unrecognized option.
|
||||
"""
|
||||
while rargs:
|
||||
arg = rargs[0]
|
||||
try:
|
||||
if arg[0:2] == "--" and len(arg) > 2:
|
||||
# process a single long option (possibly with value(s))
|
||||
# the superclass code pops the arg off rargs
|
||||
self._process_long_opt(rargs, values)
|
||||
elif arg[:1] == "-" and len(arg) > 1:
|
||||
# process a cluster of short options (possibly with
|
||||
# value(s) for the last one only)
|
||||
# the superclass code pops the arg off rargs
|
||||
self._process_short_opts(rargs, values)
|
||||
else:
|
||||
# it's either a non-default option or an arg
|
||||
# either way, add it to the args list so we can keep
|
||||
# dealing with options
|
||||
del rargs[0]
|
||||
raise Exception
|
||||
except: # Needed because we might need to catch a SystemExit
|
||||
largs.append(arg)
|
||||
|
|
|
|||
Loading…
Reference in a new issue