exceptions.py 5.0 KB

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