django_evolution.compat.commands

Compatibility module for management commands.

Classes

BaseCommand([stdout, stderr, no_color, ...])

Base command compatible with a range of Django versions.

OptionParserWrapper(parser)

Compatibility wrapper for OptionParser.

class django_evolution.compat.commands.OptionParserWrapper(parser)

Bases: object

Compatibility wrapper for OptionParser.

This exports a more modern ArgumentParser-based API for OptionParser, for use when adding arguments in management commands. This only contains a subset of the functionality of ArgumentParser.

__init__(parser)

Initialize the wrapper.

Parameters:

parser (optparse.OptionParser) – The option parser.

add_argument(*args, **kwargs)

Add an argument to the parser.

This is a simple wrapper that provides compatibility with most of argparse.ArgumentParser.add_argument(). It supports the types that optparse.OptionParser.add_option() supports (though those types should be passed as the primitive types and not as the string names).

Parameters:
class django_evolution.compat.commands.BaseCommand(stdout=None, stderr=None, no_color=False, force_color=False)

Bases: BaseCommand

Base command compatible with a range of Django versions.

This is a version of django.core.management.base.BaseCommand that supports the modern way of adding arguments while retaining compatibility with older versions of Django. See the parent class’s documentation for details on usage.

property use_argparse

Whether argparse should be used for argument parsing.

This is used internally by Django.

create_parser(*args, **kwargs)

Create a parser for the command.

This is a wrapper around Django’s method that ensures compatibility with old-style (<= 1.6)) and new-style (>= 1.7) argument parsing logic.

Parameters:
  • *args (tuple) – Positional arguments to pass to the parent method.

  • **kwargs (dict) – Keyword arguments to pass to the parent method.

Returns:

The argument parser. This will be a optparse.OptionParser or a argparse.ArgumentParser.

Return type:

object

add_arguments(parser)

Add arguments to the command.

By default, this does nothing. Subclasses can override to add additional arguments.

Parameters:

parser (object) – The argument parser. This will be a optparse.OptionParser or a argparse.ArgumentParser.

__getattribute__(name)

Return an attribute from the command.

If the attribute name is “option_list”, some special work will be done to ensure we’re returning a valid list that the caller can work with, even if the options were created in add_arguments().

Parameters:

name (unicode) – The attribute name.

Returns:

The attribute value.

Return type:

object