def handle_noargs(self, **options):
        verbosity = int(options.get("verbosity", 0))
        interactive = int(options.get("interactive", 0))
        no_data = int(options.get("nodata", 0))
        if "conf_setting" in connection.introspection.table_names():
            raise CommandError("Database already created, you probably "
                               "want the syncdb or migrate command")

        syncdb.Command().execute(**options)
        if not interactive and not no_data:
            install_optional_data(verbosity)
        if settings.USE_SOUTH:
            try:
                from south.management.commands import migrate
            except ImportError:
                return
            if interactive:
                confirm = input("\nSouth is installed for this project."
                                "\nWould you like to fake initial "
                                "migrations? (yes/no): ")
                while True:
                    if confirm == "yes":
                        break
                    elif confirm == "no":
                        return
                    confirm = input("Please enter either 'yes' or 'no': ")
            if verbosity >= 1:
                print()
                print("Faking initial migrations ...")
                print()
            migrate.Command().execute(fake=True)
示例#2
0
    def sync_apps(self, app_labels, app_name_to_app_map, options):
        if DJANGO_17:
            from django.db.migrations.executor import MigrationExecutor
            from django.core.management.commands import migrate

            apps_to_sync = []
            for app_label in app_labels:
                app_label = app_name_to_app_map[
                    app_label].label if app_label in app_name_to_app_map else app_label
                apps_to_sync.append(app_label)

            connection = connections[options.get('database', 'default')]

            cmd = migrate.Command()
            cmd.stdout = self.stdout
            cmd.stderr = self.stderr
            cmd.run_syncdb = True
            cmd.verbosity = int(options.get('verbosity'))
            cmd.interactive = options.get('interactive')
            cmd.show_traceback = options.get('traceback')
            cmd.load_initial_data = options.get('load_initial_data')
            cmd.test_database = options.get('test_database', False)
            cmd.sync_apps(connection, apps_to_sync)
        else:
            old_installed, settings.INSTALLED_APPS = settings.INSTALLED_APPS, app_labels
            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 app_labels
            ])

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

            settings.INSTALLED_APPS = old_installed
            cache.app_store = old_app_store
示例#3
0
 def call_command_syncdb():
     cmd = syncdb.Command()
     cmd.stdout = self.stdout
     cmd.stderr = self.stderr
     cmd.handle_noargs(noinput=False,
                       verbosity=verbosity,
                       database=DEFAULT_DB_ALIAS)
示例#4
0
 def handle_noargs(self, **options):
     verbosity = int(options.get("verbosity", 0))
     interactive = int(options.get("interactive", 0))
     no_data = int(options.get("nodata", 0))
     syncdb.Command().execute(**options)
     if not interactive and not no_data:
         install_optional_data(verbosity)
     if settings.USE_SOUTH:
         try:
             from south.management.commands import migrate
         except ImportError:
             return
         if interactive:
             confirm = raw_input("\nWould you like to fake initial "
                                 "migrations? (yes/no): ")
             while True:
                 if confirm == "yes":
                     break
                 elif confirm == "no":
                     return
                 confirm = raw_input("Please enter either 'yes' or 'no': ")
         if verbosity >= 1:
             print
             print "Faking initial migrations ..."
             print
         migrate.Command().execute(fake=True)
示例#5
0
    def handle(self, *args, **options):
        self.args = args
        self.options = options
        model = self.get_model()
        database = self.options.get('database')
        database = database if database else DEFAULT_DB_ALIAS
        only_sqlall = self.options.get('sqlall')

        # First, make sure all the partition models have been generated
        for partition_name in self.get_partition_names(model):
            model._partition_manager.get_partition(partition_name)

        if only_sqlall:
            # We've been asked just to dump the SQL
            sqlall_command = sqlall.Command()
            self._setup_command(sqlall_command)
            app = models.get_app(model._meta.app_label)
            print(sqlall_command.handle_app(
                app,
                database=database
            ))
        else:
            # Invoke syncdb directly. We don't use call_command, as South
            # provides its own implementation which we don't want to use.
            syncdb_command = syncdb.Command()
            self._setup_command(syncdb_command)
            syncdb_command.handle_noargs(
                database=database,
                interactive=False,
                load_initial_data=False,
                show_traceback=True,
                verbosity=0,
            )
示例#6
0
    def handle(self, *args, **options):
        from django.core.management.commands import syncdb
        from django.core.management import call_command
        from django.conf import settings

        interactive = options.get('interactive')
        verbosity = options.get('verbosity')
        use_core_syncdb = options.get('coresyncdb')
        database = options.get('database')

        if database != DEFAULT_DB_ALIAS:# and not use_core_syncdb:
            # see http://code.djangoproject.com/ticket/16039
            print "django does not handle different database sync, I give up"
            return


        if interactive:
            try:
                db = settings.DATABASES[database]
            except KeyError:
                raise Exception('Given database (%s) not found in settings' % database)

            confirm = raw_input('\n'.join((
                'You have requested a database reset.',
                'This will IRREVERSIBLY DESTROY',
                'ALL data in the database "%s".' % db['NAME'],
                'Are you sure you want to do this?',
                '',
                "Type 'yes' to continue, or 'no' to cancel: ")))
        else:
            confirm = 'yes'

        if confirm != 'yes':
            print "Reset cancelled."
            return

        if verbosity >= 1:
            print ''
            print 'Running database reset (drop&create database)'
        call_command('reset_db', verbosity=verbosity, interactive=False, database=database)

        if use_core_syncdb:
            #za tohle pujdu do pekla
            from wsgiadmin.bills.models import balance
            balance._meta.managed = True
            syncdb.Command().execute(**options)
            balance._meta.managed = False
        else:
            call_command('syncdb', verbosity=verbosity, interactive=interactive, migrate=True)


        if verbosity >= 1:
            print ''
            print 'Loading project initial data: '

        for fixt in FIXTURES_SITES:
            if verbosity >= 1:
                print "    %s" % fixt
            call_command('loaddata', fixt, verbosity=verbosity, database=database)
示例#7
0
文件: syncdb.py 项目: daasara/riba
    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)"
示例#8
0
 def _pre_setup(self):
     # Add the models to the db.
     self._original_installed_apps = settings.INSTALLED_APPS
     assert self.app is not None, "TestCase.app must be defined!"
     settings.INSTALLED_APPS = list(settings.INSTALLED_APPS)
     settings.INSTALLED_APPS.append(self.app)
     loading.cache.loaded = False
     # Use Django's 'syncdb' rather than South's.
     syncdb.Command().handle_noargs(
         verbosity=0, interactive=False, database=DEFAULT_DB_ALIAS)
     super(TestModelMixin, self)._pre_setup()
示例#9
0
    def handle(self, *args, **options):
        installed_version = models.KegbotSite.get_installed_version()
        app_version = get_version_object()
        force = options.get('force')

        if installed_version is None:
            print 'Kegbot is not installed; run setup-kegbot.py first.'
            sys.exit(1)

        if installed_version == app_version and not force:
            print 'Version {} already installed.'.format(installed_version)
            return

        if installed_version > app_version:
            print 'Installed version {} is newer than app version {}'.format(
                installed_version, app_version)
            sys.exit(1)

        if installed_version < MINIMUM_INSTALLED_VERSION:
            print ''
            print 'ERROR: This version of Kegbot can only upgrade systems running on version'
            print 'v{} or newer.  Please install Kegbot v{} and run `kegbot upgrade` again.'.format(
                MINIMUM_INSTALLED_VERSION, MINIMUM_INSTALLED_VERSION)
            print '(Existing version: {})'.format(installed_version)
            print ''
            print 'More help: https://github.com/Kegbot/kegbot-server/wiki/Upgrading-Old-Versions'
            print ''
            sys.exit(1)

        print 'Upgrading from {} to {}'.format(installed_version, app_version)
        self.do_version_upgrades(installed_version)

        run(syncdb.Command(), args=['--noinput', '-v', '0'])

        if not options.get('skip_stats'):
            run(regen_stats.Command())

        if not options.get('skip_static'):
            run(collectstatic.Command(), args=['--noinput'])

        site = models.KegbotSite.get()
        site.server_version = str(app_version)
        site.save()

        # Refresh any news (since we have a new version).
        try:
            checkin.checkin(timeout=5.0, quiet=True)
        except (checkin.CheckinError, Exception):
            pass

        print ''
        print 'Upgrade complete!'
示例#10
0
 def syncdb(self):
     loading.cache.loaded = False
     # Use this, rather than call_command, or 'south' will screw with us.
     command = syncdb.Command()
     defaults = {}
     for opt in command.option_list:
         if opt.default is NO_DEFAULT:
             defaults[opt.dest] = None
         else:
             defaults[opt.dest] = opt.default
     defaults['verbosity'] = 0
     defaults['interactive'] = False
     command.execute(*[], **defaults)
示例#11
0
    def handle_noargs(self, **options):
        # Work out what uses migrations and so doesn't need syncing
        apps_needing_sync = []
        apps_migrated = []
        for app in models.get_apps():
            app_name = get_app_name(app)
            migrations = migration.get_app(app)
            if migrations is None:
                apps_needing_sync.append(app_name)
            else:
                # This is a migrated app, leave it
                apps_migrated.append(app_name)
        verbosity = int(options.get('verbosity', 0))
        # Run syncdb on only the ones needed
        if verbosity > 0:
            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_name(k) in apps_needing_sync
        ])
        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 > 0:
                print "Migrating..."
            management.call_command('migrate', **options)
        # Be obvious about what we did
        if verbosity > 0:
            print "\nSynced:\n > %s" % "\n > ".join(apps_needing_sync)

        if options.get('migrate', True):
            if verbosity > 0:
                print "\nMigrated:\n - %s" % "\n - ".join(apps_migrated)
        else:
            if verbosity > 0:
                print "\nNot synced (use migrations):\n - %s" % "\n - ".join(
                    apps_migrated)
                print "(use ./manage.py migrate to migrate these)"
示例#12
0
 def syncdb(self):
     loading.cache.loaded = False
     # Use this, rather than call_command, or 'south' will screw with us.
     syncdb.Command().execute(verbosity=0)
示例#13
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)")
示例#14
0
def sync():
    syncdb.Command().execute(noinput=True, verbosity=1, database='default')
示例#15
0
文件: syncdb.py 项目: DaveLepp/wmr
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)"