Added option to pretty-print dumped fixture output
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4661 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a72f908924
commit
790b585819
|
@ -1413,7 +1413,7 @@ def load_data(fixture_labels, verbosity=1):
|
||||||
load_data.help_doc = 'Installs the named fixture(s) in the database'
|
load_data.help_doc = 'Installs the named fixture(s) in the database'
|
||||||
load_data.args = "[--verbosity] fixture, fixture, ..."
|
load_data.args = "[--verbosity] fixture, fixture, ..."
|
||||||
|
|
||||||
def dump_data(app_labels, format='json'):
|
def dump_data(app_labels, format='json', indent=None):
|
||||||
"Output the current contents of the database as a fixture of the given format"
|
"Output the current contents of the database as a fixture of the given format"
|
||||||
from django.db.models import get_app, get_apps, get_models
|
from django.db.models import get_app, get_apps, get_models
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
|
@ -1435,7 +1435,7 @@ def dump_data(app_labels, format='json'):
|
||||||
for model in get_models(app):
|
for model in get_models(app):
|
||||||
objects.extend(model.objects.all())
|
objects.extend(model.objects.all())
|
||||||
try:
|
try:
|
||||||
print serializers.serialize(format, objects)
|
print serializers.serialize(format, objects, indent=indent)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
sys.stderr.write(style.ERROR("Unable to serialize database: %s\n" % e))
|
sys.stderr.write(style.ERROR("Unable to serialize database: %s\n" % e))
|
||||||
dump_data.help_doc = 'Output the contents of the database as a fixture of the given format'
|
dump_data.help_doc = 'Output the contents of the database as a fixture of the given format'
|
||||||
|
@ -1525,6 +1525,8 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
|
||||||
help='Tells Django to NOT use the auto-reloader when running the development server.')
|
help='Tells Django to NOT use the auto-reloader when running the development server.')
|
||||||
parser.add_option('--format', default='json', dest='format',
|
parser.add_option('--format', default='json', dest='format',
|
||||||
help='Specifies the output serialization format for fixtures')
|
help='Specifies the output serialization format for fixtures')
|
||||||
|
parser.add_option('--indent', default=None, dest='indent',
|
||||||
|
type='int', help='Specifies the indent level to use when pretty-printing output')
|
||||||
parser.add_option('--verbosity', action='store', dest='verbosity', default='1',
|
parser.add_option('--verbosity', action='store', dest='verbosity', default='1',
|
||||||
type='choice', choices=['0', '1', '2'],
|
type='choice', choices=['0', '1', '2'],
|
||||||
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
|
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
|
||||||
|
@ -1579,7 +1581,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
|
||||||
parser.print_usage_and_exit()
|
parser.print_usage_and_exit()
|
||||||
elif action == 'dumpdata':
|
elif action == 'dumpdata':
|
||||||
try:
|
try:
|
||||||
action_mapping[action](args[1:], options.format)
|
action_mapping[action](args[1:], options.format, options.indent)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
parser.print_usage_and_exit()
|
parser.print_usage_and_exit()
|
||||||
elif action in ('startapp', 'startproject'):
|
elif action in ('startapp', 'startproject'):
|
||||||
|
|
|
@ -473,7 +473,7 @@ setting the Python path for you.
|
||||||
.. _import search path: http://diveintopython.org/getting_to_know_python/everything_is_an_object.html
|
.. _import search path: http://diveintopython.org/getting_to_know_python/everything_is_an_object.html
|
||||||
|
|
||||||
--format
|
--format
|
||||||
---------
|
--------
|
||||||
|
|
||||||
**New in Django development version**
|
**New in Django development version**
|
||||||
|
|
||||||
|
@ -490,6 +490,19 @@ of a registered serializer.
|
||||||
Displays a help message that includes a terse list of all available actions and
|
Displays a help message that includes a terse list of all available actions and
|
||||||
options.
|
options.
|
||||||
|
|
||||||
|
--indent
|
||||||
|
--------
|
||||||
|
|
||||||
|
**New in Django development version**
|
||||||
|
|
||||||
|
Example usage::
|
||||||
|
|
||||||
|
django-admin.py dumpdata --indent=4
|
||||||
|
|
||||||
|
Specifies the number of spaces that will be used for indentation when
|
||||||
|
pretty-printing output. By default, output will *not* be pretty-printed.
|
||||||
|
Pretty-printing will only be enabled if the indent option is provided.
|
||||||
|
|
||||||
--noinput
|
--noinput
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue