Page 1 of 2

setup.py script template

Published: May 2, 2016 - 10:26 PM
by so37
Hello,

I would like a template to perform the following steps:

Check if the software is installed on the client machine; if it is installed, uninstall it and then reinstall it; if it is not installed, install it.


Thank you in advance.

Re: Setup.py script template

Published: May 3, 2016 - 09:10
by sfonteneau
!!! Compatible only from version 1.3.5 onwards, I believe !!!

To install only if the software is not present or the version is older:

Exe:

Code: Select all

def install ():
     install_exe_if_needed('vlc-2.2.2-win32.exe',silentflags='/S --no-qt-privacy-ask --no-qt-updates-notif',key='VLC media player',min_version='2.2.2',killbefore=['vlc.exe'],accept_returncodes=[0],timeout=300)
 
MSI (simpler):

Code: Select all

def install ():
   install_msi_if_needed('install_flash_player_21_active_x.msi',killbefore=['iexplore.exe'])
In most cases, prior uninstallation is not necessary, but not always.
To initiate an uninstallation:

Code: Select all

      softname = 'Scribus'
      versionsoft = '15.007.20033'
      check_installed_soft = installed_softwares(softname)
      if check_installed_soft:
             for uninstall in check_installed_soft:
                if Version(uninstall['version']) < Version(versionsoft):
                   key=uninstall['key']
                   if installed_softwares(uninstallkey=key):
                      cmd = WAPT.uninstall_cmd(uninstall['key'])
                      run(cmd)
However, this method can sometimes cause problems.
Indeed, in the example we are looking for software with the name scribus.
But if in our software, a program is called "Sribus plugin extra"
Well, this one will go through it too.

In this case, the setup.py file will need to be more specific

Simon

Re: Setup.py script template

Published: May 3, 2016 - 10:05 AM
by so37
Here is my script to install Visual Studio 2005 Tools for Office Second Edition Runtime (vstor2005.exe):

Code: Select all

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

uninstallkey = ["{388E4B09-3E71-4649-8921-F44A3A2954A7}"]
uninstallstring = ['msiexec /qb /uninstall {388E4B09-3E71-4649-8921-F44A3A2954A7}']

def install ():
     install_exe_if_needed('vstor2005.exe', '/q',accept_returncodes=[0],timeout=300)

	
def uninstall():
      softname = 'Visual Studio 2005 Tools pour Office Second Edition Runtime'
      versionsoft = '8.0.50727.940'
      check_installed_soft = installed_softwares(softname)
      if check_installed_soft:
             for uninstall in check_installed_soft:
                if uninstall['version'] == versionsoft:
                   cmd = 'msiexec /qb /uninstall {388E4B09-3E71-4649-8921-F44A3A2954A7}'
                   run(cmd)


The code appears to work only if vstor2005 is not installed; however, when vstor2005 is already installed, here is the error message:

Code: Select all

C:\Windows\system32>wapt-get install C:\Users\x\Desktop\Nuxeo\enm
-vstor2005
Installing WAPT file C:\Users\x\Desktop\Nuxeo\enm-vstor2005
2016-05-03 10:13:38,529 CRITICAL Fatal error in install script: EWaptSetupExcept
ion: Fatal error : Setup vstor2005.exe has been and uninstall key None found but
 version is not good:
Traceback (most recent call last):
  File "C:\wapt\common.py", line 3178, in install_wapt
    exitstatus = setup.install()
  File "C:\Users\x\Desktop\Nuxeo\enm-vstor2005\setup.py", line 8,
 in install
    install_exe_if_needed('vstor2005.exe','/q',accept_returncodes=[0],timeout=30
0)
  File "C:\wapt\setuphelpers.py", line 3416, in install_exe_if_needed
    error('Setup %s has been and uninstall key %s found but version is not good'
 % (exe,key))
  File "C:\wapt\setuphelpers.py", line 3524, in error
    raise EWaptSetupException(u'Fatal error : %s' % reason)
EWaptSetupException: Fatal error : Setup vstor2005.exe has been and uninstall ke
y None found but version is not good

FATAL ERROR : EWaptSetupException: Fatal error : Setup vstor2005.exe has been an
d uninstall key None found but version is not good

Re: Setup.py script template

Published: May 3, 2016 - 10:10 AM
by so37
When I uninstall this package, it's supposed to uninstall with the command that

Code: Select all

msiexec /qb /uninstall {388E4B09-3E71-4649-8921-F44A3A2954A7}

Re: Setup.py script template

Published: May 3, 2016 - 10:28 AM
by sfonteneau
One problem after another...

If no min_version is specified (as in your case), install_exe_if_needed will read the version from the executable file's properties (if the executable is correctly formatted). Are you sure you don't want to specify a min_version?

Also, there's no key argument in your command.

We'll look at uninstallation later.

Re: Setup.py script template

Published: May 3, 2016 - 10:38
by so37
I'm not entirely sure what min_version refers to, but if it's preferable to do so, why not? Regarding the executable, the version of vstor2005.exe = 8.0.50727.940. Is that what you're interested in?

Re: Setup.py script template

Published: May 3, 2016 - 10:44 AM
by so37
Here are the changes made regarding def install:

Code: Select all

def install ():
     install_exe_if_needed('vstor2005.exe','/q',min_version='8.0.50727.940',key='Visual Studio 2005 Tools pour Office Second Edition Runtime',accept_returncodes=[0],timeout=300)	

Re: Setup.py script template

Published: May 7, 2016 - 1:00 PM
by sfonteneau
A small error has been fixed in setuphelpers.py

https://github.com/tranquilit/WAPT/comm ... 84de4f0488

It's possible your problem stemmed from there,

Simon

Re: Setup.py script template

Published: May 9, 2016 - 09:07
by so37
Here is my current model:

Code: Select all

# -*- coding: utf-8 -*-
import subprocess
from setuphelpers import *
import os
import time
import platform

uninstallkey = []
uninstallstring = ['msiexec /qb /uninstall {B0E8A140-26FA-43C7-AA0F-03691E6DBB02}']


def install():
  global uninstallkey
  from common import Wapt
  softname = 'Nuxeo MSIE Browser Extension'
  versionsoft = '2.1.3'
  check_installed = installed_softwares(softname)
  # si cette liste globale n est pas vide, on check chaque logiciel
  if check_installed:
             # boucle pour chaque logiciel trouvée
             for uninstall in check_installed:
                      cmd = "msiexec /qb /uninstall {B0E8A140-26FA-43C7-AA0F-03691E6DBB02}"
                      run(cmd)

  if iswin64():
        killalltasks('iexplore.exe')
        run("Nuxeo-MSIEBrowserExtension.msi /quiet /norestart")

  else:
        killalltasks('iexplore.exe')
        print run("Nuxeo-MSIEBrowserExtension.msi /quiet /norestart")


def uninstall():
  softname = 'Nuxeo MSIE Browser Extension'
  versionsoft = '2.1.3'
  check_installed = installed_softwares(softname)
  # si cette liste globale n est pas vide, on check chaque logiciel
  if check_installed:
             # boucle pour chaque logiciel trouvée
             for uninstall in check_installed:
                      cmd = "msiexec /qb /uninstall {B0E8A140-26FA-43C7-AA0F-03691E6DBB02}"
                      run(cmd)


Is there a better option? Is it optimized enough?

Re: Setup.py script template

Published: May 11, 2016 - 1:52 PM
by so37
After setting the WAPTService to administrator privileges, things improved; however, when I run the script I copied above, I get the following error message:

Code: Select all

"id"	"description"	"summary"	"start_date"	"logs"
10	Installation of test-nuxeobrowser (=2.1.3-6) (task #10)	Exception: Error during install of test-nuxeobrowser (=2.1.3-6): errors in packages test-nuxeobrowser	2016-05-11T13:51:41.573000	Installing test-nuxeobrowser
Exception: Error during install of test-nuxeobrowser (=2.1.3-6): errors in packages test-nuxeobrowser
Traceback (most recent call last):
  File "C:\wapt\waptservice\waptservice.py", line 2063, in run
    self.running_task.run()
  File "C:\wapt\waptservice\waptservice.py", line 1323, in pwrapper
    return func(*arg, **kwargs)
  File "C:\wapt\waptservice\waptservice.py", line 1383, in run
    self._run()
  File "C:\wapt\waptservice\waptservice.py", line 1807, in _run
    ','.join([ p[1].package for p in self.result['errors']]),
Exception: Error during install of test-nuxeobrowser (=2.1.3-6): errors in packages test-nuxeobrowser