Debian Codegraph @

tasks/build_/_dist.py

raw symbols SCIP
1 # -*- coding: ascii -*-
2 #
3 # Copyright 2007 - 2025
4 # Andr\xe9 Malo or his licensors, as applicable
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 """
18 Dist building code
19 ~~~~~~~~~~~~~~~~~~
20
21 """
22
23 import os as _os
24
25 # pylint: disable = import-outside-toplevel
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_)