author | Yuya Nishihara <yuya@tcha.org> |
Sat, 05 Oct 2019 09:58:21 -0400 | |
changeset 43082 | fdfe5cfb3723 |
parent 43076 | 2372284d9457 |
child 43516 | d053d3f10b6a |
permissions | -rw-r--r-- |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
1 |
# util.py - Common packaging utility code. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
2 |
# |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
3 |
# Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com> |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
4 |
# |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
6 |
# GNU General Public License version 2 or any later version. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
7 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
8 |
# no-check-code because Python 3 native. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
9 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
10 |
import distutils.version |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
11 |
import getpass |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
12 |
import os |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
13 |
import pathlib |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
14 |
import subprocess |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
15 |
import tarfile |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
16 |
import zipfile |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
17 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
18 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
19 |
def extract_tar_to_directory(source: pathlib.Path, dest: pathlib.Path): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
20 |
with tarfile.open(source, 'r') as tf: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
21 |
tf.extractall(dest) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
22 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
23 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
24 |
def extract_zip_to_directory(source: pathlib.Path, dest: pathlib.Path): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
25 |
with zipfile.ZipFile(source, 'r') as zf: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
26 |
zf.extractall(dest) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
27 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
28 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
29 |
def find_vc_runtime_files(x64=False): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
30 |
"""Finds Visual C++ Runtime DLLs to include in distribution.""" |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
31 |
winsxs = pathlib.Path(os.environ['SYSTEMROOT']) / 'WinSxS' |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
32 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
33 |
prefix = 'amd64' if x64 else 'x86' |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
34 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
35 |
candidates = sorted( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
36 |
p |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
37 |
for p in os.listdir(winsxs) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
38 |
if p.lower().startswith('%s_microsoft.vc90.crt_' % prefix) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
39 |
) |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
40 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
41 |
for p in candidates: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
42 |
print('found candidate VC runtime: %s' % p) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
43 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
44 |
# Take the newest version. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
45 |
version = candidates[-1] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
46 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
47 |
d = winsxs / version |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
48 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
49 |
return [ |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
50 |
d / 'msvcm90.dll', |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
51 |
d / 'msvcp90.dll', |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
52 |
d / 'msvcr90.dll', |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
53 |
winsxs / 'Manifests' / ('%s.manifest' % version), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
54 |
] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
55 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
56 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
57 |
def windows_10_sdk_info(): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
58 |
"""Resolves information about the Windows 10 SDK.""" |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
59 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
60 |
base = pathlib.Path(os.environ['ProgramFiles(x86)']) / 'Windows Kits' / '10' |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
61 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
62 |
if not base.is_dir(): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
63 |
raise Exception('unable to find Windows 10 SDK at %s' % base) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
64 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
65 |
# Find the latest version. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
66 |
bin_base = base / 'bin' |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
67 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
68 |
versions = [v for v in os.listdir(bin_base) if v.startswith('10.')] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
69 |
version = sorted(versions, reverse=True)[0] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
70 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
71 |
bin_version = bin_base / version |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
72 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
73 |
return { |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
74 |
'root': base, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
75 |
'version': version, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
76 |
'bin_root': bin_version, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
77 |
'bin_x86': bin_version / 'x86', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
78 |
'bin_x64': bin_version / 'x64', |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
79 |
} |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
80 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
81 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
82 |
def find_signtool(): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
83 |
"""Find signtool.exe from the Windows SDK.""" |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
84 |
sdk = windows_10_sdk_info() |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
85 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
86 |
for key in ('bin_x64', 'bin_x86'): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
87 |
p = sdk[key] / 'signtool.exe' |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
88 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
89 |
if p.exists(): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
90 |
return p |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
91 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
92 |
raise Exception('could not find signtool.exe in Windows 10 SDK') |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
93 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
94 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
95 |
def sign_with_signtool( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
96 |
file_path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
97 |
description, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
98 |
subject_name=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
99 |
cert_path=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
100 |
cert_password=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
101 |
timestamp_url=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
102 |
): |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
103 |
"""Digitally sign a file with signtool.exe. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
104 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
105 |
``file_path`` is file to sign. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
106 |
``description`` is text that goes in the signature. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
107 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
108 |
The signing certificate can be specified by ``cert_path`` or |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
109 |
``subject_name``. These correspond to the ``/f`` and ``/n`` arguments |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
110 |
to signtool.exe, respectively. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
111 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
112 |
The certificate password can be specified via ``cert_password``. If |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
113 |
not provided, you will be prompted for the password. |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
114 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
115 |
``timestamp_url`` is the URL of a RFC 3161 timestamp server (``/tr`` |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
116 |
argument to signtool.exe). |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
117 |
""" |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
118 |
if cert_path and subject_name: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
119 |
raise ValueError('cannot specify both cert_path and subject_name') |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
120 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
121 |
while cert_path and not cert_password: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
122 |
cert_password = getpass.getpass('password for %s: ' % cert_path) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
123 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
124 |
args = [ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
125 |
str(find_signtool()), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
126 |
'sign', |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
127 |
'/v', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
128 |
'/fd', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
129 |
'sha256', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
130 |
'/d', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42090
diff
changeset
|
131 |
description, |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
132 |
] |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
133 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
134 |
if cert_path: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
135 |
args.extend(['/f', str(cert_path), '/p', cert_password]) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
136 |
elif subject_name: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
137 |
args.extend(['/n', subject_name]) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
138 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
139 |
if timestamp_url: |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
140 |
args.extend(['/tr', timestamp_url, '/td', 'sha256']) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
141 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
142 |
args.append(str(file_path)) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
143 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
144 |
print('signing %s' % file_path) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
145 |
subprocess.run(args, check=True) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
146 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
147 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
148 |
PRINT_PYTHON_INFO = ''' |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
149 |
import platform; print("%s:%s" % (platform.architecture()[0], platform.python_version())) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
150 |
'''.strip() |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
151 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
152 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
153 |
def python_exe_info(python_exe: pathlib.Path): |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
154 |
"""Obtain information about a Python executable.""" |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
155 |
|
42090
9c07d345fd6d
packaging: don't crash building wix with python3.6 and earlier
Matt Harbison <matt_harbison@yahoo.com>
parents:
41952
diff
changeset
|
156 |
res = subprocess.check_output([str(python_exe), '-c', PRINT_PYTHON_INFO]) |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
157 |
|
42090
9c07d345fd6d
packaging: don't crash building wix with python3.6 and earlier
Matt Harbison <matt_harbison@yahoo.com>
parents:
41952
diff
changeset
|
158 |
arch, version = res.decode('utf-8').split(':') |
41952
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
159 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
160 |
version = distutils.version.LooseVersion(version) |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
161 |
|
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
162 |
return { |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
163 |
'arch': arch, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
164 |
'version': version, |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
165 |
'py3': version >= distutils.version.LooseVersion('3'), |
b83de9150c1c
packaging: convert files to LF
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41921
diff
changeset
|
166 |
} |