| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
""" |
| 18 |
Dist building code |
| 19 |
~~~~~~~~~~~~~~~~~~ |
| 20 |
|
| 21 |
""" |
| 22 |
|
| 23 |
import os as _os |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
def compress(ctx, filename, cmd, ext): |
| 29 |
"""Compress tar file""" |
| 30 |
prog = ctx.shell.frompath(cmd) |
| 31 |
if prog is None: |
| 32 |
return None |
| 33 |
|
| 34 |
ctx.run( |
| 35 |
"%s -c9 <%s >%s" |
| 36 |
% (ctx.q(prog), ctx.q(filename), ctx.q(filename + ext)), |
| 37 |
echo=True, |
| 38 |
) |
| 39 |
return filename + ext |
| 40 |
|
| 41 |
|
| 42 |
def digest(ctx, files, digestname): |
| 43 |
"""Make digest file""" |
| 44 |
import hashlib as _hashlib |
| 45 |
|
| 46 |
result = {} |
| 47 |
for filename in files: |
| 48 |
basename = _os.path.basename(filename) |
| 49 |
result[basename] = [] |
| 50 |
for method in ("md5", "sha1", "sha256"): |
| 51 |
sign = getattr(_hashlib, method)() |
| 52 |
with open(filename, "rb") as fp: |
| 53 |
for block in iter(lambda fp=fp: fp.read(8192), b""): |
| 54 |
sign.update(block) |
| 55 |
result[basename].append(sign.hexdigest()) |
| 56 |
|
| 57 |
with open(digestname, "wb") as fp: |
| 58 |
fp.write(b"\n# The file contains MD5, SHA1 and SHA256 digests\n") |
| 59 |
fp.write(b"# Check archive integrity with, e.g. md5sum -c\n") |
| 60 |
fp.write(b"# Check digest file integrity with PGP\n\n") |
| 61 |
|
| 62 |
for basename, digests in sorted(result.items()): |
| 63 |
for sign in digests: |
| 64 |
fp.write(("%s *%s\n" % (sign, basename)).encode("utf-8")) |
| 65 |
|
| 66 |
_sign_inline(ctx, digestname) |
| 67 |
|
| 68 |
|
| 69 |
def _sign_inline(ctx, filename): |
| 70 |
"""Sign file (inline)""" |
| 71 |
gpg = ctx.shell.frompath("gpg") |
| 72 |
ctx.run( |
| 73 |
ctx.c( |
| 74 |
""" |
| 75 |
%s --output %s --clearsign -- %s |
| 76 |
""", |
| 77 |
gpg, |
| 78 |
filename + ".signed", |
| 79 |
filename, |
| 80 |
), |
| 81 |
echo=True, |
| 82 |
) |
| 83 |
_os.rename(filename + ".signed", filename) |
| 84 |
|
| 85 |
|
| 86 |
def copy_changes(ctx): |
| 87 |
"""Copy changelog""" |
| 88 |
version = ctx.run("python setup.py --version", hide=True).stdout.strip() |
| 89 |
from_ = "CHANGES" |
| 90 |
to_ = "dist/CHANGES-%s" % (version,) |
| 91 |
ctx.shell.cp(from_, to_) |