getting file size for all dict files to be downloaded. coming to be 400mb or so.
[worddb.git] / libs / dmigrations / migration_loader.py
blob14ccbe6fa891dd18513c9b53f20005dbf13c61d4
1 from migrations import BaseMigration
2 from exceptions import *
4 import imp
5 import os
7 def load_migration_from_path(file_path, dev=False):
8 """
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.
12 """
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)
20 try:
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
35 migration.dev = dev
37 return migration