Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto update func #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 38 additions & 2 deletions control_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@
__author__ = 'Kazuyuki TAKASE'
__copyright__ = 'PLEN Project Company, and all authors.'
__license__ = 'The MIT License'

__version__ = '2.4.1'

import os
import sys
import imp
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.
# =============================================================================
Expand Down Expand Up @@ -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()
Expand Down