Skip to content

Commit

Permalink
version update check and updater, untested.
Browse files Browse the repository at this point in the history
  • Loading branch information
den4uk committed Dec 16, 2019
1 parent ff81844 commit 93218b8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions andriller/adb_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ def adb(self, cmd, binary=False, su=False, **kwargs) -> str:
return self.unstrip(run.stdout)
return run.stdout.decode().strip()

def adb_iter(self, cmd):
@staticmethod
def cmditer(cmd):
process = subprocess.Popen(
[self.adb_bin] + shlex.split(cmd),
shlex.split(cmd),
shell=False,
startupinfo=startupinfo,
stdout=subprocess.PIPE)
Expand Down
22 changes: 22 additions & 0 deletions andriller/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import logging
import pathlib
import datetime
import requests
import configparser
from contextlib import suppress
from appdirs import AppDirs
from . import utils
from . import statics
Expand Down Expand Up @@ -34,6 +36,7 @@ def __init__(self):
self.tzone = None
self.date_format = None
self.setup_tz()
self.update_available = False

def __call__(self, key):
return self.conf[self.NS][key]
Expand Down Expand Up @@ -102,3 +105,22 @@ def default_user_config(cls):
@property
def is_mac(self):
return self.OS == 'darwin'

@utils.threaded
def check_latest_version(self, logger=logger):
url = f'https://pypi.org/pypi/{__package_name__}/json'
with suppress(Exception):
response = requests.get(url)
if response.ok and response.headers.get('Content-Type') == 'application/json':
latest = max(response.json()['releases'])
logger.debug(f'Fetched latest version from PYPI: {latest}')
if utils.totupe(__version__) < utils.totupe(latest):
logger.warning(f' ** Update available: {latest} **')
self.update_available = True

@utils.threaded
def upgrade_package(self, package=__package_name__, logger=logger):
from .adb_conn import ADBConn
cmd = f'{sys.executable} -m pip install {package} -U'
for line in ADBConn.cmditer(cmd):
logger.info(line)
3 changes: 3 additions & 0 deletions andriller/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def __init__(self, **kwargs):
logger.info(f"Detected/PC time: {self.time_now_local}")
logger.info(f"Universal time: {self.time_now_utc}")
logger.info(f"Time in reports: {self.time_now_configured} <--") # \u2190
self.conf.check_latest_version(logger=self.logger)

# Setup ADB
# def setup_adb(self):
Expand Down Expand Up @@ -378,6 +379,8 @@ def build_help_menus(self):
self.menubar.add_cascade(menu=menu_help, label='Help', underline=0)
menu_help.add_command(label='Visit website')
menu_help.add_separator()
menu_help.add_command(label='Run Update', command=lambda: self.conf.upgrade_package(logger=self.logger))
menu_help.add_separator()
menu_help.add_command(label='About', command=self.about_msg)

def build_adb_menus(self):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Jinja2==2.10.3
timeout-decorator==0.4.1
appdirs==1.4.3
dataclasses
requests==2.22.0

0 comments on commit 93218b8

Please sign in to comment.