]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python3 | |
2 | ||
3 | """ | |
4 | Usage: python3 ./devscripts/update-formulae.py <path-to-formulae-rb> <version> | |
5 | version can be either 0-aligned (yt-dlp version) or normalized (PyPi version) | |
6 | """ | |
7 | ||
8 | # Allow direct execution | |
9 | import os | |
10 | import sys | |
11 | ||
12 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
13 | ||
14 | ||
15 | import json | |
16 | import re | |
17 | import urllib.request | |
18 | ||
19 | from devscripts.utils import read_file, write_file | |
20 | ||
21 | filename, version = sys.argv[1:] | |
22 | ||
23 | normalized_version = '.'.join(str(int(x)) for x in version.split('.')) | |
24 | ||
25 | pypi_release = json.loads(urllib.request.urlopen( | |
26 | 'https://pypi.org/pypi/yt-dlp/%s/json' % normalized_version | |
27 | ).read().decode()) | |
28 | ||
29 | tarball_file = next(x for x in pypi_release['urls'] if x['filename'].endswith('.tar.gz')) | |
30 | ||
31 | sha256sum = tarball_file['digests']['sha256'] | |
32 | url = tarball_file['url'] | |
33 | ||
34 | formulae_text = read_file(filename) | |
35 | ||
36 | formulae_text = re.sub(r'sha256 "[0-9a-f]*?"', 'sha256 "%s"' % sha256sum, formulae_text, count=1) | |
37 | formulae_text = re.sub(r'url "[^"]*?"', 'url "%s"' % url, formulae_text, count=1) | |
38 | ||
39 | write_file(filename, formulae_text) |