本文整理汇总了Python中south.migration.Migrations.create_migrations_directory方法的典型用法代码示例。如果您正苦于以下问题:Python Migrations.create_migrations_directory方法的具体用法?Python Migrations.create_migrations_directory怎么用?Python Migrations.create_migrations_directory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类south.migration.Migrations
的用法示例。
在下文中一共展示了Migrations.create_migrations_directory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from south.migration import Migrations [as 别名]
# 或者: from south.migration.Migrations import create_migrations_directory [as 别名]
def handle(self, app=None, name="", freeze_list=None, stdout=False, verbosity=1, **options):
# Any supposed lists that are None become empty lists
freeze_list = freeze_list or []
# --stdout means name = -
if stdout:
name = "-"
# Only allow valid names
if re.search('[^_\w]', name) and name != "-":
self.error("Migration names should contain only alphanumeric characters and underscores.")
# if not name, there's an error
if not name:
self.error("You must provide a name for this migration\n" + self.usage_str)
if not app:
self.error("You must provide an app to create a migration for.\n" + self.usage_str)
# Get the Migrations for this app (creating the migrations dir if needed)
try:
migrations = Migrations(app)
except NoMigrations:
Migrations.create_migrations_directory(app, verbose=verbosity > 0)
migrations = Migrations(app)
# See what filename is next in line. We assume they use numbers.
new_filename = migrations.next_filename(name)
# Work out which apps to freeze
apps_to_freeze = self.calc_frozen_apps(migrations, freeze_list)
# So, what's in this file, then?
file_contents = MIGRATION_TEMPLATE % {
"frozen_models": freezer.freeze_apps_to_string(apps_to_freeze),
"complete_apps": apps_to_freeze and "complete_apps = [%s]" % (", ".join(map(repr, apps_to_freeze))) or ""
}
# - is a special name which means 'print to stdout'
if name == "-":
print file_contents
# Write the migration file if the name isn't -
else:
fp = open(os.path.join(migrations.migrations_dir(), new_filename), "w")
fp.write(file_contents)
fp.close()
print >>sys.stderr, "Created %s." % new_filename