Show More
@@ -1,154 +1,154 b'' | |||||
1 | # cli.py - Command line interface for automation |
|
1 | # cli.py - Command line interface for automation | |
2 | # |
|
2 | # | |
3 | # Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com> |
|
3 | # Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | # no-check-code because Python 3 native. |
|
8 | # no-check-code because Python 3 native. | |
9 |
|
9 | |||
10 | import argparse |
|
10 | import argparse | |
11 | import os |
|
11 | import os | |
12 | import pathlib |
|
12 | import pathlib | |
13 |
|
13 | |||
14 | from . import ( |
|
14 | from . import ( | |
15 | inno, |
|
15 | inno, | |
16 | wix, |
|
16 | wix, | |
17 | ) |
|
17 | ) | |
18 |
|
18 | |||
19 | HERE = pathlib.Path(os.path.abspath(os.path.dirname(__file__))) |
|
19 | HERE = pathlib.Path(os.path.abspath(os.path.dirname(__file__))) | |
20 | SOURCE_DIR = HERE.parent.parent.parent |
|
20 | SOURCE_DIR = HERE.parent.parent.parent | |
21 |
|
21 | |||
22 |
|
22 | |||
23 | def build_inno(pyoxidizer_target, iscc=None, version=None): |
|
23 | def build_inno(pyoxidizer_target, iscc=None, version=None): | |
24 | if iscc: |
|
24 | if iscc: | |
25 | iscc = pathlib.Path(iscc) |
|
25 | iscc = pathlib.Path(iscc) | |
26 | else: |
|
26 | else: | |
27 | iscc = ( |
|
27 | iscc = ( | |
28 | pathlib.Path(os.environ["ProgramFiles(x86)"]) |
|
28 | pathlib.Path(os.environ["ProgramFiles(x86)"]) | |
29 | / "Inno Setup 5" |
|
29 | / "Inno Setup 5" | |
30 | / "ISCC.exe" |
|
30 | / "ISCC.exe" | |
31 | ) |
|
31 | ) | |
32 |
|
32 | |||
33 | build_dir = SOURCE_DIR / "build" |
|
33 | build_dir = SOURCE_DIR / "build" | |
34 |
|
34 | |||
35 | inno.build_with_pyoxidizer( |
|
35 | inno.build_with_pyoxidizer( | |
36 | SOURCE_DIR, build_dir, pyoxidizer_target, iscc, version=version |
|
36 | SOURCE_DIR, build_dir, pyoxidizer_target, iscc, version=version | |
37 | ) |
|
37 | ) | |
38 |
|
38 | |||
39 |
|
39 | |||
40 | def build_wix( |
|
40 | def build_wix( | |
41 | pyoxidizer_target, |
|
41 | pyoxidizer_target, | |
42 | name=None, |
|
42 | name=None, | |
43 | version=None, |
|
43 | version=None, | |
44 | sign_sn=None, |
|
44 | sign_sn=None, | |
45 | sign_cert=None, |
|
45 | sign_cert=None, | |
46 | sign_password=None, |
|
46 | sign_password=None, | |
47 | sign_timestamp_url=None, |
|
47 | sign_timestamp_url=None, | |
48 | extra_wxs=None, |
|
48 | extra_wxs=None, | |
49 | extra_features=None, |
|
49 | extra_features=None, | |
50 | extra_pyoxidizer_vars=None, |
|
50 | extra_pyoxidizer_vars=None, | |
51 | ): |
|
51 | ): | |
52 | kwargs = { |
|
52 | kwargs = { | |
53 | "source_dir": SOURCE_DIR, |
|
53 | "source_dir": SOURCE_DIR, | |
54 | "version": version, |
|
54 | "version": version, | |
55 | "target_triple": pyoxidizer_target, |
|
55 | "target_triple": pyoxidizer_target, | |
56 | "extra_pyoxidizer_vars": extra_pyoxidizer_vars, |
|
56 | "extra_pyoxidizer_vars": extra_pyoxidizer_vars, | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | if extra_wxs: |
|
59 | if extra_wxs: | |
60 | kwargs["extra_wxs"] = dict( |
|
60 | kwargs["extra_wxs"] = dict( | |
61 | thing.split("=") for thing in extra_wxs.split(",") |
|
61 | thing.split("=") for thing in extra_wxs.split(",") | |
62 | ) |
|
62 | ) | |
63 | if extra_features: |
|
63 | if extra_features: | |
64 | kwargs["extra_features"] = extra_features.split(",") |
|
64 | kwargs["extra_features"] = extra_features.split(",") | |
65 |
|
65 | |||
66 | if sign_sn or sign_cert: |
|
66 | if sign_sn or sign_cert: | |
67 | kwargs["signing_info"] = { |
|
67 | kwargs["signing_info"] = { | |
68 | "name": name, |
|
68 | "name": name, | |
69 | "subject_name": sign_sn, |
|
69 | "subject_name": sign_sn, | |
70 | "cert_path": sign_cert, |
|
70 | "cert_path": sign_cert, | |
71 | "cert_password": sign_password, |
|
71 | "cert_password": sign_password, | |
72 | "timestamp_url": sign_timestamp_url, |
|
72 | "timestamp_url": sign_timestamp_url, | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | wix.build_installer_pyoxidizer(**kwargs) |
|
75 | wix.build_installer_pyoxidizer(**kwargs) | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | def get_parser(): |
|
78 | def get_parser(): | |
79 | parser = argparse.ArgumentParser() |
|
79 | parser = argparse.ArgumentParser() | |
80 |
|
80 | |||
81 | subparsers = parser.add_subparsers() |
|
81 | subparsers = parser.add_subparsers() | |
82 |
|
82 | |||
83 | sp = subparsers.add_parser("inno", help="Build Inno Setup installer") |
|
83 | sp = subparsers.add_parser("inno", help="Build Inno Setup installer") | |
84 | sp.add_argument( |
|
84 | sp.add_argument( | |
85 | "--pyoxidizer-target", |
|
85 | "--pyoxidizer-target", | |
86 | choices={"i686-pc-windows-msvc", "x86_64-pc-windows-msvc"}, |
|
86 | choices={"i686-pc-windows-msvc", "x86_64-pc-windows-msvc"}, | |
87 | required=True, |
|
87 | required=True, | |
88 | help="Build with PyOxidizer targeting this host triple", |
|
88 | help="Build with PyOxidizer targeting this host triple", | |
89 | ) |
|
89 | ) | |
90 | sp.add_argument("--iscc", help="path to iscc.exe to use") |
|
90 | sp.add_argument("--iscc", help="path to iscc.exe to use") | |
91 | sp.add_argument( |
|
91 | sp.add_argument( | |
92 | "--version", |
|
92 | "--version", | |
93 | help="Mercurial version string to use " |
|
93 | help="Mercurial version string to use " | |
94 | "(detected from __version__.py if not defined", |
|
94 | "(detected from __version__.py if not defined)", | |
95 | ) |
|
95 | ) | |
96 | sp.set_defaults(func=build_inno) |
|
96 | sp.set_defaults(func=build_inno) | |
97 |
|
97 | |||
98 | sp = subparsers.add_parser( |
|
98 | sp = subparsers.add_parser( | |
99 | "wix", help="Build Windows installer with WiX Toolset" |
|
99 | "wix", help="Build Windows installer with WiX Toolset" | |
100 | ) |
|
100 | ) | |
101 | sp.add_argument("--name", help="Application name", default="Mercurial") |
|
101 | sp.add_argument("--name", help="Application name", default="Mercurial") | |
102 | sp.add_argument( |
|
102 | sp.add_argument( | |
103 | "--pyoxidizer-target", |
|
103 | "--pyoxidizer-target", | |
104 | choices={"i686-pc-windows-msvc", "x86_64-pc-windows-msvc"}, |
|
104 | choices={"i686-pc-windows-msvc", "x86_64-pc-windows-msvc"}, | |
105 | required=True, |
|
105 | required=True, | |
106 | help="Build with PyOxidizer targeting this host triple", |
|
106 | help="Build with PyOxidizer targeting this host triple", | |
107 | ) |
|
107 | ) | |
108 | sp.add_argument( |
|
108 | sp.add_argument( | |
109 | "--sign-sn", |
|
109 | "--sign-sn", | |
110 | help="Subject name (or fragment thereof) of certificate " |
|
110 | help="Subject name (or fragment thereof) of certificate " | |
111 | "to use for signing", |
|
111 | "to use for signing", | |
112 | ) |
|
112 | ) | |
113 | sp.add_argument( |
|
113 | sp.add_argument( | |
114 | "--sign-cert", help="Path to certificate to use for signing" |
|
114 | "--sign-cert", help="Path to certificate to use for signing" | |
115 | ) |
|
115 | ) | |
116 | sp.add_argument("--sign-password", help="Password for signing certificate") |
|
116 | sp.add_argument("--sign-password", help="Password for signing certificate") | |
117 | sp.add_argument( |
|
117 | sp.add_argument( | |
118 | "--sign-timestamp-url", |
|
118 | "--sign-timestamp-url", | |
119 | help="URL of timestamp server to use for signing", |
|
119 | help="URL of timestamp server to use for signing", | |
120 | ) |
|
120 | ) | |
121 | sp.add_argument("--version", help="Version string to use") |
|
121 | sp.add_argument("--version", help="Version string to use") | |
122 | sp.add_argument( |
|
122 | sp.add_argument( | |
123 | "--extra-wxs", help="CSV of path_to_wxs_file=working_dir_for_wxs_file" |
|
123 | "--extra-wxs", help="CSV of path_to_wxs_file=working_dir_for_wxs_file" | |
124 | ) |
|
124 | ) | |
125 | sp.add_argument( |
|
125 | sp.add_argument( | |
126 | "--extra-features", |
|
126 | "--extra-features", | |
127 | help=( |
|
127 | help=( | |
128 | "CSV of extra feature names to include " |
|
128 | "CSV of extra feature names to include " | |
129 | "in the installer from the extra wxs files" |
|
129 | "in the installer from the extra wxs files" | |
130 | ), |
|
130 | ), | |
131 | ) |
|
131 | ) | |
132 |
|
132 | |||
133 | sp.add_argument( |
|
133 | sp.add_argument( | |
134 | "--extra-pyoxidizer-vars", |
|
134 | "--extra-pyoxidizer-vars", | |
135 | help="json map of extra variables to pass to pyoxidizer", |
|
135 | help="json map of extra variables to pass to pyoxidizer", | |
136 | ) |
|
136 | ) | |
137 |
|
137 | |||
138 | sp.set_defaults(func=build_wix) |
|
138 | sp.set_defaults(func=build_wix) | |
139 |
|
139 | |||
140 | return parser |
|
140 | return parser | |
141 |
|
141 | |||
142 |
|
142 | |||
143 | def main(): |
|
143 | def main(): | |
144 | parser = get_parser() |
|
144 | parser = get_parser() | |
145 | args = parser.parse_args() |
|
145 | args = parser.parse_args() | |
146 |
|
146 | |||
147 | if not hasattr(args, "func"): |
|
147 | if not hasattr(args, "func"): | |
148 | parser.print_help() |
|
148 | parser.print_help() | |
149 | return |
|
149 | return | |
150 |
|
150 | |||
151 | kwargs = dict(vars(args)) |
|
151 | kwargs = dict(vars(args)) | |
152 | del kwargs["func"] |
|
152 | del kwargs["func"] | |
153 |
|
153 | |||
154 | args.func(**kwargs) |
|
154 | args.func(**kwargs) |
General Comments 0
You need to be logged in to leave comments.
Login now