• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2File generation for catalog signing non-binary contents.
3"""
4
5__author__ = "Steve Dower <steve.dower@python.org>"
6__version__ = "3.8"
7
8
9import sys
10
11__all__ = ["PYTHON_CAT_NAME", "PYTHON_CDF_NAME"]
12
13
14def public(f):
15    __all__.append(f.__name__)
16    return f
17
18
19PYTHON_CAT_NAME = "python.cat"
20PYTHON_CDF_NAME = "python.cdf"
21
22
23CATALOG_TEMPLATE = r"""[CatalogHeader]
24Name={target.stem}.cat
25ResultDir={target.parent}
26PublicVersion=1
27CatalogVersion=2
28HashAlgorithms=SHA256
29PageHashes=false
30EncodingType=
31
32[CatalogFiles]
33"""
34
35
36def can_sign(file):
37    return file.is_file() and file.stat().st_size
38
39
40@public
41def write_catalog(target, files):
42    with target.open("w", encoding="utf-8") as cat:
43        cat.write(CATALOG_TEMPLATE.format(target=target))
44        cat.writelines("<HASH>{}={}\n".format(n, f) for n, f in files if can_sign(f))
45