2018-11-02 17:18:04 +01:00
|
|
|
#!/usr/bin/env python3
|
2016-08-13 22:40:01 +02:00
|
|
|
"""
|
2019-02-03 15:08:29 +01:00
|
|
|
Generate Ruby code with URLs and file hashes for packages from PyPi
|
|
|
|
(i.e., httpie itself as well as its dependencies) to be included
|
|
|
|
in the Homebrew formula after a new release of HTTPie has been published
|
|
|
|
on PyPi.
|
2016-08-13 22:40:01 +02:00
|
|
|
|
2019-02-03 15:08:29 +01:00
|
|
|
<https://github.com/Homebrew/homebrew-core/blob/master/Formula/httpie.rb>
|
2016-08-13 22:40:01 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
import hashlib
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
PACKAGES = [
|
|
|
|
'httpie',
|
2019-02-03 14:26:05 +01:00
|
|
|
'Pygments',
|
2018-11-02 17:18:04 +01:00
|
|
|
'requests',
|
2020-08-15 17:50:00 +02:00
|
|
|
'requests-toolbelt',
|
2018-11-02 17:18:04 +01:00
|
|
|
'certifi',
|
|
|
|
'urllib3',
|
|
|
|
'idna',
|
|
|
|
'chardet',
|
|
|
|
'PySocks',
|
2016-08-13 22:40:01 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2018-07-12 21:16:16 +02:00
|
|
|
def get_package_meta(package_name):
|
2019-08-31 15:17:10 +02:00
|
|
|
api_url = f'https://pypi.python.org/pypi/{package_name}/json'
|
2016-08-13 22:40:01 +02:00
|
|
|
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:
|
2019-08-31 15:17:10 +02:00
|
|
|
raise RuntimeError(f'{package_name}: download not found: {resp}')
|
2016-08-13 22:40:01 +02:00
|
|
|
|
|
|
|
|
2018-07-12 21:16:16 +02:00
|
|
|
def main():
|
|
|
|
package_meta_map = {
|
|
|
|
package_name: get_package_meta(package_name)
|
|
|
|
for package_name in PACKAGES
|
|
|
|
}
|
|
|
|
httpie_meta = package_meta_map.pop('httpie')
|
|
|
|
print()
|
|
|
|
print(' url "{url}"'.format(url=httpie_meta['url']))
|
|
|
|
print(' sha256 "{sha256}"'.format(sha256=httpie_meta['sha256']))
|
|
|
|
print()
|
|
|
|
for dep_meta in package_meta_map.values():
|
|
|
|
print(' resource "{name}" do'.format(name=dep_meta['name']))
|
|
|
|
print(' url "{url}"'.format(url=dep_meta['url']))
|
|
|
|
print(' sha256 "{sha256}"'.format(sha256=dep_meta['sha256']))
|
|
|
|
print(' end')
|
2018-11-02 17:18:04 +01:00
|
|
|
print('')
|
2018-07-12 21:16:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|