示例#1
0
    def test_pull_is_dirty_if_target_arch_changes(
        self,
        mock_install_build_snaps,
        mock_install_build_packages,
        mock_enable_cross_compilation,
    ):
        # Set the option to error on dirty/outdated steps
        with snapcraft.config.CLIConfig() as cli_config:
            cli_config.set_outdated_step_action(
                snapcraft.config.OutdatedStepAction.ERROR
            )

        mock_install_build_packages.return_value = []
        project_config = self.make_snapcraft_project(
            textwrap.dedent(
                """\
                parts:
                  part1:
                    plugin: nil
                """
            )
        )

        project = Project(
            snapcraft_yaml_file_path=self.snapcraft_yaml_file_path,
            target_deb_arch="amd64",
        )
        project_config = project_loader.load_config(project)
        # Pull it with amd64
        lifecycle.execute(steps.PULL, project_config)

        # Reset logging since we only care about the following
        self.fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(self.fake_logger)

        project = Project(
            snapcraft_yaml_file_path=self.snapcraft_yaml_file_path,
            target_deb_arch="armhf",
        )
        project_config = project_loader.load_config(project)
        # Pull it again with armhf. Should catch that the part needs to be
        # re-pulled due to the change in target architecture and raise an
        # error.
        raised = self.assertRaises(
            errors.StepOutdatedError, lifecycle.execute, steps.PULL, project_config
        )

        self.assertThat(
            self.fake_logger.output, Contains("Setting target machine to 'armhf'")
        )

        self.assertThat(raised.step, Equals(steps.PULL))
        self.assertThat(raised.part, Equals("part1"))
        self.assertThat(
            raised.report,
            Equals("The 'deb_arch' project option appears to have changed.\n"),
        )
示例#2
0
    def test_plugs_as_properties_should_fail(self):
        self.data += '        plugs: [plug1]'
        self.make_snapcraft_yaml(self.data)

        with self.assertRaises(SystemExit):
            project_loader.load_config()

        expected_message = self.expected_message_template.format('plugs')
        self.assertIn(expected_message, self.fake_logger.output)
示例#3
0
    def test_pull_is_dirty_if_target_arch_changes(
        self, mock_install_build_packages, mock_enable_cross_compilation
    ):
        mock_install_build_packages.return_value = []
        project_config = self.make_snapcraft_project(
            textwrap.dedent(
                """\
                parts:
                  part1:
                    plugin: nil
                """
            )
        )

        project = Project(
            snapcraft_yaml_file_path=self.snapcraft_yaml_file_path,
            target_deb_arch="amd64",
        )
        project_config = project_loader.load_config(project)
        # Pull it with amd64
        lifecycle.execute(steps.PULL, project_config)

        # Reset logging since we only care about the following
        self.fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(self.fake_logger)

        project = Project(
            snapcraft_yaml_file_path=self.snapcraft_yaml_file_path,
            target_deb_arch="armhf",
        )
        project_config = project_loader.load_config(project)
        # Pull it again with armhf. Should catch that the part needs to be
        # re-pulled due to the change in target architecture and raise an
        # error.
        raised = self.assertRaises(
            errors.StepOutdatedError, lifecycle.execute, steps.PULL, project_config
        )

        self.assertThat(
            self.fake_logger.output, Equals("Setting target machine to 'armhf'\n")
        )

        self.assertThat(raised.step, Equals(steps.PULL))
        self.assertThat(raised.part, Equals("part1"))
        self.assertThat(
            raised.report,
            Equals("The 'deb_arch' project option appears to have changed.\n"),
        )
示例#4
0
def clean(project_options, parts, step=None):
    # step defaults to None because that's how it comes from docopt when it's
    # not set.
    if not step:
        step = steps.PULL

    if not parts and step == steps.PULL:
        _cleanup_common_directories_for_step(step, project_options)
        return

    config = project_loader.load_config(project_options)

    if not parts and step <= steps.PRIME:
        # If we've been asked to clean stage or prime without being given
        # specific parts, just blow away those directories instead of
        # doing it per part (it would just be a waste of time).
        _cleanup_common_directories_for_step(
            step, project_options, parts=config.all_parts
        )

        # No need to continue if that's all that was required
        if step >= steps.STAGE:
            return

    if parts:
        config.parts.validate(parts)
    else:
        parts = [part.name for part in config.all_parts]

    staged_state = config.get_project_state(steps.STAGE)
    primed_state = config.get_project_state(steps.PRIME)

    _clean_parts(parts, step, config, staged_state, primed_state)

    _cleanup_common_directories(config, project_options)
示例#5
0
def refresh(debug, **kwargs):
    """Refresh an existing LXD container.

    \b
    Examples:
        snapcraft refresh

    This will take care of updating the apt package cache, upgrading packages
    as needed as well as refreshing snaps.
    """

    build_environment = env.BuilderEnvironmentConfig()
    if build_environment.is_host:
        raise errors.SnapcraftEnvironmentError(
            "The 'refresh' command only applies to LXD containers but "
            "SNAPCRAFT_BUILD_ENVIRONMENT is not set or set to host.\n"
            "Maybe you meant to update the parts cache instead? "
            "You can do that with the following command:\n\n"
            "snapcraft update")

    project = get_project(**kwargs, debug=debug)
    config = project_loader.load_config(project)
    lxd.Project(
        project_options=project,
        output=None,
        source=os.path.curdir,
        metadata=config.get_metadata(),
    ).refresh()
示例#6
0
 def make_snapcraft_project(self, snapcraft_yaml, project_kwargs=None):
     snapcraft_yaml_file_path = self.make_snapcraft_yaml(snapcraft_yaml)
     if project_kwargs is None:
         project_kwargs = dict()
     project = _Project(snapcraft_yaml_file_path=snapcraft_yaml_file_path,
                        **project_kwargs)
     return project_loader.load_config(project)
示例#7
0
文件: _clean.py 项目: mvo5/snapcraft
def clean(project_options, parts, step=None):
    # step defaults to None because that's how it comes from docopt when it's
    # not set.
    if not step:
        step = steps.PULL

    if not parts and step == steps.PULL:
        _cleanup_common_directories_for_step(step, project_options)
        return

    config = project_loader.load_config(project_options)

    if not parts and step <= steps.PRIME:
        # If we've been asked to clean stage or prime without being given
        # specific parts, just blow away those directories instead of
        # doing it per part (it would just be a waste of time).
        _cleanup_common_directories_for_step(
            step, project_options, parts=config.all_parts
        )

        # No need to continue if that's all that was required
        if step >= steps.STAGE:
            return

    if parts:
        config.parts.validate(parts)
    else:
        parts = [part.name for part in config.all_parts]

    staged_state = config.get_project_state(steps.STAGE)
    primed_state = config.get_project_state(steps.PRIME)

    _clean_parts(parts, step, config, staged_state, primed_state)

    _cleanup_common_directories(config, project_options)
示例#8
0
    def make_snapcraft_project(self, common_id):
        yaml = textwrap.dedent(
            """\
           name: test
           base: core18
           version: "1.0"
           summary: test
           description: test
           confinement: strict
           grade: stable
           adopt-info: part
           apps:
             test-app:
               command: echo
               common-id: {common_id}
           parts:
             part:
               plugin: nil
               parse-info: ["1.metainfo.xml", "2.metainfo.xml"]
           """
        )

        yaml_path = self.make_snapcraft_yaml(yaml.format(common_id=common_id))
        project = Project(snapcraft_yaml_file_path=yaml_path)
        return project_loader.load_config(project)
示例#9
0
    def generate_meta_yaml(
        self, *, build=False, actual_prime_dir=None, snapcraft_yaml_file_path=None
    ):
        if snapcraft_yaml_file_path is None:
            snapcraft_yaml_file_path = self.snapcraft_yaml_file_path
        os.makedirs("snap", exist_ok=True)
        with open(snapcraft_yaml_file_path, "w") as f:
            f.write(yaml_utils.dump(self.config_data))

        self.project = Project(snapcraft_yaml_file_path=snapcraft_yaml_file_path)
        if actual_prime_dir is not None:
            self.project._prime_dir = actual_prime_dir

        self.meta_dir = os.path.join(self.project.prime_dir, "meta")
        self.hooks_dir = os.path.join(self.meta_dir, "hooks")
        self.snap_yaml = os.path.join(self.meta_dir, "snap.yaml")

        self.config = project_loader.load_config(project=self.project)
        if build:
            for part in self.config.parts.all_parts:
                part.pull()
                part.build()
                part.stage()
                part.prime()

        _snap_packaging.create_snap_packaging(self.config)

        self.assertTrue(os.path.exists(self.snap_yaml), "snap.yaml was not created")

        with open(self.snap_yaml) as f:
            return yaml_utils.load(f)
示例#10
0
def refresh(debug, **kwargs):
    """Refresh an existing LXD container.

    \b
    Examples:
        snapcraft refresh

    This will take care of updating the apt package cache, upgrading packages
    as needed as well as refreshing snaps.
    """

    container_config = env.get_container_config()
    if not container_config.use_container:
        raise errors.SnapcraftEnvironmentError(
            "The 'refresh' command only applies to LXD containers but "
            "SNAPCRAFT_CONTAINER_BUILDS is not set or 0.\n"
            "Maybe you meant to update the parts cache instead? "
            "You can do that with the following command:\n\n"
            "snapcraft update")

    project_options = get_project_options(**kwargs, debug=debug)
    config = project_loader.load_config(project_options)
    lxd.Project(project_options=project_options,
                remote=container_config.remote,
                output=None,
                source=os.path.curdir,
                metadata=config.get_metadata()).refresh()
示例#11
0
def refresh(debug, **kwargs):
    """Refresh an existing LXD container.

    \b
    Examples:
        snapcraft refresh

    This will take care of updating the apt package cache, upgrading packages
    as needed as well as refreshing snaps.
    """

    build_environment = env.BuilderEnvironmentConfig()
    if build_environment.is_host:
        raise errors.SnapcraftEnvironmentError(
            "The 'refresh' command only applies to LXD containers but "
            "SNAPCRAFT_BUILD_ENVIRONMENT is not set or set to host.\n"
            "Maybe you meant to update the parts cache instead? "
            "You can do that with the following command:\n\n"
            "snapcraft update"
        )

    project = get_project(**kwargs, debug=debug)
    config = project_loader.load_config(project)
    lxd.Project(
        project_options=project,
        output=None,
        source=os.path.curdir,
        metadata=config.get_metadata(),
    ).refresh()
示例#12
0
def clean(project_options, parts, step=None):
    # step defaults to None because that's how it comes from docopt when it's
    # not set.
    if not step:
        step = 'pull'

    if not parts and step == 'pull':
        _cleanup_common_directories_for_step(step, project_options)
        return

    config = project_loader.load_config()

    if not parts and (step == 'stage' or step == 'prime'):
        # If we've been asked to clean stage or prime without being given
        # specific parts, just blow away those directories instead of
        # doing it per part.
        _cleanup_common_directories_for_step(step,
                                             project_options,
                                             parts=config.all_parts)
        return

    if parts:
        config.parts.validate(parts)
    else:
        parts = [part.name for part in config.all_parts]

    staged_state = config.get_project_state('stage')
    primed_state = config.get_project_state('prime')

    _clean_parts(parts, step, config, staged_state, primed_state)

    _cleanup_common_directories(config, project_options)
示例#13
0
def cleanbuild(remote, debug, **kwargs):
    """Create a snap using a clean environment managed by a build provider.

    \b
    Examples:
        snapcraft cleanbuild

    The cleanbuild command requires a properly setup lxd environment that
    can connect to external networks. Refer to the "Ubuntu Desktop and
    Ubuntu Server" section on
    https://linuxcontainers.org/lxd/getting-started-cli
    to get started.

    If using a remote, a prior setup is required which is described on:
    https://linuxcontainers.org/lxd/getting-started-cli/#multiple-hosts
    """
    project = get_project(**kwargs, debug=debug)
    project_config = project_loader.load_config(project)
    # cleanbuild is a special snow flake, while all the other commands
    # would work with the host as the build_provider it makes little
    # sense in this scenario.
    build_environment = env.BuilderEnvironmentConfig(
        default="lxd", additional_providers=["multipass"]
    )

    lifecycle.cleanbuild(
        project=project,
        project_config=project_config,
        echoer=echo,
        remote=remote,
        build_environment=build_environment,
    )
示例#14
0
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)
示例#15
0
def get_project_config(snapcraft_yaml_content):
    snapcraft_yaml_path = pathlib.Path("Snapcraft.yaml")
    with snapcraft_yaml_path.open("w") as snapcraft_yaml_file:
        print(snapcraft_yaml_content, file=snapcraft_yaml_file)

    project = Project(snapcraft_yaml_file_path=snapcraft_yaml_path.as_posix())
    return project_loader.load_config(project)
示例#16
0
 def make_snapcraft_project(self, snapcraft_yaml, project_kwargs=None):
     snapcraft_yaml_file_path = self.make_snapcraft_yaml(snapcraft_yaml)
     if project_kwargs is None:
         project_kwargs = dict()
     project = _Project(
         snapcraft_yaml_file_path=snapcraft_yaml_file_path, **project_kwargs
     )
     return project_loader.load_config(project)
示例#17
0
def _execute(  # noqa: C901
        step: steps.Step,
        parts: str,
        pack_project: bool = False,
        output: str = None,
        shell: bool = False,
        shell_after: bool = False,
        destructive_mode: bool = False,
        **kwargs) -> "Project":
    # fmt: on
    provider = "host" if destructive_mode else None
    build_environment = env.BuilderEnvironmentConfig(force_provider=provider)
    project = get_project(is_managed_host=build_environment.is_managed_host,
                          **kwargs)

    conduct_project_sanity_check(project)

    if 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:
        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()
    return project
示例#18
0
    def make_snapcraft_project(self, *, confinement: str):
        snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path)
        snapcraft_yaml.data["confinement"] = confinement
        snapcraft_yaml.update_part("test-part", dict(plugin="nil"))
        self.useFixture(snapcraft_yaml)

        project = Project(
            snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path)
        return project_loader.load_config(project)
示例#19
0
    def test_part_order_consistency(self):
        """Test that parts are always processed in the same order."""

        self.make_snapcraft_yaml(self.contents)
        config = project_loader.load_config()
        self.assertThat(config.all_parts, HasLength(len(self.expected_order)))

        for part, expected_name in zip(config.all_parts, self.expected_order):
            self.expectThat(part.name, Equals(expected_name))
示例#20
0
    def make_snapcraft_project(self, parts):
        snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path)
        snapcraft_yaml.update_part("part1", dict(plugin="nil"))
        for part_name, part in parts:
            snapcraft_yaml.update_part(part_name, part)
        self.useFixture(snapcraft_yaml)

        project = Project(
            snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path)
        return project_loader.load_config(project)
示例#21
0
    def make_snapcraft_project(self, apps):
        snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path)
        snapcraft_yaml.update_part("part1", dict(plugin="nil"))
        for app_name, app in apps:
            snapcraft_yaml.update_app(app_name, app)
        self.useFixture(snapcraft_yaml)

        p = project.Project(
            snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path)
        return load_config(p)
示例#22
0
def get_project_config(snapcraft_yaml_content, target_deb_arch=None):
    snapcraft_yaml_path = pathlib.Path("Snapcraft.yaml")
    with snapcraft_yaml_path.open("w") as snapcraft_yaml_file:
        print(snapcraft_yaml_content, file=snapcraft_yaml_file)

    snapcraft_project = project.Project(
        snapcraft_yaml_file_path=snapcraft_yaml_path.as_posix(),
        target_deb_arch=target_deb_arch,
    )
    return load_config(snapcraft_project)
示例#23
0
    def make_snapcraft_project(self, *, confinement: str):
        snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path)
        snapcraft_yaml.data["confinement"] = confinement
        snapcraft_yaml.update_part("test-part", dict(plugin="nil"))
        self.useFixture(snapcraft_yaml)

        project = Project(
            snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path
        )
        return project_loader.load_config(project)
示例#24
0
    def test_load_with_dummy_repo(self, os_release_mock):
        self.make_snapcraft_yaml(dedent("""\
            name: test
            version: "1"
            summary: test
            description: test
            confinement: strict

            parts:
              part1:
                source: https://github.com/snapcore/snapcraft.git
                plugin: python
                stage-packages: [fswebcam]
                snap: [foo]
        """))

        # Ensure the dummy repo returns an empty set for required
        # build tools.
        project_loader.load_config()
示例#25
0
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
示例#26
0
    def make_snapcraft_project(self, parts):
        snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path)
        snapcraft_yaml.update_part("part1", dict(plugin="nil"))
        for part_name, part in parts:
            snapcraft_yaml.update_part(part_name, part)
        self.useFixture(snapcraft_yaml)

        project = Project(
            snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path
        )
        return project_loader.load_config(project)
示例#27
0
    def test_load_with_dummy_repo(self, os_release_mock):
        self.make_snapcraft_yaml(
            dedent("""\
            name: test
            version: "1"
            summary: test
            description: test
            confinement: strict

            parts:
              part1:
                source: https://github.com/snapcore/snapcraft.git
                plugin: python
                stage-packages: [fswebcam]
                snap: [foo]
        """))

        # Ensure the dummy repo returns an empty set for required
        # build tools.
        project_loader.load_config()
示例#28
0
    def test_slash_warning(self, mock_loadPlugin):
        fake_logger = fixtures.FakeLogger(level=logging.WARN)
        self.useFixture(fake_logger)

        self.make_snapcraft_yaml("""name: test
version: "1"
summary: test
description: test
confinement: strict

parts:
  part/1:
    plugin: go
    stage-packages: [fswebcam]
""")
        project_loader.load_config()

        self.assertThat(fake_logger.output, Contains(
            'DEPRECATED: Found a "/" in the name of the {!r} part'.format(
                'part/1')))
示例#29
0
    def _get_snap_packaging(self, **yaml_args):
        if "parts" not in yaml_args:
            yaml_args["parts"] = dict(part1=dict(plugin="nil"))

        snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path, **yaml_args)
        self.useFixture(snapcraft_yaml)

        project = Project(
            snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path)
        config = load_config(project)

        return _SnapPackaging(project_config=config, extracted_metadata=None)
示例#30
0
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()
示例#31
0
    def test_snap_deprecation(self, mock_loadPlugin):
        """Test that using the 'snap' keyword results in a warning."""

        fake_logger = fixtures.FakeLogger(level=logging.WARN)
        self.useFixture(fake_logger)

        self.make_snapcraft_yaml("""name: test
version: "1"
summary: test
description: test
confinement: strict

parts:
  part1:
    plugin: go
    stage-packages: [fswebcam]
    snap: [foo]
""")
        project_loader.load_config()

        self.assertThat(fake_logger.output,
                        Contains(deprecations._deprecation_message('dn1')))
示例#32
0
def cleanbuild(*, project, echoer, build_environment, remote='') -> None:
    config = project_loader.load_config(project)
    tar_filename = _create_tar_file(project.info.name)

    if build_environment.is_lxd:
        _deprecated_cleanbuild(project, remote, config, tar_filename)
        return

    build_provider_class = build_providers.get_provider_for('multipass')
    with build_provider_class(project=project, echoer=echoer) as instance:
        instance.provision_project(tar_filename)
        instance.build_project()
        instance.retrieve_snap()
示例#33
0
def refresh(project):
    series = storeapi.constants.DEFAULT_SERIES
    project_config = project_loader.load_config(project)
    snap_name = project_config.data["name"]
    logger.info('Refreshing credentials to push and release "{}" snaps '
                "to edge channel in series {}".format(snap_name, series))

    packages = [{"name": snap_name, "series": series}]
    channels = ["edge"]
    _acquire_and_encrypt_credentials(packages, channels)

    logger.info("Done. Please commit the changes to `{}` file.".format(
        ENCRYPTED_CONFIG_FILENAME))
示例#34
0
    def test_create_gadget_meta_with_missing_gadget_yaml_raises_error(self):
        self.config_data['type'] = 'gadget'

        os.makedirs('snap', exist_ok=True)
        with open(os.path.join('snap', 'snapcraft.yaml'), 'w') as f:
            f.write(yaml.dump(self.config_data))

        config = project_loader.load_config()

        self.assertRaises(errors.MissingGadgetError,
                          _snap_packaging.create_snap_packaging,
                          self.config_data, config.parts, self.project_options,
                          'dummy')
示例#35
0
    def test_snap_deprecation(self):
        """Test that using the 'snap' keyword results in a warning."""

        fake_logger = fixtures.FakeLogger(level=logging.WARN)
        self.useFixture(fake_logger)

        self.make_snapcraft_yaml("""name: test
version: "1"
summary: test
description: test
confinement: strict

parts:
  part1:
    plugin: go
    stage-packages: [fswebcam]
    snap: [foo]
""")
        project_loader.load_config()

        self.assertThat(fake_logger.output,
                        Contains(deprecations._deprecation_message('dn1')))
示例#36
0
    def test_slash_warning(self):
        fake_logger = fixtures.FakeLogger(level=logging.WARN)
        self.useFixture(fake_logger)

        self.make_snapcraft_yaml("""name: test
version: "1"
summary: test
description: test
confinement: strict

parts:
  part/1:
    plugin: go
    stage-packages: [fswebcam]
""")
        project_loader.load_config()

        self.assertThat(
            fake_logger.output,
            Contains(
                'DEPRECATED: Found a "/" in the name of the {!r} part'.format(
                    'part/1')))
示例#37
0
def refresh():
    series = storeapi.constants.DEFAULT_SERIES
    project_config = project_loader.load_config()
    snap_name = project_config.data['name']
    logger.info('Refreshing credentials to push and release "{}" snaps '
                'to edge channel in series {}'.format(snap_name, series))

    packages = [{'name': snap_name, 'series': series}]
    channels = ['edge']
    _acquire_and_encrypt_credentials(packages, channels)

    logger.info('Done. Please commit the changes to `{}` file.'.format(
        ENCRYPTED_CONFIG_FILENAME))
示例#38
0
    def test_get_parts_none(self):
        self.make_snapcraft_yaml("""name: test
version: "1"
summary: test
description: test
confinement: strict

parts:
  part1:
    plugin: go
    stage-packages: [fswebcam]
""")
        config = project_loader.load_config(None)
        self.assertThat(config.parts.get_part('not-a-part'), Equals(None))
示例#39
0
    def test_get_parts_none(self, mock_loadPlugin):
        self.make_snapcraft_yaml("""name: test
version: "1"
summary: test
description: test
confinement: strict

parts:
  part1:
    plugin: go
    stage-packages: [fswebcam]
""")
        config = project_loader.load_config(None)
        self.assertEqual(None, config.parts.get_part('not-a-part'))
示例#40
0
def cleanbuild(project_options, remote=''):
    if remote and not lxd._remote_is_valid(remote):
        raise errors.InvalidContainerRemoteError(remote)

    config = project_loader.load_config(project_options)
    tar_filename = '{}_{}_source.tar.bz2'.format(config.data['name'],
                                                 config.data['version'])

    with tarfile.open(tar_filename, 'w:bz2') as t:
        t.add(os.path.curdir, filter=_create_tar_filter(tar_filename))
    lxd.Cleanbuilder(source=tar_filename,
                     project_options=project_options,
                     metadata=config.get_metadata(),
                     remote=remote).execute()
示例#41
0
    def test_non_prime_and_no_version(self):
        snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path, version=None)
        snapcraft_yaml.data["adopt-info"] = "test-part"
        snapcraft_yaml.update_part(
            "test-part",
            {"plugin": "nil", "override-build": "snapcraftctl set-version 1.0"},
        )
        self.useFixture(snapcraft_yaml)

        project = Project(
            snapcraft_yaml_file_path=snapcraft_yaml.snapcraft_yaml_file_path
        )
        project_config = project_loader.load_config(project)

        # This should not fail
        lifecycle.execute(steps.PULL, project_config)
示例#42
0
文件: travis.py 项目: mvo5/snapcraft
def enable(project):
    series = storeapi.constants.DEFAULT_SERIES
    project_config = project_loader.load_config(project)
    snap_name = project_config.data["name"]
    logger.info(
        "Enabling Travis testbeds to push and release {!r} snaps "
        "to edge channel in series {!r}".format(snap_name, series)
    )

    packages = [{"name": snap_name, "series": series}]
    channels = ["edge"]
    _acquire_and_encrypt_credentials(packages, channels)

    logger.info(
        'Configuring "deploy" phase to build and release the snap in the ' "Store."
    )
    with open(TRAVIS_CONFIG_FILENAME, "r+") as fd:
        travis_conf = yaml.safe_load(fd)
        # Enable 'sudo' capability and 'docker' service.
        travis_conf["sudo"] = "required"
        services = travis_conf.setdefault("services", [])
        if "docker" not in services:
            services.append("docker")
        # Add a 'deploy' section with 'script' provider for building and
        # release the snap within a xenial docker container.
        travis_conf["deploy"] = {
            "skip_cleanup": True,
            "provider": "script",
            "script": (
                "docker run -v $(pwd):$(pwd) -t snapcore/snapcraft sh -c "
                '"apt update -qq && cd $(pwd) && '
                'snapcraft && snapcraft push *.snap --release edge"'
            ),
            "on": {"branch": "master"},
        }
        fd.seek(0)
        yaml.dump(travis_conf, fd, default_flow_style=False)

    logger.info(
        "Done. Now you just have to review and commit changes in your "
        "Travis project (`{}`).\n"
        "Also make sure you add the new `{}` file.".format(
            TRAVIS_CONFIG_FILENAME, ENCRYPTED_CONFIG_FILENAME
        )
    )
示例#43
0
文件: travis.py 项目: mvo5/snapcraft
def refresh(project):
    series = storeapi.constants.DEFAULT_SERIES
    project_config = project_loader.load_config(project)
    snap_name = project_config.data["name"]
    logger.info(
        'Refreshing credentials to push and release "{}" snaps '
        "to edge channel in series {}".format(snap_name, series)
    )

    packages = [{"name": snap_name, "series": series}]
    channels = ["edge"]
    _acquire_and_encrypt_credentials(packages, channels)

    logger.info(
        "Done. Please commit the changes to `{}` file.".format(
            ENCRYPTED_CONFIG_FILENAME
        )
    )
示例#44
0
    def make_snapcraft_project(self, parts, snap_type=""):
        yaml = textwrap.dedent(
            """\
            name: test
            version: 0
            summary: test
            description: test
            confinement: strict
            grade: stable
            {type}

            {parts}
            """
        )

        self.snapcraft_yaml_file_path = self.make_snapcraft_yaml(
            yaml.format(parts=parts, type=snap_type)
        )
        project = snapcraft.project.Project(
            snapcraft_yaml_file_path=self.snapcraft_yaml_file_path
        )
        return project_loader.load_config(project)