bitbucket-cli 1.2.0

A powerful command-line interface for Bitbucket Cloud - manage repos, PRs, issues, and pipelines from your terminal with OAuth 2.0
Documentation
#!/usr/bin/env python3
"""Regenerate packaging/windows/icon.ico deterministically.

The MSI product icon is a 16x16 32-bit solid Bitbucket-blue (#0052CC) ICO.
This script is the icon's source of record: running it always produces the
exact bytes committed at packaging/windows/icon.ico, so the binary can be
audited and reproduced instead of trusted.

Usage: ./scripts/generate-icon.py [--check]
  --check  verify the committed file matches instead of writing it
"""

import struct
import sys
from pathlib import Path

SIZE = 16
BLUE_BGRA = bytes((0xCC, 0x52, 0x00, 0xFF))  # #0052CC, opaque

ICON_PATH = Path(__file__).resolve().parent.parent / "packaging" / "windows" / "icon.ico"


def build_ico() -> bytes:
    pixels = BLUE_BGRA * (SIZE * SIZE)
    and_mask = bytes(SIZE * 4)  # 16 rows x 4 bytes, all visible

    # BITMAPINFOHEADER: height is doubled to cover the XOR and AND masks.
    bmp_header = struct.pack(
        "<IiiHHIIiiII",
        40, SIZE, SIZE * 2, 1, 32, 0, len(pixels) + len(and_mask), 0, 0, 0, 0
    )
    image = bmp_header + pixels + and_mask

    icon_dir = struct.pack("<HHH", 0, 1, 1)
    dir_entry = struct.pack(
        "<BBBBHHII",
        SIZE, SIZE, 0, 0, 1, 32, len(image), len(icon_dir) + 16
    )
    return icon_dir + dir_entry + image


def main() -> int:
    data = build_ico()
    if "--check" in sys.argv[1:]:
        if ICON_PATH.read_bytes() == data:
            print(f"ok: {ICON_PATH} matches ({len(data)} bytes)")
            return 0
        print(f"MISMATCH: {ICON_PATH} does not match the generated bytes")
        return 1
    ICON_PATH.write_bytes(data)
    print(f"wrote: {ICON_PATH} ({len(data)} bytes)")
    return 0


if __name__ == "__main__":
    sys.exit(main())