[SOLVED] Gesper software package creation

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

August 25, 2017 - 08:45

Good morning,

I am creating a new package in order to be able to deploy the Gesper software.
Installation and uninstallation work correctly in my package, but I would like to deploy the software configuration file to the user's %appdata% directory. Obviously, I'm encountering some difficulties. Here is my code:

Code: Select all

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

uninstallkey = []

def install():
    print('installing wapt-gesper')
    install_exe_if_needed("Gesper_Install_7.7.2.exe",'/verysilent /TASKS="MSDENonInstall"',key='{A2A6875A-1AAA-467F-948F-76851D7013AA}_is1',min_version='7.7.0.0',killbefore='gesper.exe')
    uninstallkey.remove('{A2A6875A-1AAA-467F-948F-76851D7013AA}_is1')
    create_desktop_shortcut(r'Gesper',target=u'C:\Program Files (x86)\CAP-RH\Gesper\Gesper.exe')
    import tempfile
    pathparamsfile = makepath(tempfile.gettempdir(),'params.ini')
    pathuser = user_appdata()
    data = ur"""[SETUP]
data_server=monserveur
data_access=
archives_path=C:\GESPER_BACKUP
"""
    fichier = open(pathparamsfile, "w")
    fichier.write(data)
    fichier.close()
    mkdirs(makepath('%s',Gesper) % pathuser)
    filecopyto('%s/params.ini' % pathparamsfile,'%s/Gesper' % pathuser)
    remove_file(pathparamsfile)

def uninstall():
    print('uninstalling wapt-geper')
    run('"C:\Program Files (x86)\CAP-RH\Gesper\unins000.exe" /verysilent')
    run('"MsiExec.exe" /I{900D6ADF-DF79-46FB-A58E-E89A73B2A132} /qn')
    remove_desktop_shortcut('Gesper.lnk')
Thank you for your help
Last edited by olaplanche on 06 Sep 2017 - 14:42, edited 1 time.
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

August 25, 2017 - 08:49

Hello,

I recommend you look at the session_setup:

https://www.wapt.fr/fr/doc/CreationPaqu ... index.html
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

September 6, 2017 - 8:53 AM

Good morning,

After modifying my code like this:

Code: Select all

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

uninstallkey = []

def install():
    print('installing wapt-gesper')
    install_exe_if_needed("Gesper_Install_7.7.2.exe",'/verysilent /TASKS="MSDENonInstall"',key='{A2A6875A-1AAA-467F-948F-76851D7013AA}_is1',min_version='7.7.0.0',killbefore='gesper.exe')
    uninstallkey.remove('{A2A6875A-1AAA-467F-948F-76851D7013AA}_is1')
    create_desktop_shortcut(r'Gesper',target=u'C:\Program Files (x86)\CAP-RH\Gesper\Gesper.exe')
    
def session_setup():
    import tempfile
    pathparamsfile = makepath(tempfile.gettempdir(),'params.ini')
    pathuser = user_appdata()
    data = ur"""[SETUP]
data_server=monserveur
data_access=
archives_path=C:\GESPER_BACKUP
"""
    fichier = open(pathparamsfile, "w")
    fichier.write(data)
    fichier.close()
    mkdirs(makepath('%s',Gesper) % pathuser)
    filecopyto('%s/params.ini' % pathparamsfile,'%s/Gesper' % pathuser)
    remove_file(pathparamsfile)

def uninstall():
    print('uninstalling wapt-geper')
    run('"C:\Program Files (x86)\CAP-RH\Gesper\unins000.exe" /verysilent')
    run('"MsiExec.exe" /I{900D6ADF-DF79-46FB-A58E-E89A73B2A132} /qn')
    remove_desktop_shortcut('Gesper.lnk')
I get the following error message when running session-setup:

638 CRITICAL NameError: global name 'Gesper' is not defined

Any ideas?

THANKS
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

September 6, 2017 - 1:33 PM

Code: Select all

mkdirs(makepath('%s',Gesper) % pathuser)
The ' ' are missing from Gesper
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

September 6, 2017 - 2:42 PM

I just solved my problem by modifying two lines of code as follows:

Code: Select all

    mkdirs('%s\\Gesper' %pathuser)
    filecopyto(pathparamsfile,'%s/Gesper' % pathuser)
My package is now fully functional!
Thank you for your help
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

September 6, 2017 - 4:01 PM

There was a small typo in the line of code for uninstalling SAP Crystal Reports; here is the final code:

Code: Select all

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

uninstallkey = []

def install():
    print('installing wapt-gesper')
    install_exe_if_needed("Gesper_Install_7.7.2.exe",'/verysilent /TASKS="MSDENonInstall"',key='{A2A6875A-1AAA-467F-948F-76851D7013AA}_is1',min_version='7.7.0.0',killbefore='gesper.exe')
    uninstallkey.remove('{A2A6875A-1AAA-467F-948F-76851D7013AA}_is1')
    create_desktop_shortcut(r'Gesper',target=u'C:\Program Files (x86)\CAP-RH\Gesper\Gesper.exe')

def session_setup():
    import tempfile
    pathparamsfile = makepath(tempfile.gettempdir(),'params.ini')
    pathuser = user_appdata()
    data = ur"""[SETUP]
data_server=dnsdemonserveur
data_access=
archives_path=C:\GESPER_BACKUP
"""
    fichier = open(pathparamsfile, "w")
    fichier.write(data)
    fichier.close()
    mkdirs('%s\\Gesper' %pathuser)
    filecopyto(pathparamsfile,'%s/Gesper' % pathuser)
    remove_file(pathparamsfile)

def uninstall():
    print('uninstalling wapt-geper')
    run('"C:\Program Files (x86)\CAP-RH\Gesper\unins000.exe" /verysilent')
    run('"MsiExec.exe" /X{900D6ADF-DF79-46FB-A58E-E89A73B2A132} /qn')
    remove_desktop_shortcut('Gesper.lnk')
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

September 17, 2021 - 2:28 PM

Good morning,

Code version updated as of 09/2021:

Code: Select all

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

uninstallkey = []

# Defining variables
bin_name_string = 'Logiciel Gesper - installation-%s.exe'
bin_temp = 'Logiciel Gesper - installation.exe'
url_dl = 'https://www.aplon.org/Ressources/Documents/T%C3%A9l%C3%A9chargements/Gesper%20(RH)/Logiciel%20Gesper%20-%20installation.exe'
app_uninstallkey = '{A2A6875A-1AAA-467F-948F-76851D7013AA}_is1'
SERVERNAME = 'MONSERVERGESPER' # Le nom NETBIOS du serveur gesper

def install():
    # Initializing variables
    package_version = control.version.split('-',1)[0]
    bin_name = bin_name_string % package_version
    session_setup()
    print('Installing: %s' % bin_name)
    try:
        install_exe_if_needed(bin_name,'/verysilent /TASKS="MSDENonInstall"',key=app_uninstallkey,min_version=package_version,killbefore='gesper.exe',timeout=600)
        uninstallkey.remove(app_uninstallkey)
    except TimeoutExpired:
        pass
        killalltasks('AdminConsole.exe')
        create_desktop_shortcut(r'Gesper',target=u'C:\Program Files (x86)\CAP-RH\Gesper\Gesper.exe')

def session_setup():
    import tempfile
    pathparamsfile = makepath(tempfile.gettempdir(),'params.ini')
    pathuser = user_appdata()
    data = r"""[SETUP]
data_server=%s
data_access=
archives_path=C:\GESPER_BACKUP
""" % SERVERNAME
    fichier = open(pathparamsfile, "w")
    fichier.write(data)
    fichier.close()
    mkdirs('%s\\Gesper' % pathuser)
    filecopyto(pathparamsfile,'%s/Gesper' % pathuser)
    remove_file(pathparamsfile)

def update_package():
    print('Download/Update package content from upstream binary sources')

    # Initializing variables
    proxies = get_proxies()
    if not proxies:
        proxies = get_proxies_from_wapt()
    latest_bin = bin_temp
    version = '1.0' # Fake version

    print('Download url is: ' + url_dl)

    # Downloading latest binaries
    if isfile(bin_temp):
        remove_file(bin_temp)
    if not isfile(latest_bin):
        print('Downloading: %s' % latest_bin)
        wget(url_dl, latest_bin, proxies=proxies)


        # Checking version from file
        version_from_file = get_version_from_binary(latest_bin)
        if version != version_from_file:
            os.rename(latest_bin,bin_name_string % version_from_file)
            version = version_from_file

        # Changing version of the package
        control.version = '%s-%s' % (version, int(control.version.split('-')[-1])+1)
        control.save_control_to_wapt()
        print('Changing version to: %s in WAPT\\control' % control.version)

    # Deleting outdated binaries
    remove_outdated_binaries(version)
    # put here what to do to update package content with newer installers.
    # launched with command wapt-get update-package-sources <path-to-wapt-directory>
    # implicit context variables are WAPT, basedir, control, user, params, run
    # if attributes in control are changed, they should be explicitly saved to package file with control.save_control_to_wapt()

def get_proxies():
    import platform
    if platform.python_version_tuple()[0] == '3':
        from urllib.request import getproxies
    else:
        from urllib import getproxies
    return getproxies()


def get_proxies_from_wapt():
    import platform
    proxies = {}
    if platform.system() == 'Windows':
        waptconsole_ini_path = makepath(user_local_appdata(), 'waptconsole', 'waptconsole.ini')
    else:
        waptconsole_ini_path = makepath(user_home_directory(), '.config', 'waptconsole', 'waptconsole.ini')
    if isfile(waptconsole_ini_path):
        proxy_wapt = inifile_readstring(waptconsole_ini_path, 'global', 'http_proxy')
        if proxy_wapt:
            proxies = {'http': proxy_wapt, 'https': proxy_wapt}
    return proxies


def remove_outdated_binaries(version, list_extensions=['exe','msi','deb','rpm','dmg','pkg'], list_filename_contain=None):
    if type(list_extensions) != list:
        list_extensions = [list_extensions]
    if list_filename_contain:
        if type(list_filename_contain) != list:
            list_filename_contain = [list_filename_contain]
    list_extensions = ['.' + ext for ext in list_extensions if ext[0] != '.']
    for file_ext in list_extensions:
        for bin_in_dir in glob.glob('*%s' % file_ext):
            if not version in bin_in_dir:
                remove_file(bin_in_dir)
            if list_filename_contain:
                for filename_contain in list_filename_contain:
                    if not filename_contain in bin_in_dir:
                        remove_file(bin_in_dir)


def get_version_from_binary(filename, parameter='ProductVersion'):
    if filename.endswith('.msi'):
        return get_msi_properties(filename)[parameter]
    else:
        return get_file_properties(filename)[parameter]

def uninstall():
    print('Uninstalling: %s' % control.package)
    run(r'"%s\CAP-RH\Gesper\unins000.exe" /verysilent' % programfiles32)
    run(r'"MsiExec.exe" /X{81BDC5D8-E319-435E-91F5-0896E599717A} /qn')
    remove_desktop_shortcut('Gesper.lnk')
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
Locked