Commits

Simon Law committed 2975407

Push more logic into Migrations.guess_migration

Comments (0)

Files changed (2)

south/migration/__init__.py

     if verbosity:
         print "Running migrations for %s:" % app_name
     # Guess the target_name
-    if target_name not in ["zero", None]:
-        target = migrations.guess_migration(target_name)
-        if target.name() != target_name:
-            if verbosity:
-                print " - Soft matched migration %s to %s." % (target_name,
-                                                               target.name())
-            target_name = target.name()
+    target = migrations.guess_migration(target_name)
+    if verbosity and \
+       target_name not in ('zero', None) and \
+       target.name() != target_name:
+        print " - Soft matched migration %s to %s." % (target_name,
+                                                       target.name())
+        target_name = target.name()
     # Get the forwards and reverse dependencies for this target
     forwards = []
     backwards = []

south/migration/base.py

             return self.migration(value)
         return super(_Migrations, self).__getitem__(value)
 
-    def guess_migration(self, prefix):
+    def _guess_migration(self, prefix):
         prefix = Migration.strip_filename(prefix)
         matches = [m for m in self if m.name().startswith(prefix)]
         if len(matches) == 1:
         else:
             raise exceptions.UnknownMigration(prefix, None)
 
+    def guess_migration(self, target_name):
+        if target_name == 'zero' or not self:
+            return
+        elif target_name is None:
+            return self[-1]
+        else:
+            return self._guess_migration(prefix=target_name)
+
     def app_name(self):
         return get_app_name(self._migrations)
 
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.