コード例 #1
0
ファイル: lifecycle.py プロジェクト: patrickchirdon/snapcraft
def clean(parts, use_lxd, destructive_mode, unprime, step):
    """Remove a part's assets.

    \b
    Examples:
        snapcraft clean
        snapcraft clean my-part
    """
    # This option is only valid in legacy.
    if step:
        raise click.BadOptionUsage("--step", "no such option: --step")

    build_environment = get_build_environment(
        use_lxd=use_lxd, destructive_mode=destructive_mode)
    project = get_project(is_managed_host=build_environment.is_managed_host)

    if unprime and not build_environment.is_managed_host:
        raise click.BadOptionUsage("--unprime", "no such option: --unprime")

    if build_environment.is_managed_host or build_environment.is_host:
        step = steps.PRIME if unprime else None
        lifecycle.clean(project, parts, step)
    else:
        build_provider_class = build_providers.get_provider_for(
            build_environment.provider)
        if parts:
            with build_provider_class(project=project,
                                      echoer=echo) as instance:
                instance.clean(part_names=parts)
        else:
            build_provider_class(project=project, echoer=echo).clean_project()
            # Clear the prime directory on the host
            lifecycle.clean(project, parts, steps.PRIME)
コード例 #2
0
ファイル: lifecycle.py プロジェクト: parrotmac/snapcraft
def clean(parts, use_lxd, unprime):
    """Remove a part's assets.

    \b
    Examples:
        snapcraft clean
        snapcraft clean my-part
    """
    build_environment = get_build_environment(use_lxd=use_lxd)
    project = get_project(is_managed_host=build_environment.is_managed_host)

    if unprime and not build_environment.is_managed_host:
        raise click.BadOptionUsage("--unprime is not a valid option.")

    if build_environment.is_managed_host or build_environment.is_host:
        step = steps.PRIME if unprime else None
        lifecycle.clean(project, parts, step)
    else:
        build_provider_class = build_providers.get_provider_for(
            build_environment.provider
        )
        if parts:
            with build_provider_class(project=project, echoer=echo) as instance:
                instance.clean(part_names=parts)
        else:
            build_provider_class(project=project, echoer=echo).clean_project()
            # Clear the prime directory on the host
            lifecycle.clean(project, parts, steps.PRIME)
コード例 #3
0
ファイル: lifecycle.py プロジェクト: touilleMan/snapcraft
def clean(parts, step_name, **kwargs):
    """Remove content - cleans downloads, builds or install artifacts.

    \b
    Examples:
        snapcraft clean
        snapcraft clean my-part --step build
    """
    try:
        project = get_project(**kwargs)
    except YamlValidationError:
        # We need to be able to clean invalid projects too.
        project = get_project(skip_snapcraft_yaml=True, **kwargs)
    build_environment = env.BuilderEnvironmentConfig()

    step = None
    if step_name:
        if step_name == "strip":
            echo.warning(
                "DEPRECATED: Use `prime` instead of `strip` as the step to clean"
            )
            step_name = "prime"
        step = steps.get_step_by_name(step_name)

    if build_environment.is_host:
        lifecycle.clean(project, parts, step)
    else:
        project_config = project_loader.load_config(project)
        lxd.Project(
            project_options=project,
            output=None,
            source=os.path.curdir,
            metadata=project_config.get_metadata(),
        ).clean(parts, step)
コード例 #4
0
ファイル: main.py プロジェクト: cjwatson/snapcraft
def _run_clean(args, project_options):
    step = args['--step']
    if step == 'strip':
        logger.warning('DEPRECATED: Use `prime` instead of `strip` '
                       'as the step to clean')
        step = 'prime'
    lifecycle.clean(project_options, args['<part>'], step)
コード例 #5
0
def _run_clean(args, project_options):
    step = args['--step']
    if step == 'strip':
        logger.warning('DEPRECATED: Use `prime` instead of `strip` '
                       'as the step to clean')
        step = 'prime'
    lifecycle.clean(project_options, args['<part>'], step)
コード例 #6
0
ファイル: main.py プロジェクト: didrocks/snapcraft
def run(args, project_options):
    lifecycle_command = _get_lifecycle_command(args)
    argless_command = _get_command_from_arg(args)
    if lifecycle_command:
        lifecycle.execute(
            lifecycle_command, project_options, args['<part>'])
    elif argless_command:
        argless_command()
    elif args['clean']:
        step = args['--step']
        if step == 'strip':
            logger.warning('DEPRECATED: Use `prime` instead of `strip` '
                           'as the step to clean')
            step = 'prime'
        lifecycle.clean(project_options, args['<part>'], step)
    elif args['upload']:
        snapcraft.upload(args['<snap-file>'])
    elif args['cleanbuild']:
        lifecycle.cleanbuild(project_options),
    # disable until the tour command is activated
    # elif args['tour']:
    #    _scaffold_examples(args['<directory>'] or _SNAPCRAFT_TOUR_DIR)
    elif args['help']:
        snapcraft.topic_help(args['<topic>'] or args['<plugin>'],
                             args['--devel'], args['topics'])
    else:  # snap by default:
        lifecycle.snap(project_options, args['<directory>'], args['--output'])

    return project_options
コード例 #7
0
def run(args, project_options):
    lifecycle_command = _get_lifecycle_command(args)
    argless_command = _get_command_from_arg(args)
    if lifecycle_command:
        lifecycle.execute(lifecycle_command, project_options, args['<part>'])
    elif argless_command:
        argless_command()
    elif args['clean']:
        step = args['--step']
        if step == 'strip':
            logger.warning('DEPRECATED: Use `prime` instead of `strip` '
                           'as the step to clean')
            step = 'prime'
        lifecycle.clean(project_options, args['<part>'], step)
    elif args['upload']:
        snapcraft.upload(args['<snap-file>'])
    elif args['cleanbuild']:
        lifecycle.cleanbuild(project_options),
    elif args['tour']:
        _scaffold_examples(args['<directory>'] or _SNAPCRAFT_TOUR_DIR)
    elif args['help']:
        snapcraft.topic_help(args['<topic>'] or args['<plugin>'],
                             args['--devel'], args['topics'])
    else:  # snap by default:
        lifecycle.snap(project_options, args['<directory>'], args['--output'])

    return project_options
コード例 #8
0
    def test_clean_removes_global_state(self):
        self.make_snapcraft_yaml("""parts:
  test-part:
    plugin: nil
""")
        lifecycle.execute('pull', self.project_options)
        lifecycle.clean(self.project_options, parts=None)
        self.assertThat(os.path.join('snap', '.snapcraft'), Not(DirExists()))
コード例 #9
0
ファイル: test_lifecycle.py プロジェクト: xnox/snapcraft
 def test_clean_removes_global_state(self):
     project_config = self.make_snapcraft_project(
         textwrap.dedent("""\
             parts:
               test-part:
                 plugin: nil
             """))
     lifecycle.execute(steps.PULL, project_config)
     lifecycle.clean(project_config.project, parts=None)
     self.assertThat(os.path.join("snap", ".snapcraft"), Not(DirExists()))
コード例 #10
0
ファイル: _project.py プロジェクト: mvo5/snapcraft
    def clean(self, parts: List[str], step: steps.Step):
        # clean with no parts deletes the container
        if not step:
            if not parts:
                self._ensure_remote()
                if self._get_container_status():
                    print("Deleting {}".format(self._container_name))
                    subprocess.check_call(["lxc", "delete", "-f", self._container_name])
            step = steps.PULL

        lifecycle.clean(self._project_options, parts, step)
コード例 #11
0
 def test_clean_removes_global_state(self):
     self.make_snapcraft_yaml(
         textwrap.dedent("""\
             parts:
               test-part:
                 plugin: nil
             """))
     lifecycle.execute('pull', self.project_options)
     lifecycle.clean(self.project_options, parts=None)
     self.assertThat(
         os.path.join('snap', '.snapcraft'),
         Not(DirExists()))
コード例 #12
0
ファイル: _project.py プロジェクト: HugoLamarche/snapcraft
    def clean(self, parts: List[str], step: steps.Step):
        # clean with no parts deletes the container
        if not step:
            if not parts:
                self._ensure_remote()
                if self._get_container_status():
                    print('Deleting {}'.format(self._container_name))
                    subprocess.check_call(
                        ['lxc', 'delete', '-f', self._container_name])
            step = steps.PULL

        lifecycle.clean(self._project_options, parts, step)
コード例 #13
0
ファイル: test_lifecycle.py プロジェクト: mvo5/snapcraft
 def test_clean_removes_global_state(self):
     project_config = self.make_snapcraft_project(
         textwrap.dedent(
             """\
             parts:
               test-part:
                 plugin: nil
             """
         )
     )
     lifecycle.execute(steps.PULL, project_config)
     lifecycle.clean(project_config.project, parts=None)
     self.assertThat(os.path.join("snap", ".snapcraft"), Not(DirExists()))
コード例 #14
0
    def clean(self, parts: List[str], step: steps.Step):
        # clean with no parts deletes the container
        if not step:
            if not parts:
                if os.path.exists(self.provider_project_dir):
                    shutil.rmtree(self.provider_project_dir)
                self._ensure_remote()
                if self._get_container_status():
                    print("Deleting {}".format(self._container_name))
                    subprocess.check_call(
                        ["lxc", "delete", "-f", self._container_name])
            step = steps.PULL

        lifecycle.clean(self._project, parts, step)
コード例 #15
0
ファイル: test_lifecycle.py プロジェクト: xnox/snapcraft
 def test_clean_leaves_prime_alone_for_tried(self, mock_for_root):
     project_config = self.make_snapcraft_project(
         textwrap.dedent("""\
             parts:
               test-part:
                 plugin: nil
             """))
     lifecycle.execute(steps.PRIME, project_config)
     lifecycle.clean(project_config.project, parts=None)
     self.assertThat(
         steps.PRIME.name,
         DirExists(),
         "Expected prime directory to remain after cleaning for tried snap",
     )
コード例 #16
0
 def clean(self, parts, step):
     # clean with no parts deletes the container
     if not step:
         if self._get_container_status():
             print('Deleting {}'.format(self._container_name))
             subprocess.check_call(
                 ['lxc', 'delete', '-f', self._container_name])
         step = 'pull'
     # clean normally, without involving the container
     if step == 'strip':
         echo.warning('DEPRECATED: Use `prime` instead of `strip` '
                      'as the step to clean')
         step = 'prime'
     lifecycle.clean(self._project_options, parts, step)
コード例 #17
0
ファイル: lifecycle.py プロジェクト: snshn/snapcraft
def clean(ctx, parts, unprime, step, **kwargs):
    """Remove a part's assets.

    \b
    Examples:
        snapcraft clean
        snapcraft clean my-part
    """
    # This option is only valid in legacy.
    if step:
        option = "--step" if "--step" in ctx.obj["argv"] else "-s"
        raise click.BadOptionUsage(option, "no such option: {}".format(option))

    build_provider = get_build_provider(**kwargs)
    build_provider_flags = get_build_provider_flags(build_provider, **kwargs)
    apply_host_provider_flags(build_provider_flags)

    is_managed_host = build_provider == "managed-host"

    # Temporary fix to ignore target_arch, silently for clean.
    if "target_arch" in kwargs and build_provider in ["multipass", "lxd"]:
        kwargs.pop("target_arch")

    try:
        project = get_project(is_managed_host=is_managed_host)
    except errors.ProjectNotFoundError:
        # Fresh environment, nothing to clean.
        return

    if unprime and not is_managed_host:
        raise click.BadOptionUsage("--unprime", "no such option: --unprime")

    if build_provider in ["host", "managed-host"]:
        step = steps.PRIME if unprime else None
        lifecycle.clean(project, parts, step)
    else:
        build_provider_class = build_providers.get_provider_for(build_provider)
        if parts:
            with build_provider_class(
                    project=project,
                    echoer=echo,
                    build_provider_flags=build_provider_flags) as instance:
                instance.clean(part_names=parts)
        else:
            build_provider_class(project=project, echoer=echo).clean_project()
            # Clear the prime directory on the host, unless on Windows.
            if sys.platform != "win32":
                lifecycle.clean(project, parts, steps.PRIME)
コード例 #18
0
ファイル: test_lifecycle.py プロジェクト: mvo5/snapcraft
 def test_clean_leaves_prime_alone_for_tried(self, mock_for_root):
     project_config = self.make_snapcraft_project(
         textwrap.dedent(
             """\
             parts:
               test-part:
                 plugin: nil
             """
         )
     )
     lifecycle.execute(steps.PRIME, project_config)
     lifecycle.clean(project_config.project, parts=None)
     self.assertThat(
         steps.PRIME.name,
         DirExists(),
         "Expected prime directory to remain after cleaning for tried snap",
     )
コード例 #19
0
def clean(parts, step_name):
    """Remove content - cleans downloads, builds or install artifacts.

    \b
    Examples:
        snapcraft clean
        snapcraft clean my-part --step build
    """
    build_environment = env.BuilderEnvironmentConfig()
    try:
        project = get_project(
            is_managed_host=build_environment.is_managed_host
        )
    except YamlValidationError:
        # We need to be able to clean invalid projects too.
        project = get_project(
            is_managed_host=build_environment.is_managed_host,
            skip_snapcraft_yaml=True
        )

    step = None
    if step_name:
        if step_name == "strip":
            echo.warning(
                "DEPRECATED: Use `prime` instead of `strip` as the step to clean"
            )
            step_name = "prime"
        step = steps.get_step_by_name(step_name)

    if build_environment.is_lxd:
        lxd.Project(project=project, output=None, source=os.path.curdir).clean(
            parts, step
        )
    elif build_environment.is_host:
        lifecycle.clean(project, parts, step)
    else:
        # TODO support for steps.
        if parts or step_name:
            raise errors.SnapcraftEnvironmentError(
                "Build providers are still not feature complete, specifying parts or a step name "
                "is not yet supported.")
        build_provider_class = build_providers.get_provider_for(
            build_environment.provider
        )
        build_provider_class(project=project, echoer=echo).clean_project()
コード例 #20
0
def run(args, project_options):
    lifecycle_command = _get_lifecycle_command(args)
    argless_command = _get_command_from_arg(args)
    if lifecycle_command:
        lifecycle.execute(lifecycle_command, project_options, args['<part>'])
    elif argless_command:
        argless_command()
    elif args['clean']:
        lifecycle.clean(project_options, args['<part>'], args['--step'])
    elif args['upload']:
        snapcraft.upload(args['<snap-file>'])
    elif args['cleanbuild']:
        lifecycle.cleanbuild(project_options),
    elif args['help']:
        snapcraft.topic_help(args['<topic>'] or args['<plugin>'],
                             args['--devel'], args['topics'])
    else:  # snap by default:
        lifecycle.snap(project_options, args['<directory>'], args['--output'])

    return project_options
コード例 #21
0
def clean(parts, step, **kwargs):
    """Remove content - cleans downloads, builds or install artifacts.

    \b
    Examples:
        snapcraft clean
        snapcraft clean my-part --step build
    """
    project_options = get_project_options(**kwargs)
    if env.is_containerbuild():
        step = step or 'pull'
        lifecycle.containerbuild('clean',
                                 project_options,
                                 args=['--step', step, *parts])
    else:
        if step == 'strip':
            echo.warning('DEPRECATED: Use `prime` instead of `strip` '
                         'as the step to clean')
            step = 'prime'
        lifecycle.clean(project_options, parts, step)
コード例 #22
0
ファイル: main.py プロジェクト: 0-T-0/snapcraft
def run(args, project_options):
    lifecycle_command = _get_lifecycle_command(args)
    argless_command = _get_command_from_arg(args)
    if lifecycle_command:
        lifecycle.execute(
            lifecycle_command, project_options, args['<part>'])
    elif argless_command:
        argless_command()
    elif args['clean']:
        lifecycle.clean(project_options, args['<part>'], args['--step'])
    elif args['upload']:
        snapcraft.upload(args['<snap-file>'])
    elif args['cleanbuild']:
        lifecycle.cleanbuild(project_options),
    elif args['help']:
        snapcraft.topic_help(args['<topic>'] or args['<plugin>'],
                             args['--devel'], args['topics'])
    else:  # snap by default:
        lifecycle.snap(project_options, args['<directory>'], args['--output'])

    return project_options
コード例 #23
0
ファイル: lifecycle.py プロジェクト: cholcombe973/snapcraft
def clean(parts, step, **kwargs):
    """Remove content - cleans downloads, builds or install artifacts.

    \b
    Examples:
        snapcraft clean
        snapcraft clean my-part --step build
    """
    project_options = get_project_options(**kwargs)
    container_config = env.get_container_config()
    if container_config.use_container:
        step = step or 'pull'
        lifecycle.containerbuild(
            'clean', project_options,
            container_config, args=['--step', step, *parts])
    else:
        if step == 'strip':
            echo.warning('DEPRECATED: Use `prime` instead of `strip` '
                         'as the step to clean')
            step = 'prime'
        lifecycle.clean(project_options, parts, step)
コード例 #24
0
ファイル: lifecycle.py プロジェクト: wting/snapcraft
def clean(ctx, parts, use_lxd, destructive_mode, unprime, step):
    """Remove a part's assets.

    \b
    Examples:
        snapcraft clean
        snapcraft clean my-part
    """
    # This option is only valid in legacy.
    if step:
        option = "--step" if "--step" in ctx.obj["argv"] else "-s"
        raise click.BadOptionUsage(option, "no such option: {}".format(option))

    build_environment = get_build_environment(
        use_lxd=use_lxd, destructive_mode=destructive_mode)

    try:
        project = get_project(
            is_managed_host=build_environment.is_managed_host)
    except errors.ProjectNotFoundError:
        # Fresh environment, nothing to clean.
        return

    if unprime and not build_environment.is_managed_host:
        raise click.BadOptionUsage("--unprime", "no such option: --unprime")

    if build_environment.is_managed_host or build_environment.is_host:
        step = steps.PRIME if unprime else None
        lifecycle.clean(project, parts, step)
    else:
        build_provider_class = build_providers.get_provider_for(
            build_environment.provider)
        if parts:
            with build_provider_class(project=project,
                                      echoer=echo) as instance:
                instance.clean(part_names=parts)
        else:
            build_provider_class(project=project, echoer=echo).clean_project()
            # Clear the prime directory on the host
            lifecycle.clean(project, parts, steps.PRIME)
コード例 #25
0
def clean(parts, step, **kwargs):
    """Remove content - cleans downloads, builds or install artifacts.

    \b
    Examples:
        snapcraft clean
        snapcraft clean my-part --step build
    """
    project_options = get_project_options(**kwargs)
    build_environment = env.BuilderEnvironmentConfig()
    if build_environment.is_host:
        step = step or 'pull'
        if step == 'strip':
            echo.warning('DEPRECATED: Use `prime` instead of `strip` '
                         'as the step to clean')
            step = 'prime'
        lifecycle.clean(project_options, parts, step)
    else:
        config = project_loader.load_config(project_options)
        lxd.Project(project_options=project_options,
                    output=None,
                    source=os.path.curdir,
                    metadata=config.get_metadata()).clean(parts, step)
コード例 #26
0
def clean(parts, step, **kwargs):
    """Remove content - cleans downloads, builds or install artifacts.

    \b
    Examples:
        snapcraft clean
        snapcraft clean my-part --step build
    """
    project_options = get_project_options(**kwargs)
    container_config = env.get_container_config()
    if container_config.use_container:
        config = snapcraft.internal.load_config(project_options)
        lxd.Project(project_options=project_options,
                    remote=container_config.remote,
                    output=None, source=os.path.curdir,
                    metadata=config.get_metadata()).clean(parts, step)
    else:
        step = step or 'pull'
        if step == 'strip':
            echo.warning('DEPRECATED: Use `prime` instead of `strip` '
                         'as the step to clean')
            step = 'prime'
        lifecycle.clean(project_options, parts, step)
コード例 #27
0
ファイル: lifecycle.py プロジェクト: jeffarrieta/snapcraft
def clean(parts):
    """Remove a part's assets.

    \b
    Examples:
        snapcraft clean
        snapcraft clean my-part
    """
    build_environment = env.BuilderEnvironmentConfig()
    project = get_project(is_managed_host=build_environment.is_managed_host)

    if build_environment.is_managed_host or build_environment.is_host:
        lifecycle.clean(project, parts)
    else:
        build_provider_class = build_providers.get_provider_for(
            build_environment.provider)
        build_provider = build_provider_class(project=project, echoer=echo)
        if parts:
            echo.info("Launching a VM.")
            with build_provider_class(project=project,
                                      echoer=echo) as instance:
                instance.clean(part_names=parts)
        else:
            build_provider.clean_project()