def convert_environment(datadir, version, always_yes):
<EOL>require_images()<EOL>inp = None<EOL>old_version = _get_current_format(datadir)<EOL>migration_func = migrations[(old_version, version)]<EOL>if version > CURRENT_FORMAT_VERSION:<EOL><INDENT>raise DatacatsError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if version < <NUM_LIT:1>:<EOL><INDENT>raise DatacatsError('<STR_LIT>')<EOL><DEDENT>if not always_yes:<EOL><INDENT>while inp != '<STR_LIT:y>' and inp != '<STR_LIT:n>':<EOL><INDENT>inp = input(migration_func.__doc__.format(version))<EOL><DEDENT>if inp == '<STR_LIT:n>':<EOL><INDENT>sys.exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>lockfile = LockFile(path_join(datadir, '<STR_LIT>'))<EOL>lockfile.acquire()<EOL>try:<EOL><INDENT>migration_func(datadir)<EOL><DEDENT>finally:<EOL><INDENT>lockfile.release()<EOL><DEDENT>
Converts an environment TO the version specified by `version`.
:param datadir: The datadir to convert.
:param version: The version to convert TO.
:param always_yes: True if the user shouldn't be prompted about the migration.