From fced1e19c0a79247fbbb316380df2c18a70c0a2a Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Thu, 29 Jan 2015 17:12:59 +0300 Subject: [PATCH] PY-11855 Run manage.py task improvements * Python 2.7 fix (no super()) * Django 1.7 fix (setup is called) * Final fields removed due to XStream deserialization fail * usage() is used instead of bare help --- python/helpers/pycharm/_django_obtainer_core.py | 1 - python/helpers/pycharm/_django_obtainer_optparse.py | 7 +++++-- python/helpers/pycharm/django_obtainer.py | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/python/helpers/pycharm/_django_obtainer_core.py b/python/helpers/pycharm/_django_obtainer_core.py index 0ef2d0d25ee0..d8d8c73c05aa 100644 --- a/python/helpers/pycharm/_django_obtainer_core.py +++ b/python/helpers/pycharm/_django_obtainer_core.py @@ -40,7 +40,6 @@ class XmlDumper(object): __command_info_tag = "commandInfo" # Name of main tag def __init__(self): - super().__init__() self.__document = minidom.Document() self.__root = self.__document.createElement("{0}-array".format(XmlDumper.__command_info_tag)) self.__document.appendChild(self.__root) diff --git a/python/helpers/pycharm/_django_obtainer_optparse.py b/python/helpers/pycharm/_django_obtainer_optparse.py index e356697ae6b3..0330856c3dd8 100644 --- a/python/helpers/pycharm/_django_obtainer_optparse.py +++ b/python/helpers/pycharm/_django_obtainer_optparse.py @@ -3,6 +3,9 @@ Exports data from optparse-based manage.py commands and reports it to pycharm.django_manage_obtainer._XmlDumper """ from optparse import Option +import django +from django.apps import registry +from django.conf import settings from django.core.management import ManagementUtility, get_commands, BaseCommand __author__ = 'Ilya.Kazakevich' @@ -20,7 +23,7 @@ def report_data(dumper): command = utility.fetch_command(command_name) assert isinstance(command, BaseCommand) dumper.start_command(command_name=command_name, - command_help_text=str(command.help), + command_help_text=str(command.usage("").replace("%prog", command_name)), # TODO: support subcommands command_args_text=str(command.args)) for opt in command.option_list: opt_type = opt.type if opt.type in Option.TYPES else "" # Empty for unknown @@ -33,4 +36,4 @@ def report_data(dumper): short_opt_names=opt._short_opts, help_text=opt.help, num_of_args=opt.nargs) - dumper.close_command() + dumper.close_command() \ No newline at end of file diff --git a/python/helpers/pycharm/django_obtainer.py b/python/helpers/pycharm/django_obtainer.py index 15bf56cfe9c3..3f9849c4ad7f 100644 --- a/python/helpers/pycharm/django_obtainer.py +++ b/python/helpers/pycharm/django_obtainer.py @@ -14,7 +14,11 @@ from _django_obtainer_core import XmlDumper __author__ = 'Ilya.Kazakevich' # TODO: Support Django 1.8 as well, it uses argparse, not optparse -assert LooseVersion(django.get_version()) < LooseVersion('1.8a'), "Only Django <1.8 is supported now" +version = LooseVersion(django.get_version()) +assert version < LooseVersion('1.8a'), "Only Django <1.8 is supported now" +# Some django versions require setup +if django.setup: + django.setup() dumper = XmlDumper() _django_obtainer_optparse.report_data(dumper) print(dumper.xml) \ No newline at end of file -- 2.32.0