def _execute(command, parts, **kwargs): project_options = get_project_options(**kwargs) build_environment = env.BuilderEnvironmentConfig() if build_environment.is_host: lifecycle.execute(command, project_options, parts) else: lifecycle.containerbuild(command, project_options, parts) return project_options
def _execute(command, parts, **kwargs): project_options = get_project_options(**kwargs) if env.is_containerbuild(): lifecycle.containerbuild(command, project_options, parts) else: lifecycle.execute(command, project_options, parts) return project_options
def _execute(command, parts, **kwargs): project_options = get_project_options(**kwargs) container_config = env.get_container_config() if container_config.use_container: lifecycle.containerbuild(command, project_options, container_config, parts) else: lifecycle.execute(command, project_options, parts) return project_options
def _execute(step: steps.Step, parts, **kwargs): project = get_project(**kwargs) project_config = project_loader.load_config(project) build_environment = env.BuilderEnvironmentConfig() if build_environment.is_host: lifecycle.execute(step, project_config, parts) else: # containerbuild takes a snapcraft command name, not a step lifecycle.containerbuild(step.name, project_config, parts) return project
def update(ctx, **kwargs): """Updates the parts listing from the cloud.""" # Update in the container so that it will use the parts at build time build_environment = env.BuilderEnvironmentConfig() if not build_environment.is_host: project_options = get_project_options(**kwargs) lifecycle.containerbuild('update', project_options) # Parts can be defined and searched from any folder on the host, so # regardless of using containers we always update these as well remote_parts.update()
def _execute(command, parts, **kwargs): project_options = get_project_options(**kwargs) if env.is_containerbuild(): lifecycle.containerbuild(command, project_options, parts) else: try: lifecycle.execute(command, project_options, parts) except Exception as e: echo.error(e) sys.exit(1) return project_options
def update(ctx, **kwargs): """Updates the parts listing from the cloud.""" # Update in the container so that it will use the parts at build time build_environment = env.BuilderEnvironmentConfig() if not build_environment.is_host: project = get_project(**kwargs) project_config = project_loader.load_config(project) lifecycle.containerbuild("update", project_config) # Parts can be defined and searched from any folder on the host, so # regardless of using containers we always update these as well remote_parts.update()
def snap(directory, output, **kwargs): """Create a snap. \b Examples: snapcraft snap snapcraft snap --output renamed-snap.snap If you want to snap a directory, you should use the snap-dir command instead. """ project_options = get_project_options(**kwargs) if env.is_containerbuild(): lifecycle.containerbuild('snap', project_options, output, directory) else: snap_name = lifecycle.snap(project_options, directory=directory, output=output) echo.info('Snapped {}'.format(snap_name))
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)
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)
def snap(directory, output, **kwargs): """Create a snap. \b Examples: snapcraft snap snapcraft snap --output renamed-snap.snap If you want to snap a directory, you should use the pack command instead. """ if directory: deprecations.handle_deprecation_notice('dn6') project_options = get_project_options(**kwargs) container_config = env.get_container_config() if container_config.use_container: lifecycle.containerbuild('snap', project_options, container_config, output, directory) else: snap_name = lifecycle.snap( project_options, directory=directory, output=output) echo.info('Snapped {}'.format(snap_name))
def run(args, project_options): # noqa 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']: _run_clean(args, project_options) elif args['cleanbuild']: lifecycle.cleanbuild(project_options, remote=args['--remote']), elif _is_store_command(args): _run_store_command(args) 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']) elif args['enable-ci']: enable_ci(args['<ci-system>'], args['--refresh']) elif args['update']: parts.update() elif args['define']: parts.define(args['<part-name>']) elif args['search']: parts.search(' '.join(args['<query>'])) elif os.environ.get('SNAPCRAFT_CONTAINER_BUILDS'): lifecycle.containerbuild(project_options, args['--output'], args['--remote']) else: # snap by default: if args['--remote']: raise RuntimeError( '--remote can only be used with SNAPCRAFT_CONTAINER_BUILDS') lifecycle.snap(project_options, args['<directory>'], args['--output']) return project_options
def _execute( # noqa: C901 step: steps.Step, parts: str, pack_project: bool = False, output: str = None, shell: bool = False, shell_after: bool = False, **kwargs) -> "Project": # fmt: on build_environment = env.BuilderEnvironmentConfig() project = get_project(is_managed_host=build_environment.is_managed_host, **kwargs) if project.info.base is not None and not ( build_environment.is_host or build_environment.is_managed_host): build_provider_class = build_providers.get_provider_for( build_environment.provider) echo.info("Launching a VM.") with build_provider_class(project=project, echoer=echo) as instance: instance.mount_project() try: if shell: # shell means we want to do everything right up to the previous # step and then go into a shell instead of the requested step. # the "snap" target is a special snowflake that has not made its # way to be a proper step. previous_step = None if pack_project: previous_step = steps.PRIME elif step > steps.PULL: previous_step = step.previous_step() # steps.PULL is the first step, so we would directly shell into it. if previous_step: instance.execute_step(previous_step) elif pack_project: instance.pack_project(output=output) else: instance.execute_step(step) except Exception: if project.debug: instance.shell() else: echo.warning( "Run the same command again with --debug to shell into the environment " "if you wish to introspect this failure.") raise else: if shell or shell_after: instance.shell() elif build_environment.is_managed_host or build_environment.is_host: project_config = project_loader.load_config(project) lifecycle.execute(step, project_config, parts) if pack_project: _pack(project.prime_dir, output=output) else: # containerbuild takes a snapcraft command name, not a step lifecycle.containerbuild(command=step.name, project=project, args=parts) if pack_project: _pack(project.prime_dir, output=output) return project
def run(args, project_options): # noqa lifecycle_command = _get_lifecycle_command(args) argless_command = _get_command_from_arg(args) if lifecycle_command: if _is_containerbuild(): lifecycle.containerbuild(lifecycle_command, project_options, args['<part>']) else: lifecycle.execute( lifecycle_command, project_options, args['<part>']) elif argless_command: argless_command() elif args['clean']: if _is_containerbuild(): step = args['--step'] or 'pull' lifecycle.containerbuild('clean', project_options, args=['--step', step] + args['<part>']) else: _run_clean(args, project_options) elif args['cleanbuild']: lifecycle.cleanbuild(project_options, remote=args['--remote']), elif _is_store_command(args): _run_store_command(args) 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']) elif args['enable-ci']: enable_ci(args['<ci-system>'], args['--refresh']) elif args['update']: if _is_containerbuild(): lifecycle.containerbuild('update', project_options) else: parts.update() elif args['define']: if _is_containerbuild(): lifecycle.containerbuild('update', project_options, args=args['<part-name>']) else: parts.define(args['<part-name>']) elif args['search']: if _is_containerbuild(): lifecycle.containerbuild('search', project_options, args=' '.join(args['<query>'])) else: parts.search(' '.join(args['<query>'])) else: # snap by default: if _is_containerbuild(): lifecycle.containerbuild('snap', project_options, args['--output'], args['<directory>']) elif os.getenv('SNAPCRAFT_COLLABORATE'): # this is only for testing snapcraft.collaborate( os.getenv('SNAPCRAFT_COLLABORATORS_SNAP_NAME'), os.getenv('SNAPCRAFT_COLLABORATORS_SIGN_KEY')) else: lifecycle.snap(project_options, args['<directory>'], args['--output']) return project_options