exceptions.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. from traceback import format_exception
  2. class SouthError(RuntimeError):
  3. pass
  4. class BrokenMigration(SouthError):
  5. def __init__(self, migration, exc_info):
  6. self.migration = migration
  7. self.exc_info = exc_info
  8. if self.exc_info:
  9. self.traceback = ''.join(format_exception(*self.exc_info))
  10. def __str__(self):
  11. return ("While loading migration '%(migration)s':\n"
  12. '%(traceback)s' % self.__dict__)
  13. class UnknownMigration(BrokenMigration):
  14. def __str__(self):
  15. return ("Migration '%(migration)s' probably doesn't exist.\n"
  16. '%(traceback)s' % self.__dict__)
  17. class InvalidMigrationModule(SouthError):
  18. def __init__(self, application, module):
  19. self.application = application
  20. self.module = module
  21. def __str__(self):
  22. return ('The migration module specified for %(application)s, %(module)r, is invalid; the parent module does not exist.' % self.__dict__)
  23. class NoMigrations(SouthError):
  24. def __init__(self, application):
  25. self.application = application
  26. def __str__(self):
  27. return "Application '%(application)s' has no migrations." % self.__dict__
  28. class MultiplePrefixMatches(SouthError):
  29. def __init__(self, prefix, matches):
  30. self.prefix = prefix
  31. self.matches = matches
  32. def __str__(self):
  33. self.matches_list = "\n ".join([unicode(m) for m in self.matches])
  34. return ("Prefix '%(prefix)s' matches more than one migration:\n"
  35. " %(matches_list)s") % self.__dict__
  36. class GhostMigrations(SouthError):
  37. def __init__(self, ghosts):
  38. self.ghosts = ghosts
  39. def __str__(self):
  40. self.ghosts_list = "\n ".join([unicode(m) for m in self.ghosts])
  41. return ("\n\n ! These migrations are in the database but not on disk:\n"
  42. " %(ghosts_list)s\n"
  43. " ! I'm not trusting myself; either fix this yourself by fiddling\n"
  44. " ! with the south_migrationhistory table, or pass --delete-ghost-migrations\n"
  45. " ! to South to have it delete ALL of these records (this may not be good).") % self.__dict__
  46. class CircularDependency(SouthError):
  47. def __init__(self, trace):
  48. self.trace = trace
  49. def __str__(self):
  50. trace = " -> ".join([unicode(s) for s in self.trace])
  51. return ("Found circular dependency:\n"
  52. " %s") % trace
  53. class InconsistentMigrationHistory(SouthError):
  54. def __init__(self, problems):
  55. self.problems = problems
  56. def __str__(self):
  57. return ('Inconsistent migration history\n'
  58. 'The following options are available:\n'
  59. ' --merge: will just attempt the migration ignoring any potential dependency conflicts.')
  60. class DependsOnHigherMigration(SouthError):
  61. def __init__(self, migration, depends_on):
  62. self.migration = migration
  63. self.depends_on = depends_on
  64. def __str__(self):
  65. return "Lower migration '%(migration)s' depends on a higher migration '%(depends_on)s' in the same app." % self.__dict__
  66. class DependsOnUnknownMigration(SouthError):
  67. def __init__(self, migration, depends_on):
  68. self.migration = migration
  69. self.depends_on = depends_on
  70. def __str__(self):
  71. print "Migration '%(migration)s' depends on unknown migration '%(depends_on)s'." % self.__dict__
  72. class DependsOnUnmigratedApplication(SouthError):
  73. def __init__(self, migration, application):
  74. self.migration = migration
  75. self.application = application
  76. def __str__(self):
  77. return "Migration '%(migration)s' depends on unmigrated application '%(application)s'." % self.__dict__
  78. class FailedDryRun(SouthError):
  79. def __init__(self, migration, exc_info):
  80. self.migration = migration
  81. self.name = migration.name()
  82. self.exc_info = exc_info
  83. self.traceback = ''.join(format_exception(*self.exc_info))
  84. def __str__(self):
  85. return (" ! Error found during dry run of '%(name)s'! Aborting.\n"
  86. "%(traceback)s") % self.__dict__
  87. class ORMBaseNotIncluded(SouthError):
  88. """Raised when a frozen model has something in _ormbases which isn't frozen."""
  89. pass
  90. class UnfreezeMeLater(Exception):
  91. """An exception, which tells the ORM unfreezer to postpone this model."""
  92. pass
  93. class ImpossibleORMUnfreeze(SouthError):
  94. """Raised if the ORM can't manage to unfreeze all the models in a linear fashion."""
  95. pass