"""Offline VS Code Linux repository & package command verifier for Ch05 (linux-install)."""
import configparser
import json
VERSION = "CPython 3.12.14 offline Linux APT/DNF/deb/rpm config verifier"
def check(name, summary, expected, actual):
return {
"name": name,
"summary": summary,
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def main():
cases = []
# Case 1: Debian APT source entry, Fedora YUM/DNF repo INI, and .deb/.rpm commands
apt_line = (
"deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] "
"https://packages.microsoft.com/repos/vscode stable main"
)
yum_repo_text = (
"[code]\n"
"name=Visual Studio Code\n"
"baseurl=https://packages.microsoft.com/yumrepos/vscode\n"
"enabled=1\n"
"gpgcheck=1\n"
"gpgkey=https://packages.microsoft.com/keys/microsoft.asc\n"
)
parser = configparser.ConfigParser()
parser.read_string(yum_repo_text)
deb_cmds = ["sudo dpkg -i code*.deb", "sudo apt-get install -f"]
rpm_cmd = "sudo rpm -i code*.rpm"
cases.append(
check(
"linux_repo_and_package_commands",
"Verify Debian APT signed-by repo line, Fedora YUM/DNF INI stanza, and .deb/.rpm install commands",
{
"apt_signed_by_keyring": True,
"yum_section": "code",
"yum_gpgcheck": True,
"deb_fixes_deps": True,
"rpm_install_flag": "-i",
},
{
"apt_signed_by_keyring": "signed-by=/usr/share/keyrings/microsoft.gpg" in apt_line,
"yum_section": parser.sections()[0],
"yum_gpgcheck": parser.get("code", "gpgcheck") == "1",
"deb_fixes_deps": deb_cmds[1].endswith("-f"),
"rpm_install_flag": rpm_cmd.split()[2],
},
)
)
# Case 2: Linux distro minimum versions & CLI PATH check
min_os = {
"Windows": "Windows 7 64 位或更高版本",
"macOS": "macOS 10.11 El Capitan 或更高版本",
"Linux": "Ubuntu 16.04+, Debian 9+, Fedora 30+, CentOS 7+",
}
linux_distros = [d.strip() for d in min_os["Linux"].split(",")]
cases.append(
check(
"linux_os_matrix_and_cli_bootstrap",
"Verify Linux supported distro floors and code CLI launch/PATH setup",
{
"linux_distro_count": 4,
"includes_ubuntu_and_fedora": True,
"cli_binary": "code",
"palette_shortcut_linux": "Ctrl + Shift + P",
},
{
"linux_distro_count": len(linux_distros),
"includes_ubuntu_and_fedora": (
any(d.startswith("Ubuntu") for d in linux_distros)
and any(d.startswith("Fedora") for d in linux_distros)
),
"cli_binary": "code",
"palette_shortcut_linux": "Ctrl + Shift + P",
},
)
)
print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
本例需在 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。
入口文件:projects/vscode-linux-install-lab/explore-linux-install.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-linux-install.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2213.zip
课程关联工程包(登记关联25章) · 含当前章节或实例 · mbskycom202612a2203.zip