setup.py script template

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
so37
Messages: 23
Registration: Apr 10, 2016 - 1:43 p.m.

May 2, 2016 - 10:26 PM

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.
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

May 3, 2016 - 09:10

!!! 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
so37
Messages: 23
Registration: Apr 10, 2016 - 1:43 p.m.

May 3, 2016 - 10:05

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
Last edited by so37 on May 3, 2016 - 10:16, edited 1 time.
so37
Messages: 23
Registration: Apr 10, 2016 - 1:43 p.m.

May 3, 2016 - 10:10

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}
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

May 3, 2016 - 10:28

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.
so37
Messages: 23
Registration: Apr 10, 2016 - 1:43 p.m.

May 3, 2016 - 10:38

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?
so37
Messages: 23
Registration: Apr 10, 2016 - 1:43 p.m.

May 3, 2016 - 10:44

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)	
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

May 7, 2016 - 1:00 PM

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
so37
Messages: 23
Registration: Apr 10, 2016 - 1:43 p.m.

May 9, 2016 - 09:07

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?
so37
Messages: 23
Registration: Apr 10, 2016 - 1:43 p.m.

May 11, 2016 - 1:52 PM

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

Locked