Project

General

Profile

Statistics
| Branch: | Revision:

root / env / lib / python2.7 / site-packages / south / exceptions.py @ d1a4905f

History | View | Annotate | Download (4.86 KB)

1
from traceback import format_exception
2

    
3
class SouthError(RuntimeError):
4
    pass
5

    
6
class SouthWarning(RuntimeWarning):
7
    pass
8

    
9
class BrokenMigration(SouthError):
10
    def __init__(self, migration, exc_info):
11
        self.migration = migration
12
        self.exc_info = exc_info
13
        if self.exc_info:
14
            self.traceback = ''.join(format_exception(*self.exc_info))
15

    
16
    def __str__(self):
17
        return ("While loading migration '%(migration)s':\n"
18
                '%(traceback)s' % self.__dict__)
19

    
20

    
21
class UnknownMigration(BrokenMigration):
22
    def __str__(self):
23
        return ("Migration '%(migration)s' probably doesn't exist.\n"
24
                '%(traceback)s' % self.__dict__)
25

    
26

    
27
class InvalidMigrationModule(SouthError):
28
    def __init__(self, application, module):
29
        self.application = application
30
        self.module = module
31
    
32
    def __str__(self):
33
        return ('The migration module specified for %(application)s, %(module)r, is invalid; the parent module does not exist.' % self.__dict__)
34

    
35

    
36
class NoMigrations(SouthError):
37
    def __init__(self, application):
38
        self.application = application
39

    
40
    def __str__(self):
41
        return "Application '%(application)s' has no migrations." % self.__dict__
42

    
43

    
44
class MultiplePrefixMatches(SouthError):
45
    def __init__(self, prefix, matches):
46
        self.prefix = prefix
47
        self.matches = matches
48

    
49
    def __str__(self):
50
        self.matches_list = "\n    ".join([unicode(m) for m in self.matches])
51
        return ("Prefix '%(prefix)s' matches more than one migration:\n"
52
                "    %(matches_list)s") % self.__dict__
53

    
54

    
55
class GhostMigrations(SouthError):
56
    def __init__(self, ghosts):
57
        self.ghosts = ghosts
58

    
59
    def __str__(self):
60
        self.ghosts_list = "\n    ".join([unicode(m) for m in self.ghosts])
61
        return ("\n\n ! These migrations are in the database but not on disk:\n"
62
                "    %(ghosts_list)s\n"
63
                " ! I'm not trusting myself; either fix this yourself by fiddling\n"
64
                " ! with the south_migrationhistory table, or pass --delete-ghost-migrations\n"
65
                " ! to South to have it delete ALL of these records (this may not be good).") % self.__dict__
66

    
67

    
68
class CircularDependency(SouthError):
69
    def __init__(self, trace):
70
        self.trace = trace
71

    
72
    def __str__(self):
73
        trace = " -> ".join([unicode(s) for s in self.trace])
74
        return ("Found circular dependency:\n"
75
                "    %s") % trace
76

    
77

    
78
class InconsistentMigrationHistory(SouthError):
79
    def __init__(self, problems):
80
        self.problems = problems
81

    
82
    def __str__(self):
83
        return ('Inconsistent migration history\n'
84
                'The following options are available:\n'
85
                '    --merge: will just attempt the migration ignoring any potential dependency conflicts.')
86

    
87

    
88
class DependsOnHigherMigration(SouthError):
89
    def __init__(self, migration, depends_on):
90
        self.migration = migration
91
        self.depends_on = depends_on
92

    
93
    def __str__(self):
94
        return "Lower migration '%(migration)s' depends on a higher migration '%(depends_on)s' in the same app." % self.__dict__
95

    
96

    
97
class DependsOnUnknownMigration(SouthError):
98
    def __init__(self, migration, depends_on):
99
        self.migration = migration
100
        self.depends_on = depends_on
101

    
102
    def __str__(self):
103
        print "Migration '%(migration)s' depends on unknown migration '%(depends_on)s'." % self.__dict__
104

    
105

    
106
class DependsOnUnmigratedApplication(SouthError):
107
    def __init__(self, migration, application):
108
        self.migration = migration
109
        self.application = application
110

    
111
    def __str__(self):
112
        return "Migration '%(migration)s' depends on unmigrated application '%(application)s'." % self.__dict__
113

    
114

    
115
class FailedDryRun(SouthError):
116
    def __init__(self, migration, exc_info):
117
        self.migration = migration
118
        self.name = migration.name()
119
        self.exc_info = exc_info
120
        self.traceback = ''.join(format_exception(*self.exc_info))
121

    
122
    def __str__(self):
123
        return (" ! Error found during dry run of '%(name)s'! Aborting.\n"
124
                "%(traceback)s") % self.__dict__
125

    
126

    
127
class ORMBaseNotIncluded(SouthError):
128
    """Raised when a frozen model has something in _ormbases which isn't frozen."""
129
    pass
130

    
131

    
132
class UnfreezeMeLater(Exception):
133
    """An exception, which tells the ORM unfreezer to postpone this model."""
134
    pass
135

    
136

    
137
class ImpossibleORMUnfreeze(SouthError):
138
    """Raised if the ORM can't manage to unfreeze all the models in a linear fashion."""
139
    pass
140

    
141
class ConstraintDropped(SouthWarning):
142
    def __init__(self, constraint, table, column=None):
143
        self.table = table
144
        if column:
145
            self.column = ".%s" % column
146
        else:
147
            self.column = ""
148
        self.constraint = constraint
149
    
150
    def __str__(self):
151
        return "Constraint %(constraint)s was dropped from %(table)s%(column)s -- was this intended?" % self.__dict__