From 52398eb1ebfcd0895ba54aa12110bb0265ab14e5 Mon Sep 17 00:00:00 2001 From: Tatsuroh Sakaguchi Date: Sun, 7 May 2017 22:27:29 +0900 Subject: [PATCH] update latest version app when start up --- README.md | 1 + control_server/main.py | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1d34587..870840e 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ If you would like to use the application as a tuning up tool, Please [see also.. - pyserial 3.0.1 - py2exe 0.6.9 - py2app 0.7.3 +- requests 2.14.2 ### GUI - Visual Studio Express 2013 for Web diff --git a/control_server/main.py b/control_server/main.py index daf946e..74ea35b 100644 --- a/control_server/main.py +++ b/control_server/main.py @@ -8,7 +8,7 @@ __author__ = 'Kazuyuki TAKASE' __copyright__ = 'PLEN Project Company, and all authors.' __license__ = 'The MIT License' - +__version__ = '2.4.1' import os import sys @@ -16,8 +16,18 @@ import json import logging import drivers +import subprocess +import platform +import zipfile +import glob +import shutil +import StringIO +import time from router.router import (set_driver, server_worker) +from distutils.version import LooseVersion, StrictVersion +from collections import OrderedDict +import requests # Create module level instances. # ============================================================================= @@ -58,7 +68,33 @@ def bootstrap(): ''' @brief Bootstrap script for the application. ''' - + + installed_dir = os.path.abspath("../../../../../../../")+"/" + latest_page = requests.get("https://api.github.com/repos/plenprojectcompany/plen-ControlServer/releases/latest", verify=False) + latest_page_json = latest_page.json(object_pairs_hook=OrderedDict) + ver = latest_page_json["tag_name"][1:] + if LooseVersion(__version__) != LooseVersion(ver): + try: + if platform.system() == 'Darwin': + latest_data = requests.get(latest_page_json["assets"][0]["browser_download_url"], stream=True, verify=False) + else: + latest_data = requests.get(latest_page_json["assets"][1]["browser_download_url"], stream=True, verify=False) + os.rename(installed_dir+"ControlServer_OSX_v"+__version__, installed_dir+"tmp") + latest_zip = zipfile.ZipFile(StringIO.StringIO(latest_data.content)) + latest_zip.extractall(installed_dir) + if platform.system() == 'Darwin': + executed = subprocess.call("open "+installed_dir+"ControlServer_OSX_v"+ver+"/ControlServer.app", shell=True) + else: + executed = subprocess.call(installed_dir+"ControlServer_Win_v"+ver+"/ControlServer.exe") + except: + print("update failed") + if platform.system() == 'Darwin': + os.rename(installed_dir+"tmp",installed_dir+"ControlServer_OSX_v"+__version__) + else: + os.rename(installed_dir+"tmp",installed_dir+"ControlServer_Win_v"+__version__) + else: + shutil.rmtree(installed_dir+"tmp") + sys.exit() # Initialize logging settings. # ========================================================================= init_logger()