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

Function _download

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

Source from the content-addressed store, hash-verified

150
151
152def _download(version: str) -> Path:
153 os_name = _os_name()
154 arch = _arch()
155 ext = "zip" if os_name == "windows" else "tar.gz"
156 # Linux ships a fully-static "-portable" build; the standard linux binary
157 # dynamically links glibc 2.38+ and fails on older distros. macOS/Windows
158 # have no such variant. Keep in sync with install.sh / install.js / cli.c.
159 variant = "-portable" if os_name == "linux" else ""
160 archive = f"codebase-memory-mcp-{os_name}-{arch}{variant}.{ext}"
161 url = f"https://github.com/{REPO}/releases/download/v{version}/{archive}"
162 _validate_url_scheme(url)
163
164 dest = _bin_path(version)
165 dest.parent.mkdir(parents=True, exist_ok=True)
166
167 print(
168 f"codebase-memory-mcp: downloading v{version} for {os_name}/{arch}...",
169 file=sys.stderr,
170 )
171
172 with tempfile.TemporaryDirectory() as tmp:
173 tmp_archive = os.path.join(tmp, f"cbm.{ext}")
174 try:
175 urllib.request.urlretrieve(url, tmp_archive) # noqa: S310 — scheme validated above
176 except urllib.error.HTTPError as e:
177 sys.exit(
178 f"codebase-memory-mcp: download failed ({e})\n"
179 f"URL: {url}\n"
180 f"See https://github.com/{REPO}/releases for available versions."
181 )
182
183 _verify_checksum(tmp_archive, archive, version)
184
185 if ext == "tar.gz":
186 import tarfile
187 with tarfile.open(tmp_archive) as tf:
188 _safe_extract_tar(tf, tmp)
189 else:
190 import zipfile
191 with zipfile.ZipFile(tmp_archive) as zf:
192 _safe_extract_zip(zf, tmp)
193
194 bin_name = "codebase-memory-mcp.exe" if os_name == "windows" else "codebase-memory-mcp"
195 extracted = os.path.join(tmp, bin_name)
196 if not os.path.exists(extracted):
197 sys.exit("codebase-memory-mcp: binary not found after extraction")
198
199 shutil.copy2(extracted, dest)
200 current = dest.stat().st_mode
201 dest.chmod(current | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
202
203 return dest
204
205
206def main() -> None:

Callers 1

mainFunction · 0.85

Calls 7

_os_nameFunction · 0.85
_archFunction · 0.85
_validate_url_schemeFunction · 0.85
_bin_pathFunction · 0.85
_verify_checksumFunction · 0.85
_safe_extract_tarFunction · 0.85
_safe_extract_zipFunction · 0.85

Tested by

no test coverage detected