Code : Tout sélectionner
# -*- coding: utf-8 -*-
import setuphelpers
from setuphelpers import *
import os
#import time
year = '2018' # à changer chaque année
#test du système pour chemin valide
if iswin64():
#version 2018
uninstallkey = "{26BC6156-3E08-4D06-89BD-A39711861AAA}"
installsheildpath = 'c:\\program files (x86)\\InstallShield Installation Information'
archi = 'x64'
else:
uninstallkey = "{0BBE1447-6994-406D-B62B-D01A3DE0F2E7}"
installsheildpath = 'c:\\program files\\InstallShield Installation Information'
archi = 'x86'
try:
os.stat('c:\\ematt')
except:
os.mkdir('c:\\ematt')
try:
os.stat('c:\\ematt\\pronote')
except:
os.mkdir('c:\\ematt\\pronote')
try:
os.stat('c:\\ematt\\pronote\\'+year+'')
except:
os.mkdir('c:\\ematt\\pronote\\'+year+'')
unattend_install = 'c:\\ematt\\pronote\\'+year+'\\pronote_unattend_install.iss'
#print(installsheildpath) #control
#Lister les différents produit installés et les désinstaller
# p['key'] variable contenant la clef d'identification des versions !créer les fichiers dans un repertoire temporaire!
def uninstall():
pronoteinstall = setuphelpers.installed_softwares('pronote') #identique à wapt-get list-registry pronote
#print(pronoteinstall) ##control
## à implémenter une condition pour savoir si la variable précédente est non nul, dans le cas contraire il faut sauter la boucle!!!!
if len(pronoteinstall) != 0: ##-----> connais pas en python????
for p in pronoteinstall:
unattend_uninstall = ("c:\\ematt\\pronote\\"+year+"\\"+"Uninstall_pronote_"+p['key']+".iss") #stocke un chemin pour un fichier réponse prore à une version
#print(unattend_uninstall) # control
#test = 'Uninstall_pronote_'+p['key']+'.iss' # control
#print(p['key']) #control
#print(test) #control
#Création du fichier réponse à la volée
file = open(unattend_uninstall,'w')
file.write("[InstallShield Silent]"'\n')
file.write("Version=v7.00"'\n')
file.write("File=Response File"'\n')
file.write("OverwrittenReadOnly=NoToAll"'\n')
file.write("["+p['key']+"-DlgOrder]"'\n')
file.write("Dlg0="+p['key']+"-MessageBox-0"'\n')
file.write("Count=2"'\n')
file.write("Dlg1="+p['key']+"-SdFinishReboot-0"'\n')
file.write("["+p['key']+"-MessageBox-0]"'\n')
file.write("Result=6"'\n')
file.write("["+p['key']+"-SdFinishReboot-0]"'\n')
file.write("Result=1"'\n')
file.write("BootOption=0")
file.close()
#lancer la désinstallation
#print('"'+installsheildpath+'\\'+p['key']+'\\setup.exe" -s -uninst -f1'+unattend_uninstall) #control
#time.sleep(300) ## pause pour controle
print('Desinstallation de '+p['name'])
os.system('"'+installsheildpath+'\\'+p['key']+'\\setup.exe" -s -uninst -f1'+unattend_uninstall)
print('toutes les installations ont ete supprimees')
else :
print('aucune version de pronote installee')
def install():
uninstall() ##sortir les installations précédentes
##Creation du fichier reponse de l'installation
file = open(unattend_install,'w')
file.write("[InstallShield Silent]"'\n')
file.write("Version=v7.00"'\n')
file.write("File=Response File"'\n')
file.write("[File Transfer]"'\n')
file.write("OverwrittenReadOnly=NoToAll"'\n')
file.write("[{26BC6156-3E08-4D06-89BD-A39711861AAA}-DlgOrder]"'\n')
file.write("Dlg0="+uninstallkey+"-SdLicense2Rtf-0"'\n')
file.write("Count=5"'\n')
file.write("Dlg1="+uninstallkey+"-SdAskDestPath-0"'\n')
file.write("Dlg2="+uninstallkey+"-AskOptions-0"'\n')
file.write("Dlg3="+uninstallkey+"-AskOptions-1"'\n')
file.write("Dlg4="+uninstallkey+"-SdFinish-0"'\n')
file.write("["+uninstallkey+"-SdLicense2Rtf-0]"'\n')
file.write("Result=1"'\n')
file.write("["+uninstallkey+"-SdAskDestPath-0]"'\n')
file.write("szDir=C:\Program Files\Index Education\Pronote 2018\Réseau"'\n')
file.write("Result=1"'\n')
file.write("["+uninstallkey+"-AskOptions-0]"'\n')
file.write("Result=1"'\n')
file.write("Sel-0=1"'\n')
file.write("Sel-1=0"'\n')
file.write("Sel-2=0"'\n')
file.write("Sel-3=0"'\n')
file.write("["+uninstallkey+"-AskOptions-1]"'\n')
file.write("Result=1"'\n')
file.write("Sel-0=1"'\n')
file.write("["+uninstallkey+"-SdFinish-0]"'\n')
file.write("Result=1"'\n')
file.write("bOpt1=0"'\n')
file.write("bOpt2=0")
file.close()
#print('"'+'pronote_'+year+'_'+archi+'.exe"-s -f1'+unattend_install) ##control
print('installing pronote-2018')
os.system('"pronote_'+year+'_'+archi+'.exe" -s -f1'+unattend_install)
def remove():
uninstall()