Files
AttribWinbiz/auto_update.py
Ambulance Clerc 32c8a5ca3f débug auto-update
2023-12-01 17:21:08 +01:00

48 lines
1.8 KiB
Python

from version import *
import urllib.request
import urllib.error
import ssl
import io
class auto_updater:
dl_version = 0
temp_dir = ""
def clean(self, str):
str = str.replace('/','')
str = str.replace(':', '')
str = str.replace('{', '')
str = str.replace('(', '')
str = str.replace("\\", '')
return str
def new_update_available(self):
ret = False
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
data = urllib.request.urlopen("https://gitea.prod.resk-u.ch/CLERC/AttribWinbiz/raw/branch/master/dl_version", context=ctx)
self.dl_version = str(data.read()).replace('b', '').replace("'", "").replace("\n","").replace('n',"")
ssl._create_default_https_context = ssl._create_unverified_context
if self.dl_version != VERSION:
print(f"Version différente trouvée {self.dl_version} téléchargement en cours => {self.temp_dir}clerc_update.exe")
try:
url = f"https://gitea.prod.resk-u.ch/CLERC/AttribWinbiz/releases/download/{self.clean(self.dl_version)}/Clercattrib2Biz_setup.exe"
urllib.request.urlretrieve(url=url, filename=f"{self.temp_dir}clerc_update.exe")
except urllib.error.URLError as e:
print(f"ERREUR de téléchargement mise à jour : {e.reason} \n {url}")
return "ERROR"
except urllib.error.HTTPError as e:
print(f"ERREUR HTTP lors du téléchargement : {e.code} {e.reason} \n {url}")
return "ERROR"
except Exception as e:
print(f"Erreur inattendue : {e} \n {url}")
return "ERROR"
ret = True
return ret