This tutorial will guide you through creating custom WAPT packages to deploy software that is not available in the WAPT store or to tailor existing software to your specific needs.
Whether you need to integrate an internal tool, a business application, or a modified version of a software, this method allows you to control deployment across your infrastructure.
7.1. Prerequisites: Setting Up Your Development Environment¶
To create and test WAPT packages, you need to meet the following requirements:
Administrator Rights: You must be a local administrator on the development machine to use WAPT’s integrated development environment.
Controlled Environment: We strongly recommend creating and editing packages in a safe and disposable environment, such as a virtual machine (e.g., VirtualBox). This avoids any impact on production systems.
Development Tools: Install a code editor to modify package files. We recommend:
- Visual Studio Code (with the WAPT extension)
- PyScripter 3 (specifically designed for WAPT)
- Avoid: PyScripter 4 (not compatible with WAPT development features).
WAPT Development Package: Import and install the `tis-waptdev` package from your WAPT repository. This package includes all the necessary tools for creating and testing WAPT packages.
If you need help importing or installing this package, refer to:
How to import and install a WAPT Package.
This method is recommended because it allows you to first test the package locally on the packaging workstation (the computer used to create the package). It also gives you the opportunity to customize the package so that it matches your organization’s requirements, for example by changing the installation directory, adding shortcuts, or configuring application-specific settings.
This will open your code editor and automatically position it on the setup.py file. You will see the following;
# -*- coding: utf-8 -*-fromsetuphelpersimport*r"""Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()"""# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between callsdefinstall():# Declaring local variables# Installing the softwareprint("Installing: naps2-8.3.2-win-x64.msi")install_msi_if_needed('naps2-8.3.2-win-x64.msi')
Testing locally the installation of the WAPT package
You can then test the installation on your development workstation without making any modifications at first.
Once launched, you will see the output in the installation function’s prompt, confirming that the installation completed successfully:
You can now verify that the software has been successfully uninstalled from the workstation:
Check that it no longer appears in the Start Menu when searching for: naps2.
If everything works as expected, you can proceed to the next step: importing the package.
Add a Desktop Shortcut for Naps2 (optionnal)
Now that both the installation and uninstallation are functional, you can further customize your package by adding additional code. In this example, we will add a desktop shortcut so users don’t have to search for the software in the Start Menu.
The function we need is create_desktop_shortcut, We will add the shortcut creation during the installation process, specifically in the install() function.
Here’s how the code looks:
# -*- coding: utf-8 -*-fromsetuphelpersimport*r"""Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()"""# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between callsdefinstall():# Declaring local variables# Installing the softwareprint("Installing: naps2-8.3.2-win-x64.msi")install_msi_if_needed('naps2-8.3.2-win-x64.msi')create_desktop_shortcut("NAPS",r'C:\Program Files\NAPS2\NAPS2.exe')#Command for add a desktop shortcut
We have successfully added the creation of a desktop shortcut. However, we must also handle its removal during uninstallation. For this, we use the remove_desktop_shortcut command.
Since the standard uninstallation process does not account for this shortcut (as it is not created in a standard way), we need to add a custom uninstallation step. This will be implemented in the uninstall() function.
During uninstallation, the uninstall() function will run first, followed by the standard software removal in the remove() function.
Here’s the updated code:
# -*- coding: utf-8 -*-fromsetuphelpersimport*r"""Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()"""# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between callsdefinstall():# Declaring local variables# Installing the softwareprint("Installing: naps2-8.3.2-win-x64.msi")install_msi_if_needed('naps2-8.3.2-win-x64.msi')create_desktop_shortcut("NAPS",r'C:\Program Files\NAPS2\NAPS2.exe')# command for add a desktop shortcutdefuninstall():remove_desktop_shortcut('NAPS')#Command for delete the desktop shortcut
You should now test the functionality by running the installation function and verifying that the desktop shortcut is created.