Page 1 of 1

PB double antislash

Published: Dec 8, 2016 - 11:31
by adaurg
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

Re: Problem with double backslash

Published: Dec 8, 2016 - 11:44 AM
by htouvet
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)

...

Re: Problem with double backslash

Published: Dec 8, 2016 - 1:58 PM
by adaurg
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

Re: Problem with double backslash

Published: Dec 8, 2016 - 2:47 PM
by htouvet
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='')


Re: Problem with double backslash

Published: Dec 13, 2016 - 10:40 PM
by adaurg
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

Re: Problem with double backslash

Published: Dec 14, 2016 - 10:31 PM
by sfonteneau
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...")
  

Re: Problem with double backslash

Published: Dec 15, 2016 - 08:13
by htouvet
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'