Пример #1
0
def _get_channel_lines_for_channel(  # noqa: C901
    snap_channel_map: ChannelMap,
    channel_name: str,
    architecture: str,
    current_tick: str,
) -> Tuple[str, List[List[str]]]:
    channel_lines: List[List[str]] = list()

    channel_info = snap_channel_map.get_channel_info(channel_name)

    try:
        progressive_mapped_channel: Optional[
            MappedChannel] = snap_channel_map.get_mapped_channel(
                channel_name=channel_name,
                architecture=architecture,
                progressive=True)
    except ValueError:
        progressive_mapped_channel = None

    if progressive_mapped_channel is not None:
        progressive_revision = snap_channel_map.get_revision(
            progressive_mapped_channel.revision)

        if progressive_mapped_channel.progressive.percentage is None:
            raise RuntimeError("Unexpected null progressive percentage")
        else:
            percentage = progressive_mapped_channel.progressive.percentage

        if progressive_mapped_channel.progressive.current_percentage is None:
            current_percentage_fmt = _HINTS.UNKNOWN
            remaining_percentage_fmt = _HINTS.UNKNOWN
        else:
            current_percentage = (
                progressive_mapped_channel.progressive.current_percentage)
            current_percentage_fmt = f"{current_percentage:.0f}"
            remaining_percentage_fmt = f"{100 - current_percentage:.0f}"

        progressive_mapped_channel_line = _get_channel_line(
            mapped_channel=progressive_mapped_channel,
            revision=progressive_revision,
            channel_info=channel_info,
            hint=current_tick,
            progress_string=
            f"{current_percentage_fmt}{_HINTS.PROGRESSING_TO}{percentage:.0f}%",
        )
        # Setup progress for the actually released revision, this needs to be
        # calculated. But only show it if the channel is open.
        progress_string = (
            f"{remaining_percentage_fmt}{_HINTS.PROGRESSING_TO}{100 - percentage:.0f}%"
        )
    else:
        progress_string = _HINTS.NO_PROGRESS

    try:
        mapped_channel: Optional[
            MappedChannel] = snap_channel_map.get_mapped_channel(
                channel_name=channel_name,
                architecture=architecture,
                progressive=False)
    except ValueError:
        mapped_channel = None

    next_tick = current_tick
    if mapped_channel is not None:
        revision = snap_channel_map.get_revision(mapped_channel.revision)
        channel_lines.append(
            _get_channel_line(
                mapped_channel=mapped_channel,
                revision=revision,
                channel_info=channel_info,
                hint=current_tick,
                progress_string=progress_string,
            ))
        if channel_info.branch is None:
            next_tick = _HINTS.FOLLOWING
    # Show an empty entry if there is no specific channel information, but
    # only for <track>/<risks> (ignoring /<branch>).
    elif channel_info.branch is None:
        channel_lines.append(
            _get_channel_line(
                mapped_channel=None,
                revision=None,
                channel_info=channel_info,
                hint=current_tick,
                progress_string=_HINTS.NO_PROGRESS
                if current_tick == _HINTS.CLOSED else progress_string,
            ))

    if (os.getenv("SNAPCRAFT_EXPERIMENTAL_PROGRESSIVE_RELEASES")
            and progressive_mapped_channel is not None):
        channel_lines.append(progressive_mapped_channel_line)
        if channel_info.branch is None:
            next_tick = _HINTS.FOLLOWING

    return next_tick, channel_lines
Пример #2
0
def _get_channel_lines_for_channel(snap_channel_map: ChannelMap,
                                   channel_name: str,
                                   architecture: str) -> List[List[str]]:
    channel_lines: List[List[str]] = list()

    channel_info = snap_channel_map.get_channel_info(channel_name)

    hint = _get_channel_hint(
        channel_map=snap_channel_map.channel_map,
        fallback=channel_info.fallback,
        architecture=architecture,
    )

    try:
        progressive_mapped_channel: Optional[
            MappedChannel] = snap_channel_map.get_mapped_channel(
                channel_name=channel_name,
                architecture=architecture,
                progressive=True)
    except ValueError:
        progressive_mapped_channel = None

    if progressive_mapped_channel is not None:
        progressive_revision = snap_channel_map.get_revision(
            progressive_mapped_channel.revision)

        progressive_mapped_channel_line = _get_channel_line(
            mapped_channel=progressive_mapped_channel,
            revision=progressive_revision,
            channel_info=channel_info,
            hint=hint,
            progress_string=
            f"{_HINTS.PROGRESSING_TO} {progressive_mapped_channel.progressive.percentage:.0f}%",
        )
        if progressive_mapped_channel.progressive.percentage is None:
            percentage = 0.0
        else:
            percentage = progressive_mapped_channel.progressive.percentage
        # Setup progress for the actually released revision, this needs to be
        # calculated. But only show it if the channel is open.
        progress_string = "{} {:.0f}%".format(_HINTS.PROGRESSING_TO,
                                              100 - percentage)
    else:
        progress_string = _HINTS.NO_PROGRESS

    try:
        mapped_channel: Optional[
            MappedChannel] = snap_channel_map.get_mapped_channel(
                channel_name=channel_name,
                architecture=architecture,
                progressive=False)
    except ValueError:
        mapped_channel = None

    if mapped_channel is not None:
        revision = snap_channel_map.get_revision(mapped_channel.revision)
        channel_lines.append(
            _get_channel_line(
                mapped_channel=mapped_channel,
                revision=revision,
                channel_info=channel_info,
                hint=hint,
                progress_string=progress_string,
            ))
    # Don't show empty branches
    elif channel_info.branch is None:
        channel_lines.append(
            _get_channel_line(
                mapped_channel=None,
                revision=None,
                channel_info=channel_info,
                hint=hint,
                progress_string=_HINTS.NO_PROGRESS
                if hint == _HINTS.CLOSED else progress_string,
            ))

    if (os.getenv("SNAPCRAFT_EXPERIMENTAL_PROGRESSIVE_RELEASES")
            and progressive_mapped_channel is not None):
        channel_lines.append(progressive_mapped_channel_line)

    return channel_lines