I just created a package update function for ParaView (https://www.paraview.org/)
I've been sweating a bit, so if this can be useful for "Lutizing" it.
The update is based on the "non-MPI" 64-bit version (see: https://learn.microsoft.com/en-us/messa ... rosoft-mpi)
As always, it's not super clean, but it works
I deliberately renamed the MSI file after downloading it because if the Python version changed in the binary, that would have needed to be managed as well. As for the shortcut, I had to create it manually because the silent MSI doesn't generate it.
Facility
Code: Select all
# -*- coding: utf-8 -*-
from setuphelpers import *
def install():
app_path = makepath(programfiles,"Paraview %s\\bin" % control.get_software_version())
msi = "ParaView-%s.msi" % control.get_software_version()
install_msi_if_needed(msi)
create_programs_menu_shortcut('Paraview', target="%s\\paraview.exe" % app_path)
pass
Code: Select all
# -*- coding: utf-8 -*-
from setuphelpers import *
def update_package():
import requests
import re
from bs4 import BeautifulSoup
from packaging.version import Version, parse
from datetime import date
import html.parser
# Stockage de la version actuelle
ancienne_version = control.get_software_version()
#URL de base des téléchargements
url = "https://www.paraview.org/files/"
#RegEx du format de la version
regex = r"v[0-9]*"
#Requete pour récupérer le contenu de la page de téléchargement et récupération de la version la plus récente
site = requests.get(url)
HTML = site.text
soup = BeautifulSoup(HTML,'html.parser')
table = soup.find('table')
trs = table.find_all('tr')
version_courte = "0.0"
for tr in trs:
tds = tr.find_all('td')
for td in tds:
if re.match(regex, td.text):
if Version(td.text[1:-1]) > Version(version_courte):
last = 1
elif Version(td.text[1:-1]) < Version(version_courte):
last = -1
else:
last = 0
if last == 1:
version_courte = td.text[1:-1]
#Contruction de l'URL de téléchargement apres avoir trouvé la dernière version
constructed_url = "https://www.paraview.org/files/v%s" % version_courte
#Requete pour récupérer le contenu de la page de téléchargement et récupérer le dernier fichier MSI (NON MPI)
site2 = requests.get(constructed_url)
HTML2 = site2.text
soup2 = BeautifulSoup(HTML2,'html.parser')
table2 = soup2.find('table')
trsb = table2.find_all('tr')
previousDate = "1970-01-01"
for trb in trsb[3:-1]:
tdsb = trb.find_all('td')
if tdsb[1].find('a').text.endswith('.msi') == True and not "MPI" in tdsb[1].find('a').text:
#Date
date = tdsb[2].text.split(" ")[0]
if previousDate < date:
lastDate = date
previousDate = date
print(tdsb[1].find('a').text)
latest_bin = tdsb[1].find('a').text
else:
print(date)
tdsb[1].find('a').text
previousDate = date
version_complete = latest_bin.split("-")[1]
ancien_fichier = 'ParaView-%s.msi' % ancienne_version
#Comparaison de la dernière version avec celle du paquet
if Version(version_complete) > Version(control.get_software_version()):
package_updated=True
print("Downloading: %s" % latest_bin)
wget("%s/%s" % (constructed_url,latest_bin),"ParaView-%s.msi" % version_complete)
print("Software version updated (from: %s to: %s)" % (control.get_software_version(), Version(version_complete)))
# Suppression de l'ancien binaire
if isfile(ancien_fichier):
os.remove(ancien_fichier)
control.set_software_version(version_complete)
control.save_control_to_wapt()
else:
package_updated=False
print("Binary is present: %s" % ancien_fichier)
#On retourne True ou False pour que la console sache si elle doit update le paquet
return package_updated
pass
Vianney
