(args, cli_version)
Check if the CLI has updates available

    Check the cache file first. If the cache is old enough, check updates
    through the pip interface. The cache file can be verified very quickly,
    whereas the verification through pip can be rather slow.

    Args:
        args        : Arguments from parent argument parser
        cli_version : Current version of the CLI
Check if the CLI has updates available
Check if the CLI has updates available
def check_cli_updates(args, cli_version):
    """Check if the CLI has updates available

    Check the cache file first. If the cache is old enough, check updates
    through the pip interface. The cache file can be verified very quickly,
    whereas the verification through pip can be rather slow.

    Args:
        args        : Arguments from parent argument parser
        cli_version : Current version of the CLI

    """

    # If pip is not available, assume the CLI was not installed via pip
    if (not which("pip3")):
        logger.debug("pip3 unavailable")
        return

    # Create the configuration directory if it does not exist
    if not os.path.exists(args.cfg_dir):
        os.makedirs(args.cfg_dir, exist_ok=True)

    # Check the update cache file first
    update_cache = UpdateCache(args.cfg_dir)

    # If the cache file says there is an update available, check whether the
    # current version is already the updated one. If not, recommend the update.
    if (update_cache.has_update()):
        if (update_cache.new_version() > StrictVersion(cli_version)):
            # Not updated yet. Recommend it.
            update_cache.recommend_update()
        else:
            # Already updated. Clear the update flag.
            update_cache.save()
        return

    # If the last update verification was still recent (less than a day ago),
    # do not check pip. Avoid the unnecessary spawning of the pip-checking
    # thread.
    if (update_cache.data):
        time_since_last_check = (datetime.now() - update_cache.last_check())
        if (time_since_last_check < timedelta(days=1)):
            logger.debug(
                "Last update check was less than a day ago: {}".format(
                    str(time_since_last_check)))
            return

    # Check pip updates on a thread. This verification can be slow, so it is
    # better not to block.
    t = threading.Thread(target=_check_pip_updates,
                         args=(args.cfg_dir, cli_version))
    t.start()
def check_cli_updates ( args , cli_version ) : # If pip is not available, assume the CLI was not installed via pip if ( not which ( "pip3" ) ) : logger . debug ( "pip3 unavailable" ) return # Create the configuration directory if it does not exist if not os . path . exists ( args . cfg_dir ) : os . makedirs ( args . cfg_dir , exist_ok = True ) # Check the update cache file first update_cache = UpdateCache ( args . cfg_dir ) # If the cache file says there is an update available, check whether the # current version is already the updated one. If not, recommend the update. if ( update_cache . has_update ( ) ) : if ( update_cache . new_version ( ) > StrictVersion ( cli_version ) ) : # Not updated yet. Recommend it. update_cache . recommend_update ( ) else : # Already updated. Clear the update flag. update_cache . save ( ) return # If the last update verification was still recent (less than a day ago), # do not check pip. Avoid the unnecessary spawning of the pip-checking # thread. if ( update_cache . data ) : time_since_last_check = ( datetime . now ( ) - update_cache . last_check ( ) ) if ( time_since_last_check < timedelta ( days = 1 ) ) : logger . debug ( "Last update check was less than a day ago: {}" . format ( str ( time_since_last_check ) ) ) return # Check pip updates on a thread. This verification can be slow, so it is # better not to block. t = threading . Thread ( target = _check_pip_updates , args = ( args . cfg_dir , cli_version ) ) t . start ( )