Commits

Andrew Godwin  committed 3602a98

Fix syncdb-migrateyness

  • Participants
  • Parent commits b6fa8b1

Comments (0)

Files changed (4)

File south/management/commands/__init__.py

+
+# Common framework for syncdb actions
+
+import copy
+
+from django.core import management
+from django.conf import settings
+
+from south.management.commands.syncdb import Command as SyncCommand
+
+class MigrateAndSyncCommand(SyncCommand):
+    """Used for situations where "syncdb" is called by test frameworks."""
+    
+    option_list = copy.deepcopy(SyncCommand.option_list)
+    
+    for opt in option_list:
+        if "--migrate" == opt.get_opt_string():
+            opt.default = True
+            break
+
+def patch_for_test_db_setup():
+    management.get_commands()
+    if hasattr(settings, "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE:
+        # point at the core syncdb command when creating tests
+        # tests should always be up to date with the most recent model structure
+        management._commands['syncdb'] = 'django.core'
+    else:
+        management._commands['syncdb'] = MigrateAndSyncCommand()

File south/management/commands/syncdb.py

             if verbosity:
                 print "\nNot synced (use migrations):\n - %s" % "\n - ".join(apps_migrated)
                 print "(use ./manage.py migrate to migrate these)"
-
-class MigrateAndSyncCommand(Command):
-    """Used for situations where "syncdb" is called by test frameworks."""
-    option_list = Command.option_list
-    for opt in option_list:
-        if "--migrate" == opt.get_opt_string():
-            opt.default = True
-            break
-
-def patch_for_test_db_setup():
-        management.get_commands()
-        if hasattr(settings, "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE:
-            # point at the core syncdb command when creating tests
-            # tests should always be up to date with the most recent model structure
-            management._commands['syncdb'] = 'django.core'
-        else:
-            management._commands['syncdb'] = MigrateAndSyncCommand()

File south/management/commands/test.py

 from django.core.management.commands import test
-import south.management.commands.syncdb
+
+from south.management.commands import patch_for_test_db_setup
 
 class Command(test.Command):
     def handle(self, *args, **kwargs):
-        south.management.commands.syncdb.patch_for_test_db_setup()
+        patch_for_test_db_setup()
         super(Command, self).handle(*args, **kwargs)

File south/management/commands/testserver.py

 from django.core.management.commands import testserver
-import south.management.commands.syncdb
+
+from south.management.commands import patch_for_test_db_setup
 
 class Command(testserver.Command):
     def handle(self, *args, **kwargs):
-        south.management.commands.syncdb.patch_for_test_db_setup()
+        patch_for_test_db_setup()
         super(Command, self).handle(*args, **kwargs)