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