Andrew Godwin avatar Andrew Godwin committed 1356c98 Merge

Branch merge

Comments (0)

Files changed (11)

 syntax: glob
 # No python bytecode
 *.pyc
+# Ignore dist builds and egg info
+dist/*
+South.egg-info/*
 92e1d7754d192043c6eb3c0f7538b7345b26f505 stableish
 92e1d7754d192043c6eb3c0f7538b7345b26f505 stableish
 dbbb515d88cbef75d92864f2ada0ba27b9c487a6 stableish
+dbbb515d88cbef75d92864f2ada0ba27b9c487a6 stableish
+48f193b5cfcc68e663bee6a320dac71758e6cf39 stableish
+48f193b5cfcc68e663bee6a320dac71758e6cf39 0.6-rc1
+48f193b5cfcc68e663bee6a320dac71758e6cf39 stableish
+0333951892018fd1ecc23d1147a5332b2574ca60 stableish
+48f193b5cfcc68e663bee6a320dac71758e6cf39 0.6-rc1
+0333951892018fd1ecc23d1147a5332b2574ca60 0.6-rc1
+8e48729e0eef357f218f194526967593ccfe2117 0.6
+0333951892018fd1ecc23d1147a5332b2574ca60 stableish
+8e48729e0eef357f218f194526967593ccfe2117 stableish
+8e48729e0eef357f218f194526967593ccfe2117 stableish
+2e88bc1e247dee4bcea9455c1d69001375aabe11 stableish

south/__init__.py

 South - Useable migrations for Django apps
 """
 
-__version__ = "0.6-pre"
+__version__ = "0.6.1"
 __authors__ = ["Andrew Godwin <andrew@aeracode.org>", "Andy McCurdy <andy@andymccurdy.com>"]

south/hacks/django_1_0.py

         Reversed the effects of clear_app_cache.
         """
         cache.app_models = self.old_app_models
+    
+    
+    def repopulate_app_cache(self):
+        """
+        Rebuilds AppCache with the real model definitions.
+        """
+        cache._populate()
     

south/management/commands/convert_to_south.py

 from optparse import make_option
 from django.core.exceptions import ImproperlyConfigured
 from south.migration import get_app
+from south.hacks import hacks
 import sys
 
 class Command(BaseCommand):
         # Finally! It seems we've got a candidate, so do the two-command trick
         verbosity = int(options.get('verbosity', 0))
         management.call_command("startmigration", app, initial=True, verbosity=verbosity)
+        
+        # Now, we need to re-clean and sanitise appcache
+        hacks.clear_app_cache()
+        hacks.repopulate_app_cache()
+        
+        # Now, migrate
         management.call_command("migrate", app, "0001", fake=True, verbosity=verbosity)
+        
         print 
         print "App '%s' converted. Note that South assumed the application's models matched the database" % app
         print "(i.e. you haven't changed it since last syncdb); if you have, you should delete the %s/migrations"

south/management/commands/migrate.py

             list_migrations(apps)
         
         if not list:
+            tree = migration.dependency_tree()
+            
             for app in apps:
                 result = migration.migrate_app(
                     app,
+                    tree,
                     resolve_mode = resolve_mode,
                     target_name = target,
                     fake = fake,

south/management/commands/startmigration.py

             new = dict([
                 (model_key(model), prep_for_freeze(model))
                 for model in models.get_models(app_models_module)
+                if (not getattr(model._meta, "proxy", False) and getattr(model._meta, "managed", True))
             ])
             # And filter other apps out of the old
             old = dict([
                     )
                 continue
             
-            # Add any dependencies
-            deps = field_dependencies(field, last_models)
-            deps.update(frozen_models)
-            frozen_models = deps
-            
             # Work out the definition
             triple = remove_useless_attributes(triple)
             field_definition = make_field_constructor(app, field, triple)
             
             print " - Deleted model '%s.%s'" % (model._meta.app_label,model._meta.object_name)
             
-            # Add the model's dependencies to the frozens
-            deps = model_dependencies(model, last_models)
-            deps.update(frozen_models)
-            frozen_models = deps
-            
             # Turn the (class, args, kwargs) format into a string
             fields = triples_to_defs(app, model, fields)
             
                 cols,
             )
             
-            backwards += DELETE_UNIQUE_SNIPPET % (
+            backwards = DELETE_UNIQUE_SNIPPET % (
                 ", ".join(ut),
                 model._meta.object_name,
                 model._meta.db_table,
                 cols,
-            )
+            ) + backwards
         
         
         ### Deleted unique_togethers ###
             
             cols = [get_field_column(model, f) for f in ut]
             
-            forwards += DELETE_UNIQUE_SNIPPET % (
+            forwards = DELETE_UNIQUE_SNIPPET % (
                 ", ".join(ut),
                 model._meta.object_name,
                 model._meta.db_table,
                 cols,
-            )
+            ) + forwards
             
             backwards += CREATE_UNIQUE_SNIPPET % (
                 ", ".join(ut),

south/management/commands/syncdb.py

             help='Tells Django to NOT prompt the user for input of any kind.'),
         make_option('--migrate', action='store_true', dest='migrate', default=False,
             help='Tells South to also perform migrations after the sync. Default for during testing, and other internal calls.'),
+        make_option('--all', action='store_true', dest='migrate_all', default=False,
+            help='Makes syncdb work on all apps, even migrated ones. Be careful!'),
     )
     if '--verbosity' not in [opt.get_opt_string() for opt in BaseCommand.option_list]:
         option_list += (
         )
     help = "Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created, except those which use migrations."
 
-    def handle_noargs(self, **options):
+    def handle_noargs(self, migrate_all=False, **options):
         # Work out what uses migrations and so doesn't need syncing
         apps_needing_sync = []
         apps_migrated = []
         for app in models.get_apps():
             app_name = get_app_name(app)
             migrations = migration.get_app(app)
-            if migrations is None:
+            if migrations is None or migrate_all:
                 apps_needing_sync.append(app_name)
             else:
                 # This is a migrated app, leave it
                 apps_migrated.append(app_name)
         verbosity = int(options.get('verbosity', 0))
+        
         # Run syncdb on only the ones needed
         if verbosity:
             print "Syncing..."
+        
         old_installed, settings.INSTALLED_APPS = settings.INSTALLED_APPS, apps_needing_sync
         old_app_store, cache.app_store = cache.app_store, SortedDict([
             (k, v) for (k, v) in cache.app_store.items()
             if get_app_name(k) in apps_needing_sync
         ])
+        
         # This will allow the setting of the MySQL storage engine, for example.
         db.connection_init()
+        
         # OK, run the actual syncdb
         syncdb.Command().execute(**options)
+        
         settings.INSTALLED_APPS = old_installed
         cache.app_store = old_app_store
+        
         # Migrate if needed
         if options.get('migrate', True):
             if verbosity:
                 print "Migrating..."
             management.call_command('migrate', **options)
+        
         # Be obvious about what we did
         if verbosity:
             print "\nSynced:\n > %s" % "\n > ".join(apps_needing_sync)

south/migration.py

     """
     Returns a list of migration file names for the given app.
     """
-    return sorted([
-        filename[:-3]
+    if getattr(settings, "SOUTH_USE_PYC", False):
+        allowed_extensions = (".pyc", ".py")
+        ignored_files = ("__init__.pyc", "__init__.py")
+    else:
+        allowed_extensions = (".py",)
+        ignored_files = ("__init__.py",)
+    
+    return sorted(set([
+        os.path.splitext(filename)[0]
         for filename in os.listdir(os.path.dirname(app.__file__))
-        if filename.endswith(".py") and filename != "__init__.py" and not filename.startswith(".")
-    ])
+        if os.path.splitext(filename)[1] in allowed_extensions and filename not in ignored_files and not filename.startswith(".")
+    ]))
 
 
 def get_migration_classes(app):
             recorder(app_name, migration)
             if not fake:
                 # Send a signal saying it ran
-                ran_migration.send(None, app=app_name, migration=migration, method=torun)
+                # Actually, don't - we're implementing this properly in 0.7
+                #ran_migration.send(None, app=app_name, migration=migration, method=torun)
+                pass
 
 
 def run_forwards(app, migrations, fake=False, db_dry_run=False, verbosity=0):
     return problems
 
 
-def migrate_app(app, target_name=None, resolve_mode=None, fake=False, db_dry_run=False, yes=False, verbosity=0, load_inital_data=False, skip=False):
+def migrate_app(app, tree, target_name=None, resolve_mode=None, fake=False, db_dry_run=False, yes=False, verbosity=0, load_inital_data=False, skip=False):
     
     app_name = get_app_name(app)
     verbosity = int(verbosity)
     pre_migrate.send(None, app=app_name)
     
     # Find out what delightful migrations we have
-    tree = dependency_tree()
     migrations = get_migration_names(app)
     
     # If there aren't any, quit quizically

south/modelsinspector.py

             raise IsDefault
     # Models get their own special repr()
     if isinstance(value, ModelBase):
+        # If it's a proxy model, follow it back to its non-proxy parent
+        if getattr(value._meta, "proxy", False):
+            value = value._meta.proxy_for_model
         return "orm['%s.%s']" % (value._meta.app_label, value._meta.object_name)
     # Callables get called.
     elif callable(value):

south/tests/logic.py

         self.assertEqual(list(migration.MigrationHistory.objects.all()), [])
         
         # Apply them normally
-        migration.migrate_app(app, target_name=None, resolve_mode=None, fake=False, verbosity=0)
+        tree = migration.dependency_tree()
+        migration.migrate_app(app, tree, target_name=None, resolve_mode=None, fake=False, verbosity=0)
         
         # We should finish with all migrations
         self.assertListEqual(
         )
         
         # Now roll them backwards
-        migration.migrate_app(app, target_name="zero", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(app, tree, target_name="zero", resolve_mode=None, fake=False, verbosity=0)
         
         # Finish with none
         self.assertEqual(list(migration.MigrationHistory.objects.all()), [])
         )
         
         # Apply them normally
+        tree = migration.dependency_tree()
         try:
             # Redirect the error it will print to nowhere
             stdout, sys.stdout = sys.stdout, StringIO.StringIO()
-            migration.migrate_app(app, target_name=None, resolve_mode=None, fake=False, verbosity=0)
+            migration.migrate_app(app, tree, target_name=None, resolve_mode=None, fake=False, verbosity=0)
             sys.stdout = stdout
         except SystemExit:
             pass
         )
         
         # Apply with merge
-        migration.migrate_app(app, target_name=None, resolve_mode="merge", fake=False, verbosity=0)
+        migration.migrate_app(app, tree, target_name=None, resolve_mode="merge", fake=False, verbosity=0)
         
         # We should finish with all migrations
         self.assertListEqual(
         )
         
         # Now roll them backwards
-        migration.migrate_app(app, target_name="0002", resolve_mode=None, fake=False, verbosity=0)
-        migration.migrate_app(app, target_name="0001", resolve_mode=None, fake=True, verbosity=0)
-        migration.migrate_app(app, target_name="zero", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(app, tree, target_name="0002", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(app, tree, target_name="0001", resolve_mode=None, fake=True, verbosity=0)
+        migration.migrate_app(app, tree, target_name="zero", resolve_mode=None, fake=False, verbosity=0)
         
         # Finish with none
         self.assertEqual(list(migration.MigrationHistory.objects.all()), [])
                 return True
         
         app = migration.get_app("fakeapp")
+        tree = migration.dependency_tree()
         self.assertEqual(list(migration.MigrationHistory.objects.all()), [])
         
         # by default name is NOT NULL
-        migration.migrate_app(app, target_name="0002", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(app, tree, target_name="0002", resolve_mode=None, fake=False, verbosity=0)
         self.failIf(null_ok())
         
         # after 0003, it should be NULL
-        migration.migrate_app(app, target_name="0003", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(app, tree, target_name="0003", resolve_mode=None, fake=False, verbosity=0)
         self.assert_(null_ok())
 
         # make sure it is NOT NULL again
-        migration.migrate_app(app, target_name="0002", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(app, tree, target_name="0002", resolve_mode=None, fake=False, verbosity=0)
         self.failIf(null_ok(), 'name not null after migration')
         
         # finish with no migrations, otherwise other tests fail...
-        migration.migrate_app(app, target_name="zero", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(app, tree, target_name="zero", resolve_mode=None, fake=False, verbosity=0)
         self.assertEqual(list(migration.MigrationHistory.objects.all()), [])
     
     def test_dependencies(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.