exceptions.py 5.2 KB

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