1 from migrations
import BaseMigration
2 from exceptions
import *
7 def load_migration_from_path(file_path
, dev
=False):
9 Given a file_path to a 001_blah.py file, returns the migration object
10 contained in that file. The file should have a "migration" symbol which
11 is an instance of a BaseMigration subclass. Raise an error otherwise.
13 dir_name
, file_name
= os
.path
.split(file_path
)
15 mod_name
= file_name
.replace('.py', '')
16 dot_py_suffix
= ('.py', 'U', 1) # From imp.get_suffixes()[2]
18 mod
= imp
.load_module(mod_name
, open(file_path
), file_path
, dot_py_suffix
)
21 migration
= mod
.migration
22 except AttributeError:
23 raise BadMigrationError(
24 u
'Module %s has no migration instance' % file_path
27 if not isinstance(migration
, BaseMigration
):
28 raise BadMigrationError(
29 u
'Migration %s is not a BaseMigration subclass' % file_path
32 # Set up .filepath and .name based on where it was loaded from
33 migration
.filepath
= file_path
34 migration
.name
= mod_name