diff options
author | Jakub Roztocil <jakub@roztocil.co> | 2016-08-13 22:40:01 +0200 |
---|---|---|
committer | Jakub Roztocil <jakub@roztocil.co> | 2016-08-13 22:40:01 +0200 |
commit | 6d65668355dd2b5e8bf385065677595c4e987e68 (patch) | |
tree | bbbe8fafe2578014d5b4568e3317981c5aaabd24 /extras | |
parent | 3e5115e4a259cd6ce60b259083de8b220f3b9e38 (diff) |
Strip request header values
Diffstat (limited to 'extras')
-rwxr-xr-x | extras/get-homebrew-formula-vars.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/extras/get-homebrew-formula-vars.py b/extras/get-homebrew-formula-vars.py new file mode 100755 index 00000000..c2c80dc2 --- /dev/null +++ b/extras/get-homebrew-formula-vars.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +""" +Generate URLs and file hashes to be included in the Homebrew formula +after a new release of HTTPie is published on PyPi. + +https://github.com/Homebrew/homebrew-core/blob/master/Formula/httpie.rb + +""" +import hashlib +import requests + + +PACKAGES = [ + 'httpie', + 'requests', + 'pygments', +] + + +def get_info(package_name): + api_url = 'https://pypi.python.org/pypi/{}/json'.format(package_name) + resp = requests.get(api_url).json() + hasher = hashlib.sha256() + for release in resp['urls']: + download_url = release['url'] + if download_url.endswith('.tar.gz'): + hasher.update(requests.get(download_url).content) + return { + 'name': package_name, + 'url': download_url, + 'sha256': hasher.hexdigest(), + } + else: + raise RuntimeError( + '{}: download not found: {}'.format(package_name, resp)) + + +packages = { + package_name: get_info(package_name) for package_name in PACKAGES +} + + +httpie_info = packages.pop('httpie') +print(""" + url "{url}" + sha256 "{sha256}" +""".format(**httpie_info)) + + +for package_info in packages.values(): + print(""" + resource "{name}" do + url "{url}" + sha256 "{sha256}" + end""".format(**package_info)) |