Ticket #7254: dumpdata.py.2.diff

File dumpdata.py.2.diff, 3.3 KB (added by Carl Karsten <carl@…>, 7 years ago)

removed unnecessary changes, s/print stderr/sys.stderr.write

  • django/core/management/commands/dumpdata.py

     
    22from django.core import serializers
    33
    44from optparse import make_option
     5import sys
    56
    67class Command(BaseCommand):
    78    option_list = BaseCommand.option_list + (
     
    910            help='Specifies the output serialization format for fixtures.'),
    1011        make_option('--indent', default=None, dest='indent', type='int',
    1112            help='Specifies the indent level to use when pretty-printing output'),
     13        make_option('-e', '--exclude', dest='exclude',action='append', default=None,
     14            help='App to exclude (use multiple --exclude to exclude multiple apps).'),
     15        make_option('-v', '--verbosity', action='store', dest='verbosity', default='0',
     16            type='choice', choices=['0', '1', '2'],
     17            help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
    1218    )
    1319    help = 'Output the contents of the database as a fixture of the given format.'
    1420    args = '[appname ...]'
     
    1622    def handle(self, *app_labels, **options):
    1723        from django.db.models import get_app, get_apps, get_models
    1824
    19         format = options.get('format', 'json')
    20         indent = options.get('indent', None)
    21         show_traceback = options.get('traceback', False)
     25        format = options.get('format')
     26        indent = options.get('indent')
     27        exclude = options.get('exclude')
     28        verbosity = int(options.get('verbosity'))
     29        show_traceback = options.get('traceback')
    2230
     31        if verbosity >= 2:
     32            sys.stderr.write(
     33                "format %s\nindent %s\nexclude %s\nshow_traceback %s\n" % \
     34                (format, indent, exclude, show_traceback) )
     35            sys.stderr.write( "apps %s\n" % (app_labels,) )
     36
    2337        if len(app_labels) == 0:
    2438            app_list = get_apps()
    2539        else:
    2640            app_list = [get_app(app_label) for app_label in app_labels]
    2741
     42        if exclude:
     43            excl_apps = [get_app(app_label) for app_label in exclude]
     44            for excl_app in excl_apps:
     45                app_list.remove(excl_app)
     46                if verbosity >= 2:
     47                   sys.stderr.write( "excluded: %s\n" % excl_app.__name__ )
     48       
     49        if verbosity >= 2:
     50            for app in app_list:
     51                sys.stderr.write( "included: %s\n" % app.__name__ )
     52           
    2853        # Check that the serialization format exists; this is a shortcut to
    2954        # avoid collating all the objects and _then_ failing.
    3055        if format not in serializers.get_public_serializer_formats():
     
    3762
    3863        objects = []
    3964        for app in app_list:
     65            if verbosity >= 1:
     66                sys.stderr.write( "dumping %s/n" % (app.__name__) )
    4067            for model in get_models(app):
     68                if verbosity >= 1:
     69                    # model dosn't have a good __str,
     70                    # so for now "<class... model_name>" is better than nothing.
     71                    sys.stderr.write("dumping %s,%s\n" % (app.__name__, model))
    4172                objects.extend(model._default_manager.all())
    4273        try:
    4374            return serializers.serialize(format, objects, indent=indent)
Back to Top