olivier.massot před 8 roky
rodič
revize
8d785552be
5 změnil soubory, kde provedl 33 přidání a 17 odebrání
  1. 1 1
      VERSION
  2. 7 3
      main.py
  3. binární
      setup-hello_world.exe
  4. 3 2
      setup.iss
  5. 22 11
      updater.py

+ 1 - 1
VERSION

@@ -1 +1 @@
-0.1.0
+1.0

+ 7 - 3
main.py

@@ -1,6 +1,6 @@
 """
 
-    [App documentaion here]
+    [App documentation here]
 
     @author:[author], [year]
 """
@@ -11,9 +11,9 @@ from PyQt5.Qt import QApplication
 from PyQt5.QtWidgets import QMessageBox
 
 from ui.window import MainWindow
+from updater import UpdateNeeded
 import updater
 
-
 try:
     # Necessary to ensure that stacktraces are printed when using PyQt5
     # Tough, could make pythonw.exe crash
@@ -25,7 +25,11 @@ except:
 with open("VERSION") as f:
     __VERSION__ = f.read()
 
-updater.autoupdate()
+try:
+    updater.autoupdate()
+except UpdateNeeded:
+    print("Veuillez patienter pendant la mise à jour automatique")
+    sys.exit(0)
 
 # Configure how errors are processed
 sys_err = sys.excepthook

binární
setup-hello_world.exe


+ 3 - 2
setup.iss

@@ -22,7 +22,7 @@
 #define AppURL "http://codebox/lab/Python_3-6-1"
 
 ; Install diretory
-#define AppLocation "{tmp}"
+#define AppLocation "{%temp}"
 
 ; Python version required
 #define PythonVersion "3.6-32"
@@ -77,7 +77,7 @@ var
   sPythonWExecPath: String;
 
 // Return the directory containing the python executable
-function UpdatePythonDir(): String;
+procedure UpdatePythonDir();
 var
   Dirname: String;
 begin
@@ -128,6 +128,7 @@ begin
         MsgBox('Python 3.6 - Une erreur s''est produite lors de l''installation des librairies' + #13#10 + '[' + SysErrorMessage(ExitCode) + ']', mbError, MB_OK);
         Exit;     
       end
+    Log('Installed in ' + ExpandConstant('{app}'))
     end
   end       
 end;

+ 22 - 11
updater.py

@@ -9,11 +9,14 @@ import tempfile
 
 import requests
 
-VERSIONFILE_URL = "http://codebox/lab/ModelePython/raw/VERSION"
-SETUPFILE_URL = "http://codebox/lab/ModelePython/raw/setup-hello_world.exe"
+VERSIONFILE_URL = "http://codebox/lab/ModelePython/raw/master/VERSION"
+SETUPFILE_URL = "http://codebox/lab/ModelePython/raw/master/setup-hello_world.exe"
 
 CURDIR = os.path.dirname(__file__)
 
+TMPDIR = os.path.join(tempfile.gettempdir(), os.path.basename(CURDIR), "update")
+TMP_SETUPFILE = os.path.join(TMPDIR, "setup.exe")
+
 class UpdateNeeded(Exception):
     pass
 
@@ -21,12 +24,19 @@ class Unavailable(requests.exceptions.RequestException):
     pass
 
 def autoupdate():
+    clean_old()
     try:
         if update_needed():
             update()
     except Unavailable:
         pass
 
+def clean_old():
+    try:
+        os.rmdir(TMPDIR)
+    except:
+        pass
+
 def update_needed():
     # Available version
     try:
@@ -42,19 +52,20 @@ def update_needed():
     return available_version > installed_version
 
 def update():
-    with tempfile.TemporaryDirectory() as tmpdir:
 
-        # Download the setup.exe
-        response = requests.get(SETUPFILE_URL, stream=True)
+    # Download the setup.exe
+    response = requests.get(SETUPFILE_URL, stream=True)
 
-        with open("setup.exe", "wb") as handle:
-            for data in response.iter_content():
-                handle.write(data)
+    os.mkdir(TMPDIR)
+    with open(TMP_SETUPFILE, "wb") as handle:
+        for chunk in response.iter_content(chunk_size=1024):
+            if chunk:
+                handle.write(chunk)
 
-        # Run the installer and restart the start command
-        args = "/SILENT && {}".format(tmpdir / "setup.exe", " ".join(sys.argv[:]))
+    # Run the installer and restart the start command
+    args = "/SILENT && {}".format(" ".join(sys.argv[:]))
 
-        Popen([os.path.join(tmpdir, "setup.exe"), args], shell=True)
+    Popen([TMP_SETUPFILE, args], shell=True)
 
     # An UpdateNeeded exception is raised so the script exit before being restarted by subprocess
     raise UpdateNeeded()