mirror of
https://github.com/frappe/bench.git
synced 2024-11-12 00:06:36 +00:00
Merge pull request #960 from gavindsouza/check-for-updates
feat: check for newer versions on PyPI
This commit is contained in:
commit
8a5e7e9ec9
@ -1,6 +1,7 @@
|
||||
import atexit
|
||||
import click
|
||||
import os, sys, logging, json, pwd, subprocess
|
||||
from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe, log, is_dist_editable, find_parent_bench
|
||||
from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe, log, is_dist_editable, find_parent_bench, check_latest_version
|
||||
from bench.app import get_apps
|
||||
from bench.config.common_site_config import get_config
|
||||
from bench.commands import bench_command
|
||||
@ -41,7 +42,7 @@ def cli():
|
||||
|
||||
else:
|
||||
try:
|
||||
# NOTE: this is the main bench command
|
||||
atexit.register(check_latest_version)
|
||||
bench_command()
|
||||
except PatchError:
|
||||
sys.exit(1)
|
||||
|
@ -1,3 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# imports - standard imports
|
||||
import errno
|
||||
import glob
|
||||
@ -21,6 +24,7 @@ from distutils.spawn import find_executable
|
||||
# imports - third party imports
|
||||
import click
|
||||
import requests
|
||||
from semantic_version import Version
|
||||
from six import iteritems
|
||||
from six.moves.urllib.parse import urlparse
|
||||
|
||||
@ -80,6 +84,23 @@ def safe_decode(string, encoding = 'utf-8'):
|
||||
return string
|
||||
|
||||
|
||||
def check_latest_version():
|
||||
try:
|
||||
pypi_request = requests.get("https://pypi.org/pypi/frappe-bench/json")
|
||||
except Exception:
|
||||
# Exceptions thrown are defined in requests.exceptions
|
||||
# ignore checking on all Exceptions
|
||||
return
|
||||
|
||||
if pypi_request.status_code == 200:
|
||||
pypi_version_str = pypi_request.json().get('info').get('version')
|
||||
pypi_version = Version(pypi_version_str)
|
||||
local_version = Version(bench.__version__)
|
||||
|
||||
if pypi_version > local_version:
|
||||
log("A newer version of bench is available: {0} → {1}".format(local_version, pypi_version))
|
||||
|
||||
|
||||
def get_frappe(bench_path='.'):
|
||||
frappe = get_env_cmd('frappe', bench_path=bench_path)
|
||||
if not os.path.exists(frappe):
|
||||
|
Loading…
Reference in New Issue
Block a user