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