MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / _download

Function _download

pkg/pypi/src/codebase_memory_mcp/_cli.py:1289–1417  ·  view source on GitHub ↗
(version: str)

Source from the content-addressed store, hash-verified

1287
1288
1289def _download(version: str) -> Path:
1290 os_name = _os_name()
1291 arch = _arch()
1292 ext = "zip" if os_name == "windows" else "tar.gz"
1293 # Linux ships a fully-static "-portable" build; the standard linux binary
1294 # dynamically links glibc 2.38+ and fails on older distros. macOS/Windows
1295 # have no such variant. Keep in sync with install.sh / install.js / cli.c.
1296 portable = "-portable" if os_name == "linux" else ""
1297 archive = f"codebase-memory-mcp-{os_name}-{arch}{portable}.{ext}"
1298 base, loopback = _download_base(version)
1299 url = f"{base}/{archive}"
1300 _validate_download_url(url, loopback)
1301
1302 dest = _bin_path(version)
1303 dest.parent.mkdir(parents=True, exist_ok=True)
1304
1305 print(
1306 f"codebase-memory-mcp: downloading v{version} for {os_name}/{arch}...",
1307 file=sys.stderr,
1308 )
1309
1310 with tempfile.TemporaryDirectory() as tmp:
1311 tmp_archive = os.path.join(tmp, f"cbm.{ext}")
1312 try:
1313 _download_file(url, tmp_archive, loopback)
1314 except (OSError, RuntimeError, urllib.error.URLError) as e:
1315 sys.exit(
1316 f"codebase-memory-mcp: download failed ({e})\n"
1317 f"URL: {url}\n"
1318 f"See https://github.com/{REPO}/releases for available versions."
1319 )
1320
1321 _verify_checksum(tmp_archive, archive, base, loopback)
1322 _require_regular_archive(tmp_archive)
1323
1324 bin_name = (
1325 _WINDOWS_BINARY_NAME if os_name == "windows" else "codebase-memory-mcp"
1326 )
1327 extraction_names = (bin_name,)
1328 archive_names = (
1329 _WINDOWS_ARCHIVE_NAMES
1330 if os_name == "windows"
1331 else _UNIX_ARCHIVE_NAMES
1332 )
1333 if ext == "tar.gz":
1334 import tarfile
1335 with tarfile.open(tmp_archive) as tf:
1336 runtime_names = _safe_extract_tar(
1337 tf,
1338 tmp,
1339 archive_names,
1340 extraction_names,
1341 )
1342 else:
1343 import zipfile
1344 with zipfile.ZipFile(tmp_archive) as zf:
1345 runtime_names = _safe_extract_zip(
1346 zf,

Callers 1

mainFunction · 0.85

Calls 15

_os_nameFunction · 0.85
_archFunction · 0.85
_download_baseFunction · 0.85
_validate_download_urlFunction · 0.85
_bin_pathFunction · 0.85
_download_fileFunction · 0.85
_verify_checksumFunction · 0.85
_require_regular_archiveFunction · 0.85
_safe_extract_tarFunction · 0.85
_safe_extract_zipFunction · 0.85
_regular_fileFunction · 0.85
_runtime_set_namesFunction · 0.85

Tested by

no test coverage detected