Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customized Welcome After Pages and Conclusion Pages #590

Merged
merged 39 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
188ce66
Adding in an example folder for custom welcome and conclusion for Win…
ryanskeith Dec 6, 2022
6646ccb
Adding in documentation for changes for Windows for the welcome and c…
ryanskeith Dec 6, 2022
070e13f
Adding in some changes.
ryanskeith Dec 6, 2022
fdc8ee3
Adding in example image.
ryanskeith Dec 6, 2022
50415c3
Adding in custom welome and conclusion file code.
ryanskeith Dec 6, 2022
6b45c6c
Adding in code to add in extra resources for extra pages.
ryanskeith Dec 6, 2022
6343f9f
Fixing an error with the nsis script.
ryanskeith Dec 6, 2022
4ed5eb6
Adding functionality for extra pages after welcome.
ryanskeith Dec 7, 2022
02917f3
fixing name collision.
ryanskeith Dec 7, 2022
c380ebb
Adding in news information about enhancement.
ryanskeith Dec 7, 2022
3f77efc
Merge branch 'main' into customize_welcome_conclusion
jaimergp Dec 8, 2022
3757f0e
Update CONSTRUCT.md via python ./scripts/make_docs.py
dbast Dec 8, 2022
07f7f13
Merge branch 'main' into customize_welcome_conclusion
dbast Dec 13, 2022
86d8023
Giving a warning if OSX packager sees an nsi file in the conclusion o…
ryanskeith Dec 14, 2022
0b49590
Update constructor/nsis/main.nsi.tmpl
ryanskeith Dec 14, 2022
cfd4ac5
Spelling changes.
ryanskeith Dec 14, 2022
0d8ac9c
Adding custom_welcome and custome_conclusion to ppd dict.
ryanskeith Dec 14, 2022
cb8df27
Update constructor/nsis/main.nsi.tmpl
ryanskeith Dec 14, 2022
a1735c4
Removing code line for custom dir.
ryanskeith Dec 14, 2022
60fbccb
extra_files items need to be in list form in yaml.
ryanskeith Dec 14, 2022
0fe9459
Fixing examples files because they need to define MUI_PAGE_WELOME and…
ryanskeith Dec 14, 2022
7287edc
Cleaning out last of extra files to plugins stuff.
ryanskeith Dec 15, 2022
f2ebebc
Update constructor/winexe.py
ryanskeith Dec 15, 2022
65f40eb
Update constructor/osxpkg.py
ryanskeith Dec 15, 2022
431571a
Succinct code and adding Warning for consistency.
ryanskeith Dec 15, 2022
a02d21a
Adding in extra temp file functionality.
ryanskeith Dec 15, 2022
1d4bd43
Changing how copy_extra_files works so temp_extra_files can use it too.
ryanskeith Dec 16, 2022
30cfee4
Merge branch 'main' into customize_welcome_conclusion
dbast Jan 3, 2023
a13c3de
Update news/590-windows-installer-enhancement
ryanskeith Jan 4, 2023
3d0d3bb
Update constructor/osxpkg.py
ryanskeith Jan 4, 2023
b5f0b86
Merge branch 'temporary_extra_files' into customize_welcome_conclusion
ryanskeith Jan 4, 2023
36bca48
Add missing comma
dbast Jan 5, 2023
21aa838
Fixing docs.
ryanskeith Jan 5, 2023
66eeb31
Update examples/customized_welcome_conclusion/construct.yaml
ryanskeith Jan 10, 2023
e148b6a
Update news/590-windows-installer-enhancement
ryanskeith Jan 10, 2023
7cceea5
Update constructor/winexe.py
ryanskeith Jan 10, 2023
cae3969
Adding in comments to explain example custom pages.
ryanskeith Jan 10, 2023
b173e0f
Merge branch 'main' into customize_welcome_conclusion
jaimergp Jan 11, 2023
ac4b1b5
doc update
dbast Jan 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 15 additions & 7 deletions CONSTRUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ The default type is `sh` on Linux and macOS, and `exe` on Windows. A special
value of `all` builds _both_ `sh` and `pkg` installers on macOS, as well
as `sh` on Linux and `exe` on Windows.

Notes for silent mode `/S` on Windows EXEs:
Notes for silent mode `/S` on Windows EXEs:
- NSIS Silent mode will not print any error message, but will silently abort the installation.
If needed, [NSIS log-builds][nsis-log] can be used to print to `%PREFIX%\install.log`, which can be
If needed, [NSIS log-builds][nsis-log] can be used to print to `%PREFIX%\install.log`, which can be
searched for `::error::` strings. Pre- and post- install scripts will only throw an error
if the environment variable `NSIS_SCRIPTS_RAISE_ERRORS` is set.
- The `/D` flag can be used to specify the target location. It must be the last argument in
Expand Down Expand Up @@ -360,7 +360,7 @@ Path to a post-install script. Some notes:
available in the `${INSTALLER_NAME}`, `${INSTALLER_VER}`, `${INSTALLER_PLAT}`
environment variables. `${INSTALLER_TYPE}` is set to `SH`.
- For PKG installers, the shebang line is respected if present;
otherwise, `bash` is used. The same variables mentioned for `sh`
otherwise, `bash` is used. The same variables mentioned for `sh`
installers are available here. `${INSTALLER_TYPE}` is set to `PKG`.
- For Windows `.exe` installers, the script must be a `.bat` file.
Installation path is available as `%PREFIX%`. Metadata about
Expand Down Expand Up @@ -389,9 +389,9 @@ This option has no effect on `SH` installers.
_required:_ no<br/>
_type:_ string<br/>
Path to a pre uninstall script. This is only supported for on Windows,
and must be a `.bat` file. Installation path is available as `%PREFIX%`.
and must be a `.bat` file. Installation path is available as `%PREFIX%`.
Metadata about the installer can be found in the `%INSTALLER_NAME%`,
`%INSTALLER_VER%`, `%INSTALLER_PLAT%` environment variables.
`%INSTALLER_VER%`, `%INSTALLER_PLAT%` environment variables.
`%INSTALLER_TYPE%` is set to `EXE`.

## `default_prefix`
Expand Down Expand Up @@ -463,8 +463,8 @@ _type:_ boolean<br/>
Whether to show UI notifications on PKG installers. On large installations,
the progress bar reaches ~90% very quickly and stays there for a long time.
This might look like the installer froze. This option enables UI notifications
so the user receives updates after each command executed by the installer.
(macOS only)
so the user receives updates after each command executed by the installer.
(macOS only)

## `welcome_image`

Expand Down Expand Up @@ -581,6 +581,10 @@ File can be plain text (.txt), rich text (.rtf) or HTML (.html). If
both `welcome_file` and `welcome_text` are provided, `welcome_file` takes precedence.
(MacOS only).

If the installer is for windows and welcome file type is nsi,
it will use the nsi script to add in extra pages before the installer
begins the installation process.

## `welcome_text`

_required:_ no<br/>
Expand Down Expand Up @@ -622,6 +626,10 @@ plain text (.txt), rich text (.rtf) or HTML (.html). If both
`conclusion_file` and `conclusion_text` are provided,
`conclusion_file` takes precedence. (MacOS only).

If the installer is for windows and conclusion file type is nsi,
it will use the nsi script to add in extra pages and the conclusion file
at the end of the installer.

## `conclusion_text`

_required:_ no<br/>
Expand Down
22 changes: 15 additions & 7 deletions constructor/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@
value of `all` builds _both_ `sh` and `pkg` installers on macOS, as well
as `sh` on Linux and `exe` on Windows.

Notes for silent mode `/S` on Windows EXEs:
Notes for silent mode `/S` on Windows EXEs:
- NSIS Silent mode will not print any error message, but will silently abort the installation.
If needed, [NSIS log-builds][nsis-log] can be used to print to `%PREFIX%\\install.log`, which can be
If needed, [NSIS log-builds][nsis-log] can be used to print to `%PREFIX%\\install.log`, which can be
searched for `::error::` strings. Pre- and post- install scripts will only throw an error
if the environment variable `NSIS_SCRIPTS_RAISE_ERRORS` is set.
- The `/D` flag can be used to specify the target location. It must be the last argument in
Expand Down Expand Up @@ -289,7 +289,7 @@
available in the `${INSTALLER_NAME}`, `${INSTALLER_VER}`, `${INSTALLER_PLAT}`
environment variables. `${INSTALLER_TYPE}` is set to `SH`.
- For PKG installers, the shebang line is respected if present;
otherwise, `bash` is used. The same variables mentioned for `sh`
otherwise, `bash` is used. The same variables mentioned for `sh`
installers are available here. `${INSTALLER_TYPE}` is set to `PKG`.
- For Windows `.exe` installers, the script must be a `.bat` file.
Installation path is available as `%PREFIX%`. Metadata about
Expand All @@ -314,9 +314,9 @@

('pre_uninstall', False, str, '''
Path to a pre uninstall script. This is only supported for on Windows,
and must be a `.bat` file. Installation path is available as `%PREFIX%`.
and must be a `.bat` file. Installation path is available as `%PREFIX%`.
Metadata about the installer can be found in the `%INSTALLER_NAME%`,
`%INSTALLER_VER%`, `%INSTALLER_PLAT%` environment variables.
`%INSTALLER_VER%`, `%INSTALLER_PLAT%` environment variables.
`%INSTALLER_TYPE%` is set to `EXE`.
'''),

Expand Down Expand Up @@ -374,8 +374,8 @@
Whether to show UI notifications on PKG installers. On large installations,
the progress bar reaches ~90% very quickly and stays there for a long time.
This might look like the installer froze. This option enables UI notifications
so the user receives updates after each command executed by the installer.
(macOS only)
so the user receives updates after each command executed by the installer.
(macOS only)
'''),

('welcome_image', False, str, '''
Expand Down Expand Up @@ -463,6 +463,10 @@
File can be plain text (.txt), rich text (.rtf) or HTML (.html). If
both `welcome_file` and `welcome_text` are provided, `welcome_file` takes precedence.
(MacOS only).

If the installer is for windows and welcome file type is nsi,
it will use the nsi script to add in extra pages before the installer
begins the installation process.
'''),

('welcome_text', False, str, '''
Expand Down Expand Up @@ -496,6 +500,10 @@
plain text (.txt), rich text (.rtf) or HTML (.html). If both
`conclusion_file` and `conclusion_text` are provided,
`conclusion_file` takes precedence. (MacOS only).

If the installer is for windows and conclusion file type is nsi,
it will use the nsi script to add in extra pages and the conclusion file
at the end of the installer.
'''),

('conclusion_text', False, str, '''
Expand Down
15 changes: 12 additions & 3 deletions constructor/nsis/main.nsi.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,13 @@ BrandingText /TRIMLEFT "${COMPANY}"

# Pages
#!define MUI_PAGE_CUSTOMFUNCTION_SHOW OnStartup
#if custom_welcome
# Custom welcome file(s)
@CUSTOM_WELCOME_FILE@
#else
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipPageIfUACInnerInstance
!insertmacro MUI_PAGE_WELCOME
#endif
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipPageIfUACInnerInstance
!insertmacro MUI_PAGE_LICENSE __LICENSEFILE__
Page Custom InstModePage_Create InstModePage_Leave
Expand All @@ -151,7 +156,12 @@ Page Custom mui_AnaCustomOptions_Show
!define MUI_FINISHPAGE_TITLE_3LINES
!define MUI_FINISHPAGE_TEXT __CONCLUSION_TEXT__
#endif
#if custom_conclusion
# Custom conclusion file(s)
@CUSTOM_CONCLUSION_FILE@
#else
!insertmacro MUI_PAGE_FINISH
#endif

!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
Expand Down Expand Up @@ -467,7 +477,6 @@ Function .onInit
Push $R2

InitPluginsDir

!insertmacro ParseCommandLineArgs

# Select the correct registry to look at, depending
Expand Down Expand Up @@ -1004,7 +1013,7 @@ Section "Install"
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("CONDA_PKGS_DIRS", "$INSTDIR\pkgs")".r0'
# Extra info for pre and post install scripts
# NOTE: If more vars are added, make sure to update the examples/scripts tests too
# There's a similar block for the pre_uninstall script, further down this file.
# There's a similar block for the pre_uninstall script, further down this file.
# Update that one as well!
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("PREFIX", "$INSTDIR").r0'
System::Call 'kernel32::SetEnvironmentVariable(t,t)i("INSTALLER_NAME", "${NAME}").r0'
Expand Down Expand Up @@ -1175,7 +1184,7 @@ Section "Uninstall"
!insertmacro AbortRetryNSExecWaitLibNsisCmd "pre_uninstall"
!insertmacro AbortRetryNSExecWaitLibNsisCmd "rmpath"
!insertmacro AbortRetryNSExecWaitLibNsisCmd "rmreg"

DetailPrint "Removing files and folders..."
nsExec::Exec 'cmd.exe /D /C RMDIR /Q /S "$INSTDIR"'

Expand Down
13 changes: 10 additions & 3 deletions constructor/osxpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,18 @@ def modify_xml(xml_path, info):
root.append(background)

### WELCOME ###
if "welcome_file" in info:
# The endswith .nsi is for windows specifically. The nsi script will add in
# welcome pages if added.
if "welcome_file" in info and not info["welcome_file"].endswith(".nsi"):
ryanskeith marked this conversation as resolved.
Show resolved Hide resolved
welcome_path = info["welcome_file"]
elif "welcome_text" in info and info["welcome_text"]:
welcome_path = join(PACKAGES_DIR, "welcome.txt")
with open(welcome_path, "w") as f:
f.write(info["welcome_text"])
else:
welcome_path = None
if "welcome_file" in info and info["welcome_file"].endswith(".nsi"):
print(f"NSI welcome_file, {info['welcome_file'].endswith('.nsi')}, is ignored.")
ryanskeith marked this conversation as resolved.
Show resolved Hide resolved

if welcome_path:
welcome = ET.Element(
Expand All @@ -117,7 +121,9 @@ def modify_xml(xml_path, info):
root.append(welcome)

### CONCLUSION ###
if "conclusion_file" in info:
# The endswith .nsi is for windows specifically. The nsi script will add in
# conclusion pages if added.
if "conclusion_file" in info and not info["conclusion_file"].endswith(".nsi"):
ryanskeith marked this conversation as resolved.
Show resolved Hide resolved
conclusion_path = info["conclusion_file"]
elif "conclusion_text" in info:
if not info["conclusion_text"]:
Expand All @@ -128,7 +134,8 @@ def modify_xml(xml_path, info):
f.write(info["conclusion_text"])
else:
conclusion_path = join(OSX_DIR, 'acloud.rtf')

if "conclusion_file" in info and info["conclusion_file"].endswith(".nsi"):
print(f"NSI conclusion_file, {info['conclusion_file'].endswith('.nsi')}, is ignored.")
ryanskeith marked this conversation as resolved.
Show resolved Hide resolved
if conclusion_path:
conclusion = ET.Element(
'conclusion', file=conclusion_path,
Expand Down
47 changes: 42 additions & 5 deletions constructor/winexe.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from subprocess import PIPE, check_call, check_output, run, STDOUT
import sys
import tempfile
from pathlib import PureWindowsPath
from pathlib import Path
from typing import List

from .construct import ns_platform
from .imaging import write_images
Expand All @@ -34,7 +35,7 @@ def str_esc(s, newlines=True):
return '"%s"' % s


def read_nsi_tmpl(info):
def read_nsi_tmpl(info) -> str:
path = abspath(info.get('nsis_template', join(NSIS_DIR, 'main.nsi.tmpl')))
print('Reading: %s' % path)
with open(path) as fi:
Expand All @@ -47,7 +48,7 @@ def pkg_commands(download_dir, dists):


def extra_files_commands(paths, common_parent):
paths = sorted([PureWindowsPath(p) for p in paths])
paths = sorted([Path(p) for p in paths])
ryanskeith marked this conversation as resolved.
Show resolved Hide resolved
lines = []
current_output_path = "$INSTDIR"
for path in paths:
Expand All @@ -59,6 +60,37 @@ def extra_files_commands(paths, common_parent):
lines.append(f"File {path}")
return lines

def insert_tempfile_commands(paths: os.PathLike) -> List[str]:
"""Helper function that copies paths into temporary install directory.

Args:
paths (os.PathLike): Paths to files that need to be copied

Returns:
List[str]: Commands to be inserted into nsi template
"""
if paths:
lines = ['SetOutPath $PLUGINSDIR']
for path in sorted([Path(p) for p in paths]):
lines.append(f"File {path}")
return lines
else:
return ['']


def custom_nsi_insert_from_file(filepath: os.PathLike) -> str:
"""Insert NSI script commands from file.

Args:
filepath (os.PathLike): Path to file

Returns:
string block of file
"""
if not filepath:
return ''
return Path(filepath).read_text()


def setup_envs_commands(info, dir_path):
template = """
Expand Down Expand Up @@ -227,6 +259,8 @@ def make_nsi(info, dir_path, extra_files=()):
ppd['with_conclusion_text'] = bool(conclusion_text)
ppd["enable_debugging"] = bool(os.environ.get("NSIS_USING_LOG_BUILD"))
ppd["has_conda"] = info["_has_conda"]
ppd["custom_welcome"] = "welcome_file" in info and info["welcome_file"].endswith(".nsi")
ppd["custom_conclusion"] = "conclusion_file" in info and info["conclusion_file"].endswith(".nsi")
ryanskeith marked this conversation as resolved.
Show resolved Hide resolved
data = preprocess(data, ppd)
data = fill_template(data, replace)
if info['_platform'].startswith("win") and sys.platform != 'win32':
Expand Down Expand Up @@ -255,6 +289,9 @@ def make_nsi(info, dir_path, extra_files=()):
'${NAME} ${VERSION} (Python ${PYVERSION} ${ARCH})'
)),
('@EXTRA_FILES@', '\n '.join(extra_files_commands(extra_files, dir_path))),
('@CUSTOM_WELCOME_FILE@', custom_nsi_insert_from_file(info.get('welcome_file', ''))),
ryanskeith marked this conversation as resolved.
Show resolved Hide resolved
('@CUSTOM_CONCLUSION_FILE@', custom_nsi_insert_from_file(info.get('conclusion_file', ''))),
('@EXTRA_FILES_TO_PLUGINS_DIR@', '\n '.join(insert_tempfile_commands(extra_files)))
]:
data = data.replace(key, value)

Expand Down Expand Up @@ -320,7 +357,7 @@ def verify_installer_signature(path):
# we had errors but maybe not critical ones
print(
f"!!! SignTool could find a signature in {path} but detected errors. "
"Please check your certificate!",
"Please check your certificate!",
file=sys.stderr
)

Expand All @@ -338,7 +375,7 @@ def create(info, verbose=False):
except KeyError:
with open(pre_dst, 'w') as fo:
fo.write(":: this is an empty pre install .bat script\n")

post_dst = join(tmp_dir, 'post_install.bat')
try:
shutil.copy(info['post_install'], post_dst)
Expand Down
Binary file not shown.
11 changes: 11 additions & 0 deletions examples/customized_welcome_conclusion/construct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: CustomizedWelcomeConclusion
version: X
installer_type: all
channels:
- http://repo.anaconda.com/pkgs/main/
specs:
- python
conclusion_file: custom_conclusion.nsi # [win]
welcome_file: custom_welcome.nsi # [win]
extra_files:
- ExtraPagesExampleImg.bmp: "$PluginsDir"