1
from optparse import make_option
4
from django.core.management.base import BaseCommand, CommandError
8
class Command(BaseCommand):
9
option_list = BaseCommand.option_list + (
10
make_option('-l', '--list', dest='list', action='store_true', default=False,
11
help='Show all available migrations'),
12
make_option('-e', '--exec', dest='migration', help='Execute the migration')
14
help = 'Execute migration scripts.'
16
def handle(self, *args, **kwargs):
19
elif kwargs['migration']:
20
self.command_migrate(kwargs['migration'])
22
print 'Invalid options'
25
def command_list(self):
26
root = os.path.dirname(os.path.realpath(pybb.__file__))
27
dir = os.path.join(root, 'migrations')
29
for fname in os.listdir(dir):
30
if fname.endswith('.py'):
32
mod = __import__('pybb.migrations.%s' % mod_name,
33
globals(), locals(), ['foobar'])
34
if hasattr(mod, 'migrate'):
35
migs.append((mod_name, mod))
37
migs = sorted(migs, lambda a, b: cmp(a[0], b[0]))
38
for name, mig in migs:
39
print '%s - %s' % (name, mig.DESCRIPTION)
42
def command_migrate(self, mod_name):
43
mod = __import__('pybb.migrations.%s' % mod_name,
44
globals(), locals(), ['foobar'])