From a7add2f2965dac3c2f63b1459c8bde725250c977 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Fri, 27 Dec 2013 15:17:56 +0100 Subject: [PATCH] Migrated built-in AppCommands to use handle_app_config. --- django/core/management/commands/sql.py | 8 ++++++-- django/core/management/commands/sqlall.py | 8 ++++++-- django/core/management/commands/sqlclear.py | 8 ++++++-- django/core/management/commands/sqlcustom.py | 8 ++++++-- .../core/management/commands/sqldropindexes.py | 8 ++++++-- django/core/management/commands/sqlindexes.py | 8 ++++++-- .../management/commands/sqlsequencereset.py | 8 ++++++-- .../management/commands/app_command.py | 4 ++-- tests/admin_scripts/tests.py | 17 +++++++---------- 9 files changed, 51 insertions(+), 26 deletions(-) diff --git a/django/core/management/commands/sql.py b/django/core/management/commands/sql.py index 399458693e..b846cc7cd4 100644 --- a/django/core/management/commands/sql.py +++ b/django/core/management/commands/sql.py @@ -18,5 +18,9 @@ class Command(AppCommand): output_transaction = True - def handle_app(self, app, **options): - return '\n'.join(sql_create(app, self.style, connections[options.get('database')])) + def handle_app_config(self, app_config, **options): + if app_config.models_module is None: + return + connection = connections[options.get('database')] + statements = sql_create(app_config.models_module, self.style, connection) + return '\n'.join(statements) diff --git a/django/core/management/commands/sqlall.py b/django/core/management/commands/sqlall.py index 0e2c05ba82..b4e65487f4 100644 --- a/django/core/management/commands/sqlall.py +++ b/django/core/management/commands/sqlall.py @@ -18,5 +18,9 @@ class Command(AppCommand): output_transaction = True - def handle_app(self, app, **options): - return '\n'.join(sql_all(app, self.style, connections[options.get('database')])) + def handle_app_config(self, app_config, **options): + if app_config.models_module is None: + return + connection = connections[options.get('database')] + statements = sql_all(app_config.models_module, self.style, connection) + return '\n'.join(statements) diff --git a/django/core/management/commands/sqlclear.py b/django/core/management/commands/sqlclear.py index efcdbbca35..15efb7872b 100644 --- a/django/core/management/commands/sqlclear.py +++ b/django/core/management/commands/sqlclear.py @@ -18,5 +18,9 @@ class Command(AppCommand): output_transaction = True - def handle_app(self, app, **options): - return '\n'.join(sql_delete(app, self.style, connections[options.get('database')])) + def handle_app_config(self, app_config, **options): + if app_config.models_module is None: + return + connection = connections[options.get('database')] + statements = sql_delete(app_config.models_module, self.style, connection) + return '\n'.join(statements) diff --git a/django/core/management/commands/sqlcustom.py b/django/core/management/commands/sqlcustom.py index b71a3dd6d4..0988654816 100644 --- a/django/core/management/commands/sqlcustom.py +++ b/django/core/management/commands/sqlcustom.py @@ -18,5 +18,9 @@ class Command(AppCommand): output_transaction = True - def handle_app(self, app, **options): - return '\n'.join(sql_custom(app, self.style, connections[options.get('database')])) + def handle_app_config(self, app_config, **options): + if app_config.models_module is None: + return + connection = connections[options.get('database')] + statements = sql_custom(app_config.models_module, self.style, connection) + return '\n'.join(statements) diff --git a/django/core/management/commands/sqldropindexes.py b/django/core/management/commands/sqldropindexes.py index d531808996..ac8469c700 100644 --- a/django/core/management/commands/sqldropindexes.py +++ b/django/core/management/commands/sqldropindexes.py @@ -19,5 +19,9 @@ class Command(AppCommand): output_transaction = True - def handle_app(self, app, **options): - return '\n'.join(sql_destroy_indexes(app, self.style, connections[options.get('database')])) + def handle_app_config(self, app_config, **options): + if app_config.models_module is None: + return + connection = connections[options.get('database')] + statements = sql_destroy_indexes(app_config.models_module, self.style, connection) + return '\n'.join(statements) diff --git a/django/core/management/commands/sqlindexes.py b/django/core/management/commands/sqlindexes.py index 2dc4f35dc6..0ff1ab3914 100644 --- a/django/core/management/commands/sqlindexes.py +++ b/django/core/management/commands/sqlindexes.py @@ -19,5 +19,9 @@ class Command(AppCommand): output_transaction = True - def handle_app(self, app, **options): - return '\n'.join(sql_indexes(app, self.style, connections[options.get('database')])) + def handle_app_config(self, app_config, **options): + if app_config.models_module is None: + return + connection = connections[options.get('database')] + statements = sql_indexes(app_config.models_module, self.style, connection) + return '\n'.join(statements) diff --git a/django/core/management/commands/sqlsequencereset.py b/django/core/management/commands/sqlsequencereset.py index 58f171e87b..d32ff3c5d0 100644 --- a/django/core/management/commands/sqlsequencereset.py +++ b/django/core/management/commands/sqlsequencereset.py @@ -19,6 +19,10 @@ class Command(AppCommand): output_transaction = True - def handle_app(self, app, **options): + def handle_app_config(self, app_config, **options): + if app_config.models_module is None: + return connection = connections[options.get('database')] - return '\n'.join(connection.ops.sequence_reset_sql(self.style, apps.get_models(app, include_auto_created=True))) + models = apps.get_models(app_config.models_module, include_auto_created=True) + statements = connection.ops.sequence_reset_sql(self.style, models) + return '\n'.join(statements) diff --git a/tests/admin_scripts/management/commands/app_command.py b/tests/admin_scripts/management/commands/app_command.py index 5cbddb6e96..5f221f48ee 100644 --- a/tests/admin_scripts/management/commands/app_command.py +++ b/tests/admin_scripts/management/commands/app_command.py @@ -6,5 +6,5 @@ class Command(AppCommand): requires_model_validation = False args = '[appname ...]' - def handle_app(self, app, **options): - print('EXECUTE:AppCommand app=%s, options=%s' % (app, sorted(options.items()))) + def handle_app_config(self, app_config, **options): + print('EXECUTE:AppCommand name=%s, options=%s' % (app_config.name, sorted(options.items()))) diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 3f9a336c16..cc0531a124 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -1416,27 +1416,24 @@ class CommandTypes(AdminScriptTestCase): args = ['app_command', 'auth'] out, err = self.run_manage(args) self.assertNoOutput(err) - self.assertOutput(out, "EXECUTE:AppCommand app=, options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', %(_)s'1')]")) + self.assertOutput(out, "EXECUTE:AppCommand name=django.contrib.auth, options=") + self.assertOutput(out, str_prefix(", options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', %(_)s'1')]")) def test_app_command_no_apps(self): "User AppCommands raise an error when no app name is provided" args = ['app_command'] out, err = self.run_manage(args) - self.assertOutput(err, 'Error: Enter at least one appname.') + self.assertOutput(err, 'Error: Enter at least one application label.') def test_app_command_multiple_apps(self): "User AppCommands raise an error when multiple app names are provided" args = ['app_command', 'auth', 'contenttypes'] out, err = self.run_manage(args) self.assertNoOutput(err) - self.assertOutput(out, "EXECUTE:AppCommand app=, options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', %(_)s'1')]")) - self.assertOutput(out, "EXECUTE:AppCommand app=, options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', %(_)s'1')]")) + self.assertOutput(out, "EXECUTE:AppCommand name=django.contrib.auth, options=") + self.assertOutput(out, str_prefix(", options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', %(_)s'1')]")) + self.assertOutput(out, "EXECUTE:AppCommand name=django.contrib.contenttypes, options=") + self.assertOutput(out, str_prefix(", options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', %(_)s'1')]")) def test_app_command_invalid_appname(self): "User AppCommands can execute when a single app name is provided"