Skip to content

Commit

Permalink
feat(fetch-releases): 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 61c1774 commit 44179d6
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 requests
import json
import subprocess

def get_all_releases(owner: str, repo: str) -> list:
"""
Expand Down Expand Up @@ -52,3 +53,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 44179d6

Please sign in to comment.