def releases(dist_name): """ This is the /pypi/releases/<dist_name> entry point, it is the interface between Stallion and the PyPI RPC service when checking for updates. :param dist_name: the package name (distribution name). """ pkg_res = get_pkg_res() data = {} pkg_dist_version = pkg_res.get_distribution(dist_name).version pypi_rel = get_pypi_releases(dist_name) data["dist_name"] = dist_name data["pypi_info"] = pypi_rel data["current_version"] = pkg_dist_version if pypi_rel: pypi_last_version = pkg_res.parse_version(pypi_rel[0]) current_version = pkg_res.parse_version(pkg_dist_version) last_version = pkg_dist_version.lower() != pypi_rel[0].lower() data["last_is_great"] = pypi_last_version > current_version data["last_version_differ"] = last_version if data["last_is_great"]: DIST_PYPI_CACHE.add(dist_name.lower()) else: try: DIST_PYPI_CACHE.remove(dist_name.lower()) except KeyError: pass return render_template('pypi_update.html', **data)
def check_pypi_update(dist_name): """ Just check for updates and return a json with the attribute "has_update". :param dist_name: distribution name :rtype: json :return: json with the attribute "has_update" """ pkg_res = get_pkg_res() pkg_dist_version = pkg_res.get_distribution(dist_name).version pypi_rel = get_pypi_releases(dist_name) if pypi_rel: pypi_last_version = pkg_res.parse_version(pypi_rel[0]) current_version = pkg_res.parse_version(pkg_dist_version) if pypi_last_version > current_version: DIST_PYPI_CACHE.add(dist_name.lower()) return jsonify({"has_update": 1}) try: DIST_PYPI_CACHE.remove(dist_name.lower()) except KeyError: pass return jsonify({"has_update": 0})
def cmd_check(args): proj_name = args['<project_name>'] cmd_show(args, short=True) print print Fore.GREEN + Style.BRIGHT + 'Searching for updates on PyPI...' print pkg_dist_version = get_pkg_res().get_distribution(proj_name).version pypi_rel = get_pypi_releases(proj_name) if pypi_rel: pypi_last_version = get_pkg_res().parse_version(pypi_rel[0]) current_version = get_pkg_res().parse_version(pkg_dist_version) try: version_index = pypi_rel.index(pkg_dist_version) except: version_index = len(pypi_rel) for version in pypi_rel[0:version_index+3]: print Fore.WHITE + Style.BRIGHT + ' Version %s' % version, if version==pypi_rel[0]: print Fore.BLUE + Style.BRIGHT + '[last version]', if version==pkg_dist_version: print Fore.GREEN + Style.BRIGHT + '[your version]', print print if pypi_last_version > current_version: print Fore.RED + Style.BRIGHT + \ ' Your version is outdated, you\'re using ' + \ Fore.WHITE + Style.BRIGHT + 'v.%s,' % pkg_dist_version + \ Fore.RED + Style.BRIGHT + \ ' but the last version is ' + Fore.WHITE + Style.BRIGHT + \ 'v.%s !' % pypi_rel[0] if pypi_last_version == current_version: print Fore.GREEN + Style.BRIGHT + ' Your version is updated !' if pypi_last_version < current_version: print Fore.YELLOW + Style.BRIGHT + \ ' Your version newer than the version available at PyPI !' print Fore.YELLOW + Style.BRIGHT + ' You\'re using ' + \ Fore.WHITE + Style.BRIGHT + 'v.%s,' % pkg_dist_version + \ Fore.YELLOW + Style.BRIGHT + \ ' but the last version in PyPI ' + Fore.WHITE + Style.BRIGHT + \ 'v.%s !' % pypi_rel[0] else: print 'No versions found on PyPI !'