Supporting API changes in Django 1.10

* Since Django 1.10 there is no optparse (and no .args field) and no "usage()" method. All django manage py test failed.
This commit is contained in:
Ilya.Kazakevich
2016-08-03 19:49:42 +03:00
parent f9811b4010
commit f8e080c866
@@ -46,7 +46,7 @@ def report_data(dumper, commands_to_skip):
if command_name in commands_to_skip:
sys.stderr.write("Skipping command '{0}' due to config\n".format(command_name))
continue
fetcher = _Fetcher(utility, command_name)
fetcher.daemon = True
fetcher.start()
@@ -62,11 +62,14 @@ def report_data(dumper, commands_to_skip):
command_name))
sys.exit(1)
use_argparse = False
try:
use_argparse = command.use_argparse
except AttributeError:
pass
# There is no optparse in 1.10
if _is_django_10():
use_argparse = True
else:
try:
use_argparse = command.use_argparse
except AttributeError:
pass
try:
parser = command.create_parser("", command_name)
@@ -74,9 +77,27 @@ def report_data(dumper, commands_to_skip):
sys.stderr.write("Error parsing command {0}: {1}\n".format(command_name, e))
continue
try: # and there is no "usage()" since 1.10
usage = command.usage("")
except AttributeError:
usage = command.help
dumper.start_command(command_name=command_name,
command_help_text=VersionAgnosticUtils().to_unicode(command.usage("")).replace("%prog",
command_name))
command_help_text=VersionAgnosticUtils().to_unicode(usage).replace("%prog",
command_name))
module_to_use = _argparse if use_argparse else _optparse # Choose appropriate module: argparse, optparse
module_to_use.process_command(dumper, command, parser)
dumper.close_command()
def _is_django_10():
"""
:return: is Django >= 1.10
"""
try:
from distutils.version import StrictVersion
import django
return StrictVersion(django.get_version()) >= StrictVersion("1.10")
except (ImportError, AttributeError):
return False