diff options
Diffstat (limited to 'django/core/management')
-rw-r--r-- | django/core/management/__init__.py | 10 | ||||
-rw-r--r-- | django/core/management/base.py | 2 | ||||
-rw-r--r-- | django/core/management/commands/dumpdata.py | 32 | ||||
-rw-r--r-- | django/core/management/commands/flush.py | 10 | ||||
-rw-r--r-- | django/core/management/commands/loaddata.py | 16 | ||||
-rw-r--r-- | django/core/management/commands/syncdb.py | 14 |
6 files changed, 58 insertions, 26 deletions
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index 32e744374a..85bf324fdc 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -250,15 +250,15 @@ class ManagementUtility(object): """ try: app_name = get_commands()[subcommand] - if isinstance(app_name, BaseCommand): - # If the command is already loaded, use it directly. - klass = app_name - else: - klass = load_command_class(app_name, subcommand) except KeyError: sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" % \ (subcommand, self.prog_name)) sys.exit(1) + if isinstance(app_name, BaseCommand): + # If the command is already loaded, use it directly. + klass = app_name + else: + klass = load_command_class(app_name, subcommand) return klass def autocomplete(self): diff --git a/django/core/management/base.py b/django/core/management/base.py index 6761cb69bc..0dc8d0356c 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -118,7 +118,7 @@ class BaseCommand(object): # Metadata about this command. option_list = ( make_option('-v', '--verbosity', action='store', dest='verbosity', default='1', - type='choice', choices=['0', '1', '2'], + type='choice', choices=['0', '1', '2', '3'], help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'), make_option('--settings', help='The Python path to a settings module, e.g. "myproject.settings.main". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.'), diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py index aaaa5845a5..d2fe6cdd07 100644 --- a/django/core/management/commands/dumpdata.py +++ b/django/core/management/commands/dumpdata.py @@ -16,11 +16,12 @@ class Command(BaseCommand): default=DEFAULT_DB_ALIAS, help='Nominates a specific database to load ' 'fixtures into. Defaults to the "default" database.'), make_option('-e', '--exclude', dest='exclude',action='append', default=[], - help='App to exclude (use multiple --exclude to exclude multiple apps).'), + help='An appname or appname.ModelName to exclude (use multiple --exclude to exclude multiple apps/models).'), make_option('-n', '--natural', action='store_true', dest='use_natural_keys', default=False, help='Use natural keys if they are available.'), ) - help = 'Output the contents of the database as a fixture of the given format.' + help = ("Output the contents of the database as a fixture of the given " + "format (using each model's default manager).") args = '[appname appname.ModelName ...]' def handle(self, *app_labels, **options): @@ -30,11 +31,25 @@ class Command(BaseCommand): indent = options.get('indent',None) using = options.get('database', DEFAULT_DB_ALIAS) connection = connections[using] - exclude = options.get('exclude',[]) + excludes = options.get('exclude',[]) show_traceback = options.get('traceback', False) use_natural_keys = options.get('use_natural_keys', False) - excluded_apps = set(get_app(app_label) for app_label in exclude) + excluded_apps = set() + excluded_models = set() + for exclude in excludes: + if '.' in exclude: + app_label, model_name = exclude.split('.', 1) + model_obj = get_model(app_label, model_name) + if not model_obj: + raise CommandError('Unknown model in excludes: %s' % exclude) + excluded_models.add(model_obj) + else: + try: + app_obj = get_app(exclude) + excluded_apps.add(app_obj) + except ImproperlyConfigured: + raise CommandError('Unknown app in excludes: %s' % exclude) if len(app_labels) == 0: app_list = SortedDict((app, None) for app in get_apps() if app not in excluded_apps) @@ -47,7 +62,8 @@ class Command(BaseCommand): app = get_app(app_label) except ImproperlyConfigured: raise CommandError("Unknown application: %s" % app_label) - + if app in excluded_apps: + continue model = get_model(app_label, model_label) if model is None: raise CommandError("Unknown model: %s.%s" % (app_label, model_label)) @@ -64,6 +80,8 @@ class Command(BaseCommand): app = get_app(app_label) except ImproperlyConfigured: raise CommandError("Unknown application: %s" % app_label) + if app in excluded_apps: + continue app_list[app] = None # Check that the serialization format exists; this is a shortcut to @@ -79,6 +97,8 @@ class Command(BaseCommand): # Now collate the objects to be serialized. objects = [] for model in sort_dependencies(app_list.items()): + if model in excluded_models: + continue if not model._meta.proxy and router.allow_syncdb(using, model): objects.extend(model._default_manager.using(using).all()) @@ -163,4 +183,4 @@ def sort_dependencies(app_list): ) model_dependencies = skipped - return model_list
\ No newline at end of file + return model_list diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py index 43279c1a13..0ebe0108fb 100644 --- a/django/core/management/commands/flush.py +++ b/django/core/management/commands/flush.py @@ -1,7 +1,7 @@ from optparse import make_option from django.conf import settings -from django.db import connections, transaction, models, DEFAULT_DB_ALIAS +from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS from django.core.management import call_command from django.core.management.base import NoArgsCommand, CommandError from django.core.management.color import no_style @@ -64,7 +64,13 @@ Are you sure you want to do this? # Emit the post sync signal. This allows individual # applications to respond as if the database had been # sync'd from scratch. - emit_post_sync_signal(models.get_models(), verbosity, interactive, db) + all_models = [] + for app in models.get_apps(): + all_models.extend([ + m for m in models.get_models(app, include_auto_created=True) + if router.allow_syncdb(db, m) + ]) + emit_post_sync_signal(all_models, verbosity, interactive, db) # Reinstall the initial_data fixture. kwargs = options.copy() diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index 5db043e468..cda7daa541 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -112,7 +112,7 @@ class Command(BaseCommand): formats = [] if formats: - if verbosity > 1: + if verbosity >= 2: self.stdout.write("Loading '%s' fixtures...\n" % fixture_name) else: sys.stderr.write( @@ -128,7 +128,7 @@ class Command(BaseCommand): fixture_dirs = app_fixtures + list(settings.FIXTURE_DIRS) + [''] for fixture_dir in fixture_dirs: - if verbosity > 1: + if verbosity >= 2: self.stdout.write("Checking %s for fixtures...\n" % humanize(fixture_dir)) label_found = False @@ -141,7 +141,7 @@ class Command(BaseCommand): if p ) - if verbosity > 1: + if verbosity >= 3: self.stdout.write("Trying %s for %s fixture '%s'...\n" % \ (humanize(fixture_dir), file_name, fixture_name)) full_path = os.path.join(fixture_dir, file_name) @@ -158,7 +158,7 @@ class Command(BaseCommand): else: fixture_count += 1 objects_in_fixture = 0 - if verbosity > 0: + if verbosity >= 2: self.stdout.write("Installing %s fixture '%s' from %s.\n" % \ (format, fixture_name, humanize(fixture_dir))) try: @@ -198,7 +198,7 @@ class Command(BaseCommand): return except Exception, e: - if verbosity > 1: + if verbosity >= 2: self.stdout.write("No %s fixture '%s' in %s.\n" % \ (format, fixture_name, humanize(fixture_dir))) @@ -207,7 +207,7 @@ class Command(BaseCommand): if object_count > 0: sequence_sql = connection.ops.sequence_reset_sql(self.style, models) if sequence_sql: - if verbosity > 1: + if verbosity >= 2: self.stdout.write("Resetting sequences\n") for line in sequence_sql: cursor.execute(line) @@ -217,10 +217,10 @@ class Command(BaseCommand): transaction.leave_transaction_management(using=using) if object_count == 0: - if verbosity > 0: + if verbosity >= 1: self.stdout.write("No fixtures found.\n") else: - if verbosity > 0: + if verbosity >= 1: self.stdout.write("Installed %d object(s) from %d fixture(s)\n" % (object_count, fixture_count)) # Close the DB connection. This is required as a workaround for an diff --git a/django/core/management/commands/syncdb.py b/django/core/management/commands/syncdb.py index d1dd49b75e..3c11a263d6 100644 --- a/django/core/management/commands/syncdb.py +++ b/django/core/management/commands/syncdb.py @@ -76,10 +76,12 @@ class Command(NoArgsCommand): ) # Create the tables for each model + if verbosity >= 1: + print "Creating tables ..." for app_name, model_list in manifest.items(): for model in model_list: # Create the model's database table, if it doesn't already exist. - if verbosity >= 2: + if verbosity >= 3: print "Processing %s.%s model" % (app_name, model._meta.object_name) sql, references = connection.creation.sql_create_model(model, self.style, seen_models) seen_models.add(model) @@ -107,12 +109,14 @@ class Command(NoArgsCommand): # Install custom SQL for the app (but only if this # is a model we've just created) + if verbosity >= 1: + print "Installing custom SQL ..." for app_name, model_list in manifest.items(): for model in model_list: if model in created_models: custom_sql = custom_sql_for_model(model, self.style, connection) if custom_sql: - if verbosity >= 1: + if verbosity >= 2: print "Installing custom SQL for %s.%s model" % (app_name, model._meta.object_name) try: for sql in custom_sql: @@ -127,16 +131,18 @@ class Command(NoArgsCommand): else: transaction.commit_unless_managed(using=db) else: - if verbosity >= 2: + if verbosity >= 3: print "No custom SQL for %s.%s model" % (app_name, model._meta.object_name) + if verbosity >= 1: + print "Installing indexes ..." # Install SQL indicies for all newly created models for app_name, model_list in manifest.items(): for model in model_list: if model in created_models: index_sql = connection.creation.sql_indexes_for_model(model, self.style) if index_sql: - if verbosity >= 1: + if verbosity >= 2: print "Installing index for %s.%s model" % (app_name, model._meta.object_name) try: for sql in index_sql: |