![](/img/trans.png)
[英]How can I copy a file from colab to github repo directly? (It is possible to save the notebook in the Github repo)
[英]How can I get Helm's binary from their GitHub repo?
我正在嘗試使用腳本下載 Helm 的最新版本。 我想下載二進制文件並將其復制到文件中。 我嘗試查看文檔,但閱讀起來非常混亂,我不明白這一點。 我找到了一種下載特定文件的方法,但沒有關於二進制文件的內容。 到目前為止,我有:
from github import Github
def get_helm(filename):
f = open(filename, 'w') # The file I want to copy the binary to
g = Github()
r = g.get_repo("helm/helm")
# Get binary and use f.write() to transfer it to the file
f.close
return filename
我也很清楚我可以做的查詢的限制,因為沒有憑據。
特別是對於 Helm,您不會玩得很開心,因為他們顯然不會通過 GitHub 發布他們的發布文件,只有校驗和元數據。
見https://github.com/helm/helm/releases/tag/v3.6.0 ...
否則,這將很簡單:
https://api.github.com/repos/{repo}/releases
獲取 JSON 數據assets
以找到您需要的文件(例如,用於您的架構)不過,這里有一個腳本適用於 Helm 的額外 hoops-to-jump-through:
import requests
def download_binary_with_progress(source_url, dest_filename):
binary_resp = requests.get(source_url, stream=True)
binary_resp.raise_for_status()
with open(dest_filename, "wb") as f:
for chunk in binary_resp.iter_content(chunk_size=524288):
f.write(chunk)
print(f.tell(), "bytes written")
return dest_filename
def download_newest_helm(desired_architecture):
releases_resp = requests.get(
f"https://api.github.com/repos/helm/helm/releases"
)
releases_resp.raise_for_status()
releases_data = releases_resp.json()
newest_release = releases_data[0]
for asset in newest_release.get("assets", []):
name = asset["name"]
# For a project using regular releases, this would be simplified to
# checking for the desired architecture and doing
# download_binary_with_progress(asset["browser_download_url"], name)
if desired_architecture in name and name.endswith(".tar.gz.asc"):
tarball_filename = name.replace(".tar.gz.asc", ".tar.gz")
tarball_url = f"https://get.helm.sh/{tarball_filename}"
return download_binary_with_progress(
source_url=tarball_url, dest_filename=tarball_filename
)
raise ValueError("No matching release found")
download_newest_helm("darwin-arm64")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.