Page 1 of 1
[SOLVED] Removing a dependency in Python
Published: January 24, 2024 - 09:52
by Benoit
Hello,
a Wapt Enterprise
version of Wapt 2.4.14.143,
server = Debian, and
package creation PC = Windows 10.
I would like to know if it's possible to remove a package from its dependencies within a Python script?
For example:
A = condition,
B = package name,
C = hostname.
If condition A is true, then
remove B from C.
I've searched using wapt-get, but I haven't found anything.
Thank you in advance for your help.
Re: Removing a dependency in Python
Published: January 24, 2024 - 12:41
by sfonteneau
Hello Benoit,
The best approach in this kind of situation is to create a meta-package and avoid dependencies, and in that case, you're free to do whatever you want
example :
Code: Select all
# -*- coding: utf-8 -*-
from setuphelpers import *
def install():
hostname = get_computername().lower()
# Si les 4 dernier caractères du poste sont "prof" alors j'installe Firefox ESR
if hostname.endswith('prof') :
WAPT.install('tis-firefox-esr')
if 'eleves' in hostname :
if WAPT.is_installed('tis-gestionnote') :
WAPT.remove('tis-gestionnote')
if installed_softwares('Mozilla Firefox') :
WAPT.install('tis-firefox-esr')
# Si la manufacture du poste est 'innotek GmbH', installer le paquet drivers smp-drivers-for-innotek
if wmi_info_basic()["System_Information"]["Manufacturer"] == 'innotek GmbH' :
WAPT.install('tis-drivers-for-innotek')
unitorga = registry_readstring(HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine', 'Distinguished-Name')
if 'OU=Ordinateur_compta,OU=Ordinateur_administratif,DC=tranquilit,DC=local' in unitorga :
WAPT.install('tis-libreoffice-stable')
if 'mongroup' in get_computer_groups():
WAPT.install('tis-group')
Simon
Re: Removing a dependency in Python
Published: January 24, 2024 - 1:11 PM
by Benoit
Thank you for your reply, but that's not what I'm trying to do:
Here is the setup I'm posing for here:
Code: Select all
# -*- coding: utf-8 -*-
"""
Script type pour installation d'un exécutable
"""
"""
import module
"""
from setuphelpers import *
import subprocess
"""
déclarations variables
"""
# Indiquez le nom d'affichage du programme
name_app ="Adobe Acrobat"
# Indiquez le nom de l'executable servant à installer le programme
exe = "AcroRdrDCx642300820470_MUI.exe"
# Indiquez le Version du programme
min_version="2023.008.20470"
#varibles pour la mise en place du raccourci si besoin
label= ""
target = r""
silentflags =f'/sAll /rs /msi EULA_ACCEPT=YES '
#uninstall_cmd ="MsiExec.exe /x {AC76BA86-1033-FF00-7760-BC15014EA700} /quiet"
"""
déclaration fonctions
"""
# fonction qui permet d'installer l'application
def install_app():
try :
print(f"L'installation de {name_app} est en cours ...")
install_exe_if_needed(exe,silentflags=silentflags,key='',min_version=min_version)
print(f"L'application {name_app} a été installée avec succès")
# commenté les deux lignes ci-dessous avec un '#' si vous n'avez pas besoin de créer un raccourci
#create_desktop_shortcut(label,target)
#print(f"Le raccourci {label} a été créer avec succès")
except Exception as e :
print(f"L'erreur 1 suivante s'est produite : {e}")
# fonction qui permet de désinstaller l'application
def uninstall():
try:
for soft in installed_softwares():
if name_app in soft['name']:
if soft['name'] != "Adobe Acrobat 2017" and soft['name'] != "Adobe Acrobat 2020":
key= soft['key']
uninstall_cmd = f"msiexec /x {key} /quiet"
print(f"L'application {name_app} est déjà installée. Elle va être désinstallée.\nMerci de patienter ...")
subprocess.run(uninstall_cmd)
print(f"L'application {name_app} a été désinstallée avec succès")
# commenté les deux lignes ci-dessous avec un '#' si vous n'avez pas besoin de supprimer un raccourci
#remove_desktop_shortcut(label)
#print(f"Le raccourci {label} a été supprimé avec succès")
break
except Exception as e :
print(f"L'erreur 2 suivante s'est produite : {e}")
"""
main code
"""
def install():
try:
pro = False
for soft in installed_softwares():
if soft['name'] == "Adobe Acrobat 2017" or soft['name'] == "Adobe Acrobat 2020" or soft['name'] == "Adobe Creative Cloud":
print(f"Une version pro de l'application {name_app} est déjà installée.\nCette version ne sera donc pas déployé sur ce poste")
pro =True
break
if not pro:
uninstall()
install_app()
except Exception as e :
print(f"L'erreur 3 suivante s'est produite : {e}")
I would like that if "pro" is true, then this package should be removed from the dependencies of the PC for which pro is true.
Re: Removing a dependency in Python
Published: January 24, 2024 - 1:34 PM
by sfonteneau
Hello Benoit,
Impossible, the dependency is at the package level, so it will come back...
You need to create a meta package for Adobe Reader:
tis-adboe-reader
and in the package something like this:
Code: Select all
def install():
if installed_software('adobe reader pro'):
WAPT.install('tis-adboe-reader-pro')
else
WAPT.install('tis-adboe-reader-normal')
Simon
Re: Removing a dependency in Python
Published: January 24, 2024 - 2:32 PM
by Benoit
Thank you for your reply.
If I understand correctly, it's impossible to remove a package from a PC's dependencies using the command line?
Regards,
Re: Removing a dependency in Python
Published: January 24, 2024 - 2:44 PM
by sfonteneau
Hi Benoit,
No, the PC can't edit the packages (remove a dependency) because it doesn't have your private key.
Simon
Re: Removing a dependency in Python
Published: January 24, 2024 - 2:50 PM
by Benoit
Thank you for your answers