Skip to content

Commit

Permalink
feat: Init gen_nix_hash func
Browse files Browse the repository at this point in the history
  • Loading branch information
haruki7049 committed Jul 17, 2024
1 parent 841f450 commit 54272cf
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions fetch-releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import json
import requests
import subprocess


def get_all_releases(owner: str, repo: str) -> list:
Expand Down Expand Up @@ -53,3 +54,24 @@ def save_to_json(sources: dict, filename: str):
"""
with open(filename, "w") as file:
json.dump(sources, file, indent=2)


def gen_nix_hash(url: str) -> str:
"""
Generate nix-hash from url by using nix-prefetch-url
Parameters
----------
url : str
URL of the file to fetch
Returns
-------
hash : str
Nix hash of the file
>>> gen_nix_hash("https://github.com/denoland/deno/releases/download/v1.42.0/deno-x86_64-unknown-linux-gnu.zip")
0brv6v98jx2b2mwhx8wpv2sqr0zp2bfpiyv4ayziay0029rxldny
"""
result = subprocess.run(["nix-prefetch-url", url], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
return result.stdout.replace("\n", "")

0 comments on commit 54272cf

Please sign in to comment.