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)
def verify_state(self, part_name, state_dir, expected_step_name): self.assertTrue(os.path.isdir(state_dir), 'Expected state directory for {}'.format(part_name)) # Expect every step up to and including the specified one to be run step = steps.get_step_by_name(expected_step_name) for step in step.previous_steps() + [step]: self.assertTrue( os.path.exists(os.path.join(state_dir, step.name)), 'Expected {!r} to be run for {}'.format(step.name, part_name))
def _migrate_state_file(self): # In previous versions of Snapcraft, the state directory was a file. # Rather than die if we're running on output from an old version, # migrate it for them. if os.path.isfile(self.plugin.statedir): with open(self.plugin.statedir, "r") as f: step = f.read() if step: os.remove(self.plugin.statedir) os.makedirs(self.plugin.statedir) self.mark_done(steps.get_step_by_name(step))
def _migrate_state_file(self): # In previous versions of Snapcraft, the state directory was a file. # Rather than die if we're running on output from an old version, # migrate it for them. if os.path.isfile(self.plugin.statedir): with open(self.plugin.statedir, "r") as f: step = f.read() if step: os.remove(self.plugin.statedir) os.makedirs(self.plugin.statedir) self.mark_done(steps.get_step_by_name(step))
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()