mirror of
https://gitlab.os-k.eu/neox/CNIRevelator.git
synced 2023-08-25 14:03:10 +02:00
Update now works !
This commit is contained in:
parent
cf17c07a2a
commit
7a388c3efe
@ -33,10 +33,7 @@ import launcher # launcher.py
|
||||
import ihm # ihm.py
|
||||
import logger # logger.py
|
||||
import updater # updater.py
|
||||
|
||||
## Global Handlers
|
||||
logfile = logger.logCur
|
||||
launcherWindow = ihm.launcherWindowCur
|
||||
import globs # globs.py
|
||||
|
||||
## MAIN FUNCTION OF CNIREVELATOR
|
||||
def main():
|
||||
@ -66,11 +63,23 @@ try:
|
||||
launcherThread = threading.Thread(target=updater.umain, daemon=False)
|
||||
launcher.lmain(launcherThread)
|
||||
except Exception:
|
||||
logfile.printerr("A FATAL ERROR OCCURED : " + str(traceback.format_exc()))
|
||||
sys.exit(1)
|
||||
|
||||
updater.UPDATE_IS_MADE = True
|
||||
|
||||
if updater.UPDATE_IS_MADE:
|
||||
# Launch app !
|
||||
args = updater.UPATH + '\\CNIRevelator.exe ' + globs.CNIRFolder
|
||||
cd = updater.UPATH
|
||||
for i in range(0,3):
|
||||
try:
|
||||
updater.spawnProcess(args, cd)
|
||||
except:
|
||||
time.sleep(3)
|
||||
continue
|
||||
break
|
||||
sys.exit(0)
|
||||
|
||||
main()
|
||||
|
||||
sys.exit(0)
|
||||
|
@ -81,7 +81,7 @@ class newcredentials:
|
||||
try:
|
||||
sessionAnswer = session.get('https://www.google.com')
|
||||
except Exception as e:
|
||||
logfile.printerr('Network Error : ' + str(e))
|
||||
logfile.printdbg('Network Error : ' + str(e))
|
||||
sessionAnswer = ''
|
||||
|
||||
logfile.printdbg("Session Answer : " + str(sessionAnswer))
|
||||
@ -183,9 +183,7 @@ class newdownload:
|
||||
|
||||
reducedFilename = filename.split("\\")[-1]
|
||||
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('Downloading {}'.format(reducedFilename)))
|
||||
launcherWindow.progressBar.stop()
|
||||
launcherWindow.progressBar.configure(mode='determinate', value=0, maximum=100)
|
||||
launcherWindow.printmsg('Downloading {}'.format(reducedFilename))
|
||||
|
||||
try:
|
||||
os.remove(filename)
|
||||
@ -199,8 +197,9 @@ class newdownload:
|
||||
self.count = os.path.getsize(self.destinationFile)
|
||||
Percent = int(self.count / self.filesize * 100)
|
||||
|
||||
launcherWindow.progressBar.configure(mode='determinate', value=(int(Percent)))
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('Downloading {}'.format(reducedFilename) + ' : ' + str((Percent)) + ' %'))
|
||||
launcherWindow.progressBar.stop()
|
||||
launcherWindow.progressBar.configure(mode='determinate', value=(int(Percent)), maximum=100)
|
||||
launcherWindow.printmsg('Downloading {}'.format(reducedFilename) + ' : ' + str((Percent)) + ' %')
|
||||
|
||||
launcherWindow.progressBar.configure(mode='indeterminate', value=0, maximum=20)
|
||||
launcherWindow.progressBar.start()
|
||||
|
@ -111,6 +111,9 @@ class LauncherWindow(Tk):
|
||||
|
||||
self.update()
|
||||
|
||||
def printmsg(self, msg):
|
||||
self.mainCanvas.itemconfigure(self.msg, text=(msg))
|
||||
|
||||
class AutoScrollbar(ttk.Scrollbar):
|
||||
|
||||
def set(self, lo, hi):
|
||||
|
@ -33,19 +33,18 @@ import ihm # ihm.py
|
||||
import globs # globs.py
|
||||
import logger # logger.py
|
||||
|
||||
## Global Handlers
|
||||
## Main function
|
||||
def lmain(mainThread):
|
||||
logfile = logger.logCur
|
||||
launcherWindow = ihm.launcherWindowCur
|
||||
|
||||
## Main function
|
||||
def lmain(mainThread):
|
||||
# Hello world
|
||||
logfile.printdbg('*** CNIRLauncher LOGFILE. Hello World ! ***')
|
||||
#logfile.printdbg('Files in directory : ' + str(os.listdir(globs.CNIRFolder)))
|
||||
|
||||
# Hello user
|
||||
launcherWindow.progressBar.configure(mode='indeterminate', value=0, maximum=20)
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text='Starting...')
|
||||
launcherWindow.printmsg('Starting...')
|
||||
launcherWindow.progressBar.start()
|
||||
|
||||
# Starting the main update thread
|
||||
@ -54,4 +53,5 @@ def lmain(mainThread):
|
||||
launcherWindow.mainloop()
|
||||
|
||||
logfile.printdbg('*** CNIRLauncher LOGFILE. Goodbye World ! ***')
|
||||
logfile.close()
|
||||
return
|
||||
|
@ -61,5 +61,8 @@ class NewLoggingSystem:
|
||||
self.printerr = logger.error
|
||||
self.printdbg = logger.info
|
||||
|
||||
def close(self):
|
||||
logging.shutdown()
|
||||
|
||||
## Global Handler
|
||||
logCur = NewLoggingSystem()
|
||||
|
@ -24,7 +24,6 @@
|
||||
"""
|
||||
|
||||
from win32com.client import Dispatch
|
||||
import subprocess
|
||||
import traceback
|
||||
import sys
|
||||
import time
|
||||
@ -32,6 +31,7 @@ import os
|
||||
import shutil
|
||||
import zipfile
|
||||
import hashlib
|
||||
import subprocess
|
||||
|
||||
import logger # logger.py
|
||||
import globs # globs.py
|
||||
@ -39,6 +39,7 @@ import ihm # ihm.py
|
||||
import downloader # downloader.py
|
||||
|
||||
UPDATE_IS_MADE = False
|
||||
UPATH = ' '
|
||||
|
||||
def createShortcut(path, target='', wDir='', icon=''):
|
||||
ext = path[-3:]
|
||||
@ -58,6 +59,9 @@ def createShortcut(path, target='', wDir='', icon=''):
|
||||
shortcut.IconLocation = icon
|
||||
shortcut.save()
|
||||
|
||||
def spawnProcess(args, cd):
|
||||
subprocess.Popen(args, close_fds=True, cwd=cd, creationflags=subprocess.DETACHED_PROCESS)
|
||||
|
||||
## Main Batch Function
|
||||
def batch():
|
||||
|
||||
@ -133,7 +137,7 @@ def batch():
|
||||
|
||||
getTheUpdate = downloader.newdownload(credentials, finalurl, globs.CNIRFolder + '\\..\\CNIPackage.zip').download()
|
||||
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('Verifying download...'))
|
||||
launcherWindow.printmsg('Verifying download...')
|
||||
|
||||
BUF_SIZE = 65536 # lets read stuff in 64kb chunks!
|
||||
|
||||
@ -153,18 +157,23 @@ def batch():
|
||||
logfile.printerr("Checksum error")
|
||||
return False
|
||||
|
||||
# And now unzip
|
||||
# And now prepare install
|
||||
global UPATH
|
||||
UPATH = globs.CNIRFolder + '\\..\\CNIRevelator' + "{}.{}.{}".format(finalver[0], finalver[1], finalver[2])
|
||||
logfile.printdbg("Make place")
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('Preparing installation...'))
|
||||
launcherWindow.printmsg('Preparing installation...')
|
||||
# Cleanup
|
||||
try:
|
||||
shutil.rmtree(UPATH + 'temp')
|
||||
except Exception as e:
|
||||
logfile.printdbg('Unable to cleanup : ' +str(e))
|
||||
try:
|
||||
shutil.rmtree(UPATH)
|
||||
except:
|
||||
pass
|
||||
|
||||
except Exception as e:
|
||||
logfile.printdbg('Unable to cleanup : ' +str(e))
|
||||
# Unzip
|
||||
logfile.printdbg("Unzipping the package")
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('Installing the updates'))
|
||||
launcherWindow.printmsg('Installing the updates')
|
||||
zip_ref = zipfile.ZipFile(globs.CNIRFolder + '\\..\\CNIPackage.zip', 'r')
|
||||
zip_ref.extractall(UPATH + "temp")
|
||||
zip_ref.close()
|
||||
@ -175,62 +184,62 @@ def batch():
|
||||
|
||||
logfile.printdbg('Extracted :' + UPATH + '\\CNIRevelator.exe')
|
||||
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('Success !'))
|
||||
launcherWindow.printmsg('Success !')
|
||||
|
||||
# Cleanup
|
||||
try:
|
||||
os.remove(globs.CNIRFolder + '\\..\\CNIPackage.zip')
|
||||
except:
|
||||
pass
|
||||
# Launch app !
|
||||
args = [UPATH + '\\CNIRevelator.exe', globs.CNIRFolder]
|
||||
subprocess.Popen(args)
|
||||
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('Launched the new process.'))
|
||||
|
||||
# Time to quit
|
||||
launcherWindow.printmsg('Launched the new process.')
|
||||
global UPDATE_IS_MADE
|
||||
UPDATE_IS_MADE = True
|
||||
return True
|
||||
|
||||
## Main Function
|
||||
def umain():
|
||||
|
||||
# Global Handlers
|
||||
logfile = logger.logCur
|
||||
launcherWindow = ihm.launcherWindowCur
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
launcherWindow.printmsg('Deleting old version !')
|
||||
logfile.printdbg("Old install detected : {}".format(sys.argv[1]))
|
||||
while os.path.exists(str(sys.argv[1])):
|
||||
try:
|
||||
shutil.rmtree(str(sys.argv[1]), ignore_errors=True)
|
||||
shutil.rmtree(str(sys.argv[1]))
|
||||
except:
|
||||
pass
|
||||
logfile.printdbg("Fail to delete old install !")
|
||||
|
||||
|
||||
try:
|
||||
# Global Handlers
|
||||
logfile = logger.logCur
|
||||
launcherWindow = ihm.launcherWindowCur
|
||||
|
||||
try:
|
||||
# EXECUTING THE UPDATE BATCH
|
||||
success = batch()
|
||||
except Exception as e:
|
||||
logfile.printerr("An error occured on the thread : " + str(traceback.format_exc()))
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('ERROR : ' + str(e)))
|
||||
launcherWindow.printmsg('ERROR : ' + str(e))
|
||||
time.sleep(3)
|
||||
launcherWindow.destroy()
|
||||
return 1
|
||||
|
||||
if success:
|
||||
logfile.printdbg("Software is up-to-date !")
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text='Software is up-to-date !')
|
||||
launcherWindow.printmsg('Software is up-to-date !')
|
||||
else:
|
||||
logfile.printerr("An error occured. No effective update !")
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text='An error occured. No effective update !')
|
||||
launcherWindow.printmsg('An error occured. No effective update !')
|
||||
time.sleep(2)
|
||||
launcherWindow = ihm.launcherWindowCur
|
||||
launcherWindow.destroy()
|
||||
return 0
|
||||
|
||||
except:
|
||||
logfile.printerr("A FATAL ERROR OCCURED : " + str(traceback.format_exc()))
|
||||
launcherWindow = ihm.launcherWindowCur
|
||||
launcherWindow.destroy()
|
||||
sys.exit(2)
|
||||
return 2
|
||||
|
Loading…
Reference in New Issue
Block a user