-
-
Save HyShai/aa4ac21d9cf4992d3241 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding:utf-8 -*- | |
"""Download Zip bundle of Python package requirements for MarkdownPDF.py | |
and extract them to 'site-packages' sub-directory. | |
This is meant for Pythonista (an iOS app) users as an easy way to install | |
these packages. | |
Packages included in the Zip bundle: | |
* html5lib | |
* markdown2pdf | |
* PyPDF2 | |
* Reportlab (without C extensions) | |
* xhtml2pdf | |
""" | |
import hashlib, os, requests, sys, zipfile | |
ZIPFN = 'markdown2pdf.zip' | |
ZIPURL = 'http://chrisarndt.de/projects/markdown2pdf/' + ZIPFN | |
SHA256_DIGEST = "eadfffc65cf13a3333ae809e61fa93f508513a19a49314b62e4adcbecebe6cf0" | |
with open(ZIPFN, 'wb') as f: | |
print("Downloading zip archive '%s'..." % ZIPFN) | |
f.write(requests.get(ZIPURL).content) | |
with open(ZIPFN, 'rb') as f: | |
print("Checking file integrity...") | |
sha256 = hashlib.sha256() | |
sha256.update(f.read()) | |
digest = sha256.hexdigest() | |
if not digest == SHA256_DIGEST: | |
print("SHA-256 checksum mismatch.") | |
print("Expected: %s" % SHA256_DIGEST) | |
print("Actual: %s" % digest) | |
sys.exit(1) | |
else: | |
print('ok') | |
with zipfile.ZipFile(ZIPFN) as z: | |
print("Extracting zip file to 'site-packages'...") | |
if not os.path.isdir('site-packages'): | |
os.mkdir('site-packages') | |
z.extractall('site-packages') | |
os.unlink(ZIPFN) | |
print("Done.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment