import migrations


TO_VERSION = 7


try:
    if migrations.check_definitions_version(TO_VERSION - 1):
        if os.path.exists("DEFAULTS"):
            warnings.warn("DEFAULTS file already exists in these definitions.")
            valid = False
        else:
            shutil.copy("migrations/007-initial-defaults", "DEFAULTS")
            valid = True

        if valid:
            migrations.set_definitions_version(TO_VERSION)
            sys.stdout.write("Migration completed successfully.\n")
            sys.exit(0)
        else:
            sys.stderr.write("Migration failed due to one or more warnings.\n")
            sys.exit(1)
    else:
        if not os.path.exists("DEFAULTS"):
            warnings.warn("These definitions are marked as version 7 but there is no " "DEFAULTS file.")
        sys.stdout.write("Nothing to do.\n")
        sys.exit(0)
except RuntimeError as e:
    sys.stderr.write("Error: %s\n" % e.message)
    sys.exit(1)
示例#2
0
            if not os.path.exists(chunk_path):
                # There's no way we can really fix this, so
                # just warn and say the migration failed.
                warnings.warn(
                    "%s points to non-existant file %s" %
                    (contents['name'], chunk_ref['morph']))
                valid = False

    return valid


try:
    if migrations.check_definitions_version(TO_VERSION - 1):
        safe_to_migrate = migrations.process_definitions(
            kinds=['stratum'], validate_cb=check_missing_chunk_morphs)

        if not safe_to_migrate:
            sys.stderr.write(
                "Migration failed due to one or more warnings.\n")
            sys.exit(1)
        else:
            migrations.set_definitions_version(TO_VERSION)
            sys.stdout.write("Migration completed successfully.\n")
            sys.exit(0)
    else:
        sys.stdout.write("Nothing to do.\n")
        sys.exit(0)
except RuntimeError as e:
    sys.stderr.write("Error: %s\n" % e.message)
    sys.exit(1)