当前位置: 首页>>代码示例>>Python>>正文


Python Migrations._clear_cache方法代码示例

本文整理汇总了Python中south.migration.Migrations._clear_cache方法的典型用法代码示例。如果您正苦于以下问题:Python Migrations._clear_cache方法的具体用法?Python Migrations._clear_cache怎么用?Python Migrations._clear_cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在south.migration.Migrations的用法示例。


在下文中一共展示了Migrations._clear_cache方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from south.migration import Migrations [as 别名]
# 或者: from south.migration.Migrations import _clear_cache [as 别名]
 def handle(self, app=None, *args, **options):
     
     # Make sure we have an app
     if not app:
         print("Please specify an app to convert.")
         return
     
     # See if the app exists
     app = app.split(".")[-1]
     try:
         app_module = models.get_app(app)
     except ImproperlyConfigured:
         print("There is no enabled application matching '%s'." % app)
         return
     
     # Try to get its list of models
     model_list = models.get_models(app_module)
     if not model_list:
         print("This application has no models; this command is for applications that already have models syncdb'd.")
         print("Make some models, and then use ./manage.py schemamigration %s --initial instead." % app)
         return
     
     # Ask South if it thinks it's already got migrations
     try:
         Migrations(app)
     except NoMigrations:
         pass
     else:
         print("This application is already managed by South.")
         return
     
     # Finally! It seems we've got a candidate, so do the two-command trick
     verbosity = int(options.get('verbosity', 0))
     management.call_command("schemamigration", app, initial=True, verbosity=verbosity)
     
     # Now, we need to re-clean and sanitise appcache
     hacks.clear_app_cache()
     hacks.repopulate_app_cache()
     
     # And also clear our cached Migration classes
     Migrations._clear_cache()
     
     # Now, migrate
     management.call_command(
         "migrate",
         app,
         "0001",
         fake=True,
         verbosity=verbosity,
         ignore_ghosts=options.get("ignore_ghosts", False),
         delete_ghosts=options.get("delete_ghosts", False),
     )
     
     print() 
     print("App '%s' converted. Note that South assumed the application's models matched the database" % app)
     print("(i.e. you haven't changed it since last syncdb); if you have, you should delete the %s/migrations" % app)
     print("directory, revert models.py so it matches the database, and try again.")
开发者ID:takeiteasyguy,项目名称:django-project,代码行数:59,代码来源:convert_to_south.py

示例2: _south_migrate_all

# 需要导入模块: from south.migration import Migrations [as 别名]
# 或者: from south.migration.Migrations import _clear_cache [as 别名]
def _south_migrate_all():
    if not 'south' in settings.INSTALLED_APPS:
        sys.stderr.write(
            "warning: 'south' is not in INSTALLED_APPS, no migration done.\n")
        return 0
    #pylint: disable=import-error,too-many-nested-blocks
    from south.migration import Migrations
    from south.management.commands import migrate
    schema_cmd = SchemaMigration()
    initial_apps = []
    auto_apps = [] #pylint: disable=unused-variable
    for app in [app for app in settings.INSTALLED_APPS if app != 'south']:
        try:
            app_module = models.get_app(app) #pylint: disable=no-member
                                             # South only used with Django < 1.7
            clsmembers = inspect.getmembers(app_module, is_model_class)
            if clsmembers:
                migrations_dir = os.path.join(
                    os.path.dirname(app_module.__file__), 'migrations')
                if os.path.isdir(migrations_dir):
                    schema_cmd.handle(app, auto=True)#pylint:disable=no-member
                    found = False
                    for migration_file in os.listdir(migrations_dir):
                        if (re.match(r'^\d\d\d\d', migration_file)
                            and not migration_file.startswith('0001_initial')):
                            found = True
                            break
                    if found:
                        auto_apps += [app]
                    else:
                        initial_apps += [app]
                else:
                    schema_cmd.handle( #pylint:disable=no-member
                        app, initial=True)
                    initial_apps += [app]
            else:
                sys.stderr.write(
                    "warning: App %s does not seem to contain any Model\n" %
                    app)
        except OSError as err:
            sys.stderr.write("error: App %s, %s\n" % (app, err))
        except RuntimeError as err:
            sys.stderr.write("error: App %s, %s\n" % (app, err))
        except ImproperlyConfigured:
            sys.stderr.write(
                "warning: App %s does not seem to contain a models.py\n" % app)

    # Clear the cached Migrations instances now that we have more of them.
    Migrations._clear_cache() #pylint: disable=no-member,protected-access
    migrate_cmd = migrate.Command()
    for app in initial_apps:
        sys.stderr.write("initial migrate for %s\n" % app)
        migrate_cmd.handle(app, fake=True)
    sys.stderr.write("MIGRATE ALL!\n")
    migrate_cmd.handle(no_initial_data=True)
    return 0
开发者ID:djaodjin,项目名称:djaodjin-deployutils,代码行数:58,代码来源:pullapp.py

示例3: print

# 需要导入模块: from south.migration import Migrations [as 别名]
# 或者: from south.migration.Migrations import _clear_cache [as 别名]
                else:
                    schema_cmd.handle( #pylint:disable=no-member
                        app, initial=True)
                    initial_apps += [app]
            else:
                print("warning: App %s does not seem to contain any Model" %
                    app)
        except OSError, err:
            print "error: App %s, %s" % (app, err)
        except RuntimeError, err:
            print "warning: App %s, %s" % (app, err)
        except ImproperlyConfigured:
            print "warning: App %s does not seem to contain a models.py" % app

    # Clear the cached Migrations instances now that we have more of them.
    Migrations._clear_cache() #pylint: disable=no-member,protected-access
    migrate_cmd = migrate.Command()
    for app in initial_apps:
        print "initial migrate for %s" % app
        migrate_cmd.handle(app, fake=True)
    print "MIGRATE ALL!"
    migrate_cmd.handle(no_initial_data=True)
    return 0


def migrate_all():
    """
    Create schema migrations for all apps specified in INSTALLED_APPS,
    then run a migrate command.
    """
    if 'south' in settings.INSTALLED_APPS:
开发者ID:Tangugo,项目名称:djaodjin-deployutils,代码行数:33,代码来源:pullapp.py


注:本文中的south.migration.Migrations._clear_cache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。