1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| from urllib.request import urlopen, urlretrieve
import os
import threading
from tkinter.ttk import Progressbar
from pyunpack import Archive
import winshell
from win32com.client import Dispatch
from tkinter import *
def createShortCut():
desktop = winshell.desktop()
path = os.path.join(desktop, "Toto.lnk")
target = fullPath+"\\"+lastMAJ+".exe"
wDir = fullPath
icon = fullPath+"\\"+lastMAJ+".exe"
shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WorkingDirectory = wDir
shortcut.IconLocation = icon
shortcut.save()
def download():
print("Téléchargement en cours")
urlretrieve(linkMAJ, chemin+"\\"+lastMAJ+".zip")
print("Extract en cours")
Archive(chemin+"\\"+lastMAJ+".zip").extractall(chemin)
os.remove(chemin+"\\"+lastMAJ+".zip")
print("Trying to launch new version")
os.startfile(fullPath+"\\"+lastMAJ+".exe")
try:
createShortCut()
except:
print("Bug à la MAJ des raccourcis")
oExit()
def oExit():
o.destroy()
if online:
if fullPath != "INACESSIBLE":
if not os.path.exists(fullPath):
print('Mise à jour disponible')
down_thread = threading.Thread(target=download)
down_thread.start()
o = Toplevel()
o.overrideredirect(True)
o.configure(width=200)
x = (o.winfo_screenwidth()*0.85 - o.winfo_reqwidth())/2
y = o.winfo_reqheight()
o.geometry("+%d+%d" % (x, y))
lbl = Label(o, text="Mise à jour du logiciel")
lbl.grid(row=0, column=0, sticky=W+E)
bar = Progressbar(o, orient='horizontal', mode='determinate', value=0, maximum=sizeMAJ)
bar.grid(row=1, column=0, sticky=W+E)
threading.Thread(target=getSizeOfDown).start()
OK = Button(o, overrelief=GROOVE, text ='OK', command=oExit)
OK.grid(row=2)
#bar.start(1)
o.mainloop() |
Partager