Ejemplo n.º 1
0
    def handle_noargs(self, migrate_all=False, **options):
        # Work out what uses migrations and so doesn't need syncing
        apps_needing_sync = []
        apps_migrated = []
        for app in models.get_apps():
            app_label = get_app_label(app)
            if migrate_all:
                apps_needing_sync.append(app_label)
            else:
                try:
                    migrations = migration.Migrations(app_label)
                except NoMigrations:
                    # It needs syncing
                    apps_needing_sync.append(app_label)
                else:
                    # This is a migrated app, leave it
                    apps_migrated.append(app_label)
        verbosity = int(options.get('verbosity', 0))

        # Run syncdb on only the ones needed
        if verbosity:
            print "Syncing..."

        old_installed, settings.INSTALLED_APPS = settings.INSTALLED_APPS, apps_needing_sync
        old_app_store, cache.app_store = cache.app_store, SortedDict([
            (k, v) for (k, v) in cache.app_store.items()
            if get_app_label(k) in apps_needing_sync
        ])

        # This will allow the setting of the MySQL storage engine, for example.
        for db in dbs.values():
            db.connection_init()

        # OK, run the actual syncdb
        syncdb.Command().execute(**options)

        settings.INSTALLED_APPS = old_installed
        cache.app_store = old_app_store

        # Migrate if needed
        if options.get('migrate', True):
            if verbosity:
                print "Migrating..."
            management.call_command('migrate', **options)

        # Be obvious about what we did
        if verbosity:
            print "\nSynced:\n > %s" % "\n > ".join(apps_needing_sync)

        if options.get('migrate', True):
            if verbosity:
                print "\nMigrated:\n - %s" % "\n - ".join(apps_migrated)
        else:
            if verbosity:
                print "\nNot synced (use migrations):\n - %s" % "\n - ".join(
                    apps_migrated)
                print "(use ./manage.py migrate to migrate these)"
Ejemplo n.º 2
0
 def handle_noargs(self, migrate_all=False, **options):
     # Work out what uses migrations and so doesn't need syncing
     apps_needing_sync = []
     apps_migrated = []
     for app in models.get_apps():
         app_label = get_app_label(app)
         if migrate_all:
             apps_needing_sync.append(app_label)
         else:
             try:
                 migrations = migration.Migrations(app_label)
             except NoMigrations:
                 # It needs syncing
                 apps_needing_sync.append(app_label)
             else:
                 # This is a migrated app, leave it
                 apps_migrated.append(app_label)
     verbosity = int(options.get('verbosity', 0))
     
     # Run syncdb on only the ones needed
     if verbosity:
         print "Syncing..."
     
     old_installed, settings.INSTALLED_APPS = settings.INSTALLED_APPS, apps_needing_sync
     old_app_store, cache.app_store = cache.app_store, SortedDict([
         (k, v) for (k, v) in cache.app_store.items()
         if get_app_label(k) in apps_needing_sync
     ])
     
     # This will allow the setting of the MySQL storage engine, for example.
     for db in dbs.values(): 
         db.connection_init() 
     
     # OK, run the actual syncdb
     syncdb.Command().execute(**options)
     
     settings.INSTALLED_APPS = old_installed
     cache.app_store = old_app_store
     
     # Migrate if needed
     if options.get('migrate', True):
         if verbosity:
             print "Migrating..."
         management.call_command('migrate', **options)
     
     # Be obvious about what we did
     if verbosity:
         print "\nSynced:\n > %s" % "\n > ".join(apps_needing_sync)
     
     if options.get('migrate', True):
         if verbosity:
             print "\nMigrated:\n - %s" % "\n - ".join(apps_migrated)
     else:
         if verbosity:
             print "\nNot synced (use migrations):\n - %s" % "\n - ".join(apps_migrated)
             print "(use ./manage.py migrate to migrate these)"
Ejemplo n.º 3
0
Archivo: syncdb.py Proyecto: 10sr/hue
 def handle_noargs(self, migrate_all=False, **options):
     
     # Import the 'management' module within each installed app, to register
     # dispatcher events.
     # This is copied from Django, to fix bug #511.
     try:
         from django.utils.importlib import import_module
     except ImportError:
         pass # TODO: Remove, only for Django1.0
     else:
         for app_name in settings.INSTALLED_APPS:
             try:
                 import_module('.management', app_name)
             except ImportError as exc:
                 msg = exc.args[0]
                 if not msg.startswith('No module named') or 'management' not in msg:
                     raise
     
     # Work out what uses migrations and so doesn't need syncing
     apps_needing_sync = []
     apps_migrated = []
     for app in models.get_apps():
         app_label = get_app_label(app)
         if migrate_all:
             apps_needing_sync.append(app_label)
         else:
             try:
                 migrations = migration.Migrations(app_label)
             except NoMigrations:
                 # It needs syncing
                 apps_needing_sync.append(app_label)
             else:
                 # This is a migrated app, leave it
                 apps_migrated.append(app_label)
     verbosity = int(options.get('verbosity', 0))
     
     # Run syncdb on only the ones needed
     if verbosity:
         print("Syncing...")
     
     old_installed, settings.INSTALLED_APPS = settings.INSTALLED_APPS, apps_needing_sync
     old_app_store, cache.app_store = cache.app_store, SortedDict([
         (k, v) for (k, v) in cache.app_store.items()
         if get_app_label(k) in apps_needing_sync
     ])
     
     # This will allow the setting of the MySQL storage engine, for example.
     for db in dbs.values(): 
         db.connection_init() 
     
     # OK, run the actual syncdb
     syncdb.Command().execute(**options)
     
     settings.INSTALLED_APPS = old_installed
     cache.app_store = old_app_store
     
     # Migrate if needed
     if options.get('migrate', True):
         if verbosity:
             print("Migrating...")
         # convert from store_true to store_false
         options['no_initial_data'] = not options.get('load_initial_data', True)
         management.call_command('migrate', **options)
     
     # Be obvious about what we did
     if verbosity:
         print("\nSynced:\n > %s" % "\n > ".join(apps_needing_sync))
     
     if options.get('migrate', True):
         if verbosity:
             print("\nMigrated:\n - %s" % "\n - ".join(apps_migrated))
     else:
         if verbosity:
             print("\nNot synced (use migrations):\n - %s" % "\n - ".join(apps_migrated))
             print("(use ./manage.py migrate to migrate these)")
Ejemplo n.º 4
0
    def handle_noargs(self, **options):
        # Import the 'management' module within each installed app, to register
        # dispatcher events.
        if not hasattr(self, 'stdout'):
            self.stdout = sys.stdout
            self.stderr = sys.stderr
        if DJANGO_17:
            from django.apps import apps
            from django.utils.module_loading import module_has_submodule

            for app_config in apps.get_app_configs():
                if module_has_submodule(app_config.module, "management"):
                    import_module('.management', app_config.name)
        else:
            for app_name in settings.INSTALLED_APPS:
                try:
                    import_module('.management', app_name)
                except ImportError as exc:
                    msg = exc.args[0]
                    if not msg.startswith(
                            'No module named') or 'management' not in msg:
                        raise

        # Work out what uses migrations and so doesn't need syncing
        apps_needing_sync = []
        apps_migrated = []
        app_name_to_app_map = {}

        if DJANGO_17:
            for app_config in apps.get_app_configs():
                if not app_config.models_module:
                    continue

                app_label = get_app_label(app_config.models_module)
                app_name_to_app_map[app_label] = app_config
                try:
                    migrations = migration.Migrations(app_label)
                except NoMigrations:
                    # It needs syncing
                    apps_needing_sync.append(app_label)
                else:
                    # This is a migrated app, leave it
                    apps_migrated.append(app_label)
        else:
            for app in models.get_apps():
                app_label = get_app_label(app)
                try:
                    migrations = migration.Migrations(app_label)
                except NoMigrations:
                    # It needs syncing
                    apps_needing_sync.append(app_label)
                else:
                    # This is a migrated app, leave it
                    apps_migrated.append(app_label)

        verbosity = int(options.get('verbosity', 0))

        # Run syncdb on only the ones needed
        if verbosity:
            self.stdout.write("Syncing...\n")

        # This will allow the setting of the MySQL storage engine, for example.
        for db in dbs.values():
            db.connection_init()

        # In Django 1.7 we need to actually run migrations (Sentry specifically)
        # as it creates the 'auth' table. To run migrations however we still need
        # to create the south tables ahead of time.
        if DJANGO_17:
            self.sync_apps(['south'], app_name_to_app_map, options)
            apps_needing_sync.remove('south')
        # In 1.6 the constraints dont function/get created in the same way, and
        # additionally contenttypes tries to apply so syncing just south isnt enough
        else:
            self.sync_apps(apps_needing_sync, app_name_to_app_map, options)

        # Migrate if needed
        if options.get('migrate', True):
            if verbosity:
                self.stdout.write("Migrating...\n")
            management.call_command('south_migrate', **options)

        if DJANGO_17:
            self.sync_apps(apps_needing_sync, app_name_to_app_map, options)

        # Be obvious about what we did
        if verbosity:
            self.stdout.write("\nSynced:\n > {}\n".format(
                "\n > ".join(apps_needing_sync)))

        if options.get('migrate', True):
            if verbosity:
                self.stdout.write("\nMigrated:\n - {}\n".format(
                    "\n - ".join(apps_migrated)))
        else:
            if verbosity:
                self.stdout.write(
                    "\nNot synced (use migrations):\n - {}\n".format(
                        "\n - ".join(apps_migrated)))
                self.stdout.write(
                    "(use ./manage.py migrate to migrate these)\n")
Ejemplo n.º 5
0
    def handle_noargs(self, migrate_all=False, **options):

        # Import the 'management' module within each installed app, to register
        # dispatcher events.
        # This is copied from Django, to fix bug #511.
        try:
            from django.utils.importlib import import_module
        except ImportError:
            pass  # TODO: Remove, only for Django1.0
        else:
            for app_name in settings.INSTALLED_APPS:
                try:
                    import_module('.management', app_name)
                except ImportError as exc:
                    msg = exc.args[0]
                    if not msg.startswith(
                            'No module named') or 'management' not in msg:
                        raise

        # Work out what uses migrations and so doesn't need syncing
        apps_needing_sync = []
        apps_migrated = []
        for app in models.get_apps():
            app_label = get_app_label(app)
            if migrate_all:
                apps_needing_sync.append(app_label)
            else:
                try:
                    migrations = migration.Migrations(app_label)
                except NoMigrations:
                    # It needs syncing
                    apps_needing_sync.append(app_label)
                else:
                    # This is a migrated app, leave it
                    apps_migrated.append(app_label)
        verbosity = int(options.get('verbosity', 0))

        # Run syncdb on only the ones needed
        if verbosity:
            print("Syncing...")

        old_installed, settings.INSTALLED_APPS = settings.INSTALLED_APPS, apps_needing_sync
        old_app_store, cache.app_store = cache.app_store, SortedDict([
            (k, v) for (k, v) in cache.app_store.items()
            if get_app_label(k) in apps_needing_sync
        ])

        # This will allow the setting of the MySQL storage engine, for example.
        for db in dbs.values():
            db.connection_init()

        # OK, run the actual syncdb
        syncdb.Command().execute(**options)

        settings.INSTALLED_APPS = old_installed
        cache.app_store = old_app_store

        # Migrate if needed
        if options.get('migrate', True):
            if verbosity:
                print("Migrating...")
            # convert from store_true to store_false
            options['no_initial_data'] = not options.get(
                'load_initial_data', True)
            management.call_command('migrate', **options)

        # Be obvious about what we did
        if verbosity:
            print("\nSynced:\n > %s" % "\n > ".join(apps_needing_sync))

        if options.get('migrate', True):
            if verbosity:
                print("\nMigrated:\n - %s" % "\n - ".join(apps_migrated))
        else:
            if verbosity:
                print("\nNot synced (use migrations):\n - %s" %
                      "\n - ".join(apps_migrated))
                print("(use ./manage.py migrate to migrate these)")
Ejemplo n.º 6
0
    def handle_noargs(self, **options):
        # Import the 'management' module within each installed app, to register
        # dispatcher events.
        if not hasattr(self, 'stdout'):
            self.stdout = sys.stdout
            self.stderr = sys.stderr
        if DJANGO_17:
            from django.apps import apps
            from django.utils.module_loading import module_has_submodule

            for app_config in apps.get_app_configs():
                if module_has_submodule(app_config.module, "management"):
                    import_module('.management', app_config.name)
        else:
            for app_name in settings.INSTALLED_APPS:
                try:
                    import_module('.management', app_name)
                except ImportError as exc:
                    msg = exc.args[0]
                    if not msg.startswith('No module named') or 'management' not in msg:
                        raise

        # Work out what uses migrations and so doesn't need syncing
        apps_needing_sync = []
        apps_migrated = []
        app_name_to_app_map = {}

        if DJANGO_17:
            for app_config in apps.get_app_configs():
                if not app_config.models_module:
                    continue

                app_label = get_app_label(app_config.models_module)
                app_name_to_app_map[app_label] = app_config
                try:
                    migrations = migration.Migrations(app_label)
                except NoMigrations:
                    # It needs syncing
                    apps_needing_sync.append(app_label)
                else:
                    # This is a migrated app, leave it
                    apps_migrated.append(app_label)
        else:
            for app in models.get_apps():
                app_label = get_app_label(app)
                try:
                    migrations = migration.Migrations(app_label)
                except NoMigrations:
                    # It needs syncing
                    apps_needing_sync.append(app_label)
                else:
                    # This is a migrated app, leave it
                    apps_migrated.append(app_label)

        verbosity = int(options.get('verbosity', 0))

        # Run syncdb on only the ones needed
        if verbosity:
            self.stdout.write("Syncing...\n")

        # This will allow the setting of the MySQL storage engine, for example.
        for db in dbs.values():
            db.connection_init()

        # In Django 1.7 we need to actually run migrations (Sentry specifically)
        # as it creates the 'auth' table. To run migrations however we still need
        # to create the south tables ahead of time.
        if DJANGO_17:
            self.sync_apps(['south'], app_name_to_app_map, options)
            apps_needing_sync.remove('south')
        # In 1.6 the constraints dont function/get created in the same way, and
        # additionally contenttypes tries to apply so syncing just south isnt enough
        else:
            self.sync_apps(apps_needing_sync, app_name_to_app_map, options)

        # Migrate if needed
        if options.get('migrate', True):
            if verbosity:
                self.stdout.write("Migrating...\n")
            management.call_command('south_migrate', **options)

        if DJANGO_17:
            self.sync_apps(apps_needing_sync, app_name_to_app_map, options)

        # Be obvious about what we did
        if verbosity:
            self.stdout.write("\nSynced:\n > {}\n".format("\n > ".join(apps_needing_sync)))

        if options.get('migrate', True):
            if verbosity:
                self.stdout.write("\nMigrated:\n - {}\n".format("\n - ".join(apps_migrated)))
        else:
            if verbosity:
                self.stdout.write(
                    "\nNot synced (use migrations):\n - {}\n".format(
                        "\n - ".join(apps_migrated)))
                self.stdout.write("(use ./manage.py migrate to migrate these)\n")
Ejemplo n.º 7
0
class Command(NoArgsCommand):
    option_list = syncdb.Command.option_list + (
        make_option(
            '--migrate',
            action='store_true',
            dest='migrate',
            default=False,
            help=
            'Tells South to also perform migrations after the sync. Default for during testing, and other internal calls.'
        ),
        make_option(
            '--all',
            action='store_true',
            dest='migrate_all',
            default=False,
            help=
            'Makes syncdb work on all apps, even migrated ones. Be careful!'),
    )
    if '--verbosity' not in [
            opt.get_opt_string() for opt in syncdb.Command.option_list
    ]:
        option_list += (make_option(
            '--verbosity',
            action='store',
            dest='verbosity',
            default='1',
            type='choice',
            choices=['0', '1', '2'],
            help=
            'Verbosity level; 0=minimal output, 1=normal output, 2=all output'
        ), )
    help = "Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created, except those which use migrations."

    def handle_noargs(self, migrate_all=False, **options):

        # Import the 'management' module within each installed app, to register
        # dispatcher events.
        # This is copied from Django, to fix bug #511.
        try:
            from django.utils.importlib import import_module
        except ImportError:
            pass  # TODO: Remove, only for Django1.0
        else:
            for app_name in settings.INSTALLED_APPS:
                try:
                    import_module('.management', app_name)
                except ImportError, exc:
                    msg = exc.args[0]
                    if not msg.startswith(
                            'No module named') or 'management' not in msg:
                        raise

        # Work out what uses migrations and so doesn't need syncing
        apps_needing_sync = []
        apps_migrated = []
        for app in models.get_apps():
            app_label = get_app_label(app)
            if migrate_all:
                apps_needing_sync.append(app_label)
            else:
                try:
                    migrations = migration.Migrations(app_label)
                except NoMigrations:
                    # It needs syncing
                    apps_needing_sync.append(app_label)
                else:
                    # This is a migrated app, leave it
                    apps_migrated.append(app_label)
        verbosity = int(options.get('verbosity', 0))

        # Run syncdb on only the ones needed
        if verbosity:
            print "Syncing..."

        old_installed, settings.INSTALLED_APPS = settings.INSTALLED_APPS, apps_needing_sync
        old_app_store, cache.app_store = cache.app_store, SortedDict([
            (k, v) for (k, v) in cache.app_store.items()
            if get_app_label(k) in apps_needing_sync
        ])

        # This will allow the setting of the MySQL storage engine, for example.
        for db in dbs.values():
            db.connection_init()

        # OK, run the actual syncdb
        syncdb.Command().execute(**options)

        settings.INSTALLED_APPS = old_installed
        cache.app_store = old_app_store

        # Migrate if needed
        if options.get('migrate', True):
            if verbosity:
                print "Migrating..."
            management.call_command('migrate', **options)

        # Be obvious about what we did
        if verbosity:
            print "\nSynced:\n > %s" % "\n > ".join(apps_needing_sync)

        if options.get('migrate', True):
            if verbosity:
                print "\nMigrated:\n - %s" % "\n - ".join(apps_migrated)
        else:
            if verbosity:
                print "\nNot synced (use migrations):\n - %s" % "\n - ".join(
                    apps_migrated)
                print "(use ./manage.py migrate to migrate these)"