Ejemplo n.º 1
0
def env_update(args):
    manifest_file = ev.manifest_file(args.env)
    backup_file = manifest_file + ".bkp"
    needs_update = not ev.is_latest_format(manifest_file)

    if not needs_update:
        tty.msg('No update needed for the environment "{0}"'.format(args.env))
        return

    proceed = True
    if not args.yes_to_all:
        msg = ('The environment "{0}" is going to be updated to the latest '
               'schema format.\nIf the environment is updated, versions of '
               'Spack that are older than this version may not be able to '
               'read it. Spack stores backups of the updated environment '
               'which can be retrieved with "spack env revert"')
        tty.msg(msg.format(args.env))
        proceed = tty.get_yes_or_no('Do you want to proceed?', default=False)

    if not proceed:
        tty.die('Operation aborted.')

    ev.update_yaml(manifest_file, backup_file=backup_file)
    msg = 'Environment "{0}" has been updated [backup={1}]'
    tty.msg(msg.format(args.env, backup_file))
Ejemplo n.º 2
0
def env_revert(args):
    manifest_file = ev.manifest_file(args.env)
    backup_file = manifest_file + ".bkp"

    # Check that both the spack.yaml and the backup exist, the inform user
    # on what is going to happen and ask for confirmation
    if not os.path.exists(manifest_file):
        msg = 'cannot fine the manifest file of the environment [file={0}]'
        tty.die(msg.format(manifest_file))
    if not os.path.exists(backup_file):
        msg = 'cannot find the old manifest file to be restored [file={0}]'
        tty.die(msg.format(backup_file))

    proceed = True
    if not args.yes_to_all:
        msg = ('Spack is going to overwrite the current manifest file'
               ' with a backup copy [manifest={0}, backup={1}]')
        tty.msg(msg.format(manifest_file, backup_file))
        proceed = tty.get_yes_or_no('Do you want to proceed?', default=False)

    if not proceed:
        tty.die('Operation aborted.')

    shutil.copy(backup_file, manifest_file)
    os.remove(backup_file)
    msg = 'Environment "{0}" reverted to old state'
    tty.msg(msg.format(manifest_file))
Ejemplo n.º 3
0
def config_edit(args):
    """Edit the configuration file for a specific scope and config section.

    With no arguments and an active environment, edit the spack.yaml for
    the active environment.
    """
    spack_env = os.environ.get(ev.spack_env_var)
    if spack_env and not args.scope:
        # Don't use the scope object for envs, as `config edit` can be called
        # for a malformed environment. Use SPACK_ENV to find spack.yaml.
        config_file = ev.manifest_file(spack_env)
    else:
        # If we aren't editing a spack.yaml file, get config path from scope.
        scope, section = _get_scope_and_section(args)
        if not scope and not section:
            tty.die('`spack config edit` requires a section argument '
                    'or an active environment.')
        config_file = spack.config.config.get_config_filename(scope, section)

    if args.print_file:
        print(config_file)
    else:
        editor(config_file)