PB double antislash

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
adaurg
Messages: 3
Registration: December 8, 2016 - 10:39

December 8, 2016 - 11:31

Good morning,

First of all, a huge thank you to the development team for this fantastic solution that makes my life so much easier ;)

After setting up the deployment of the classic packages.
I'm tackling the creation of my first packages… Sorry, I'm also a Python newbie :D

I am looking to install Qgis 2.14.9.
Installing Qgis 2.14.9 is no problem EXCEPT that I have to uninstall the previous version first: a 2.14.3 (which wasn't installed with wapt, otherwise I might have been able to use the "conflicts" function if I understand correctly?)

So I set up this:

Code: Select all

from setuphelpers import *

uninstallkey = ['QGIS 2.14']

def install():
    print('installation de Qgis 2.14.9')
    if isrunning('qgis-bin.exe'):
        print("Qgis est ouvert !!! GRRRR...")
        quit()

    print('desinstallation de Qgis 2.14.3')
    sofname = 'Qgis Essen'
    versionsoft = '2.14.3'
    uninstallkey = ['QGIS Essen']
    check_installed_soft = installed_softwares(sofname)
    if check_installed_soft:
        for uninstall in check_installed_soft:
            if Version(uninstall['version']) < Version(versionsoft):
                cmd = WAPT.uninstall_cmd(uninstall['key'])
                run(cmd)

    run(r'"QGIS-OSGeo4W-2.14.9-2-Setup-x86_64.exe" /S')
    remove_desktop_shortcut(r'GRASS GIS 7.0.4')
    remove_desktop_shortcut(r'GRASS GIS 7.0.5')
    remove_desktop_shortcut(r'OSGeo4W Shell')
    remove_tree(r'C:\Users\Public\Desktop\QGIS Essen')
    remove_tree(r'C:\Users\Public\Desktop\QGIS 2.14')
except that when I run it I get double backslashes in the path of the uninstallation executable added even though the value in the registry is correct.

Code: Select all

FATAL ERROR : CalledProcessError: Command '([u'C:\\Program Files\\QGIS Essen\\Un
install-QGIS.exe', '/S'],)' returned non-zero exit status 1
I searched through the forum posts but I didn't find anything :cry:

What is the way to get around this problem?

Thank you for your help
Denis
User avatar
htouvet
WAPT Expert
Messages: 436
Registration: March 16, 2015 - 10:48
Contact :

December 8, 2016 - 11:44

Double backslashes are "normal"
This is the display of the content of a string of characters with the backslashes "escaped" (so that they are not interpreted as control characters)

The problem lies elsewhere, most likely a 32/64 bit issue.
Wapt is a 32-bit process. Therefore, C:\Program Files\ is automatically changed to C:\Program Files (x86)\ by Windows

I therefore suggest that you disable the automatic 32/64 Windows redirection using the context function "with disable_file_system_redirection():"

Code: Select all

..
    if check_installed_soft:
        for uninstall in check_installed_soft:
            if Version(uninstall['version']) < Version(versionsoft):
                with disable_file_system_redirection():
                    cmd = WAPT.uninstall_cmd(uninstall['key'])
                    run(cmd)

...
Tranquil IT
adaurg
Messages: 3
Registration: December 8, 2016 - 10:39

December 8, 2016 - 1:58 PM

Thanks for the quick reply.
Noted about the double backslashes. :oops:

Indeed, QGIS 2.14.3 is 64-bit.

I tested it by disabling automatic redirection as indicated (thanks for the code).

But... the error is still there...

Perhaps I can work around the problem with a .bat file (but it's not very clean)?
In that case, should I put the .bat file in the same directory as the setup.py file? Or on a network share?

Thanks,
Denis
User avatar
htouvet
WAPT Expert
Messages: 436
Registration: March 16, 2015 - 10:48
Contact :

December 8, 2016 - 2:47 PM

You can draw inspiration from:

Code: Select all

from setuphelpers import *
import glob,time
import regutil

uninstallkey = []

version = '2.16.2-3'
url = "http://qgis.org/downloads/QGIS-OSGeo4W-%s-Setup-x86.exe" % version
url64 = "http://qgis.org/downloads/QGIS-OSGeo4W-%s-Setup-x86_64.exe" % version
exe = "QGIS-OSGeo4W-%s-Setup-x86.exe" % version
exe64 = "QGIS-OSGeo4W-%s-Setup-x86_64.exe" % version

def install():
    with disable_file_system_redirection():
        #Remove Old Versions in Default Directory
        for uninstall in glob.glob(makepath(programfiles,'QGIS*','Uninstall-QGIS.exe')):
            run_notfatal('"%s" /S'%uninstall)
            time.sleep(30)

        if isdir(makepath(programfiles,'QGIS 2.16.2')):
            remove_tree(makepath(programfiles,'QGIS 2.16.2'))

        #Fix bug with QGIS thinking it is still installed
        registry_delete(HKEY_LOCAL_MACHINE,makepath('Software','QGIS 2.16.2'),None)

    if iswin64():
        install_exe_if_needed(exe64,'/S',key='QGIS 2.16',min_version='')
    else:
        install_exe_if_needed(exe,'/S',key='QGIS Wien',min_version='')

Tranquil IT
adaurg
Messages: 3
Registration: December 8, 2016 - 10:39

December 13, 2016 - 10:40 PM

Thank you for your help

That saved me...
I still need to improve my Python skills... but so I did it like this

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *
import glob,time
import regutil

uninstallkey = ['QGIS 2.14']

def install():
    print('installation de Qgis 2.14.9')
    if isrunning('qgis-bin.exe'):
        print("Qgis est ouvert !!! GRRRR...")
        quit()

    print('desinstallation de Qgis 2.14.3')
    with disable_file_system_redirection():
        #Remove Old Versions in Default Directory
        for uninstall in glob.glob(makepath(programfiles,'QGIS*','Uninstall-QGIS.exe')):
            run_notfatal('"%s" /S'%uninstall)
            time.sleep(30)

        #Fix bug with QGIS thinking it is still installed
        registry_deletekey(HKEY_LOCAL_MACHINE,'software\microsoft\windows\currentversion\uninstall','QGIS Essen')
        registry_deletekey(HKEY_LOCAL_MACHINE,'software','QGIS Essen')


    run(r'"QGIS-OSGeo4W-2.14.9-2-Setup-x86_64.exe" /S')
    remove_desktop_shortcut(r'GRASS GIS 7.0.4')
    remove_desktop_shortcut(r'GRASS GIS 7.0.5')
    remove_desktop_shortcut(r'OSGeo4W Shell')
    remove_tree(r'C:\Users\Public\Desktop\QGIS Essen')
    remove_tree(r'C:\Users\Public\Desktop\QGIS 2.14')
    if isdir(makepath(programfiles,'QGIS Essen')):
            remove_tree(makepath(programfiles,'QGIS Essen'))
And it works. :P

Are you planning to create a special section for sharing setup.py files?

THANKS
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

December 14, 2016 - 10:31 PM

Attention here:

Code: Select all

def install():
    print('installation de Qgis 2.14.9')
    if isrunning('qgis-bin.exe'):
        print("Qgis est ouvert !!! GRRRR...")
        quit()
  
You exit here if qgis-bin.exe is open

There will therefore be no second attempt

You would need to replace it with

Code: Select all

def install():
    print('installation de Qgis 2.14.9')
    if isrunning('qgis-bin.exe'):
        error("Qgis est ouvert !!! GRRRR...")
  
User avatar
htouvet
WAPT Expert
Messages: 436
Registration: March 16, 2015 - 10:48
Contact :

December 15, 2016 - 8:13 AM

Also, specify that backslashes should not be interpreted by putting an 'r' (raw string) before the registry key path.

'r'software\microsoft\windows\currentversion\uninstall'
Tranquil IT
Locked