Page 1 of 1

[SOLVED] Error creating a package via the Windows portable application package generator

Published: August 18, 2023 - 4:11 PM
by elux
Good morning,
I get an error message when I try to install a package generated by the WAPT console.
The product is W11Classicmenu, and to install it, you need to copy the directory. So I used the "Windows portable application" option
Unfortunately, here is the error message I get when I try to install it:

Code: Select all

Traceback (most recent call last):
  File "C:\Program Files (x86)\wapt\common.py", line 4009, in install_wapt
    setup = import_setup(setup_filename)
  File "C:\Program Files (x86)\wapt\waptutils.py", line 1525, in import_setup
    py_mod = imp.load_source(modulename, setupfilename)
  File "imp.py", line 171, in load_source
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 839, in exec_module
  File "<frozen importlib._bootstrap_external>", line 976, in get_code
  File "<frozen importlib._bootstrap_external>", line 906, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\WINDOWS\TEMP\wapt1fubbh_4\setup.py", line 26
    print("Copying directory: %%s to: %%s" %% (dir_name, app_dir))
                                            ^
SyntaxError: invalid syntax

SyntaxError: invalid syntax (setup.py, line 26)

The setup.py file seems correct to me:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

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 calls
dir_name = 'W11ClassicMenu'
app_name = 'W11ClassicMenu'
app_exe = 'W11ClassicMenu.exe'
app_dir = makepath(programfiles32, dir_name)
app_path = makepath(app_dir, app_exe)


def install():
    # Initializing variables

    # Installing software
    print("Installing: mgp-W11ClassicMenu")
    killalltasks(control.get_impacted_process_list())
    mkdirs(app_dir)
    if isdir(app_dir):
        remove_tree(app_dir)
    mkdirs(app_dir)
    print("Copying directory: %%s to: %%s" %% (dir_name, app_dir))
    copytree2(dir_name, app_dir)

    # Creating shortcuts
    create_desktop_shortcut(app_name, app_path)
    create_programs_menu_shortcut(app_name, app_path)


def uninstall():
    # Uninstalling software
    killalltasks(control.get_impacted_process_list())
    if isdir(app_dir):
        remove_tree(app_dir)

    # Removing shortcuts
    remove_desktop_shortcut(app_name)
    remove_programs_menu_shortcut(app_name)


def audit():
    # Declaring local variables
    package_version = '1.2.0.0'

    # Getting installed software version
    if isfile(app_path):
        installed_version = get_version_from_binary(app_path)
    else :
        installed_version = None

    # Auditing software
    print("Auditing: mgp-W11ClassicMenu")
    if installed_version is None or installed_version < package_version:
        print("%%s version is incorrect (%%s)" %% (app_name, installed_version))
        return "ERROR"
    else:
        print("%%s is installed in correct version (%%s)" %% (app_name, installed_version))
        return "OK"


If you have any idea what the problem might be...
Thanks in advance
Eric

Re: Error creating a package via the Windows Portable Application Package Generator

Published: August 21, 2023 - 09:19
by t.heroult
Good morning

In WAPT packages, generally only one "%" is used and not two.

instead of

Code: Select all

print("Copying directory: %%s to: %%s" %% (dir_name, app_dir))
I would try with

Code: Select all

print("Copying directory: %s to: %s" % (dir_name, app_dir))
Sincerely,
Tom

Re: Error creating a package via the Windows Portable Application Package Generator

Published: August 21, 2023 - 10:54
by blemoigne
Good morning,
Python even recommends using the following syntax now:

Code: Select all

print(f"Copying directory: {dir_name} to:  {app_dir}")
an f for "format" before the string and curly braces for each variable.

Best regards,
Bertrand

Re: Error creating a package via the Windows Portable Application Package Generator

Published: August 28, 2023 - 3:48 PM
by elux
Hello,
Yes, that solved the problem, thank you very much!
Resolved