def check_version(server, version, filename, timeout=SHORT_TIMEOUT):
    """Check for the latest version of OK and update accordingly."""

    address = VERSION_ENDPOINT.format(server=server)

    print('Checking for software updates...')
    log.info('Existing OK version: %s', version)
    log.info('Checking latest version from %s', address)

    try:
        request = urllib.request.Request(address)
        response = urllib.request.urlopen(request, timeout=timeout)
    except (urllib.error.HTTPError, urllib.error.URLError, socket_error) as e:
        print('Network error when checking for updates.')
        log.warning('Network error when checking version from %s: %s', address,
                    str(e), stack_info=True)
        return False

    response_json = json.loads(response.read().decode('utf-8'))
    if not _validate_api_response(response_json):
        print('Error while checking updates: malformed server response')
        log.info('Malformed response from %s: %s', address,
                 json.dumps(response_json))
        return False

    current_version = response_json['data']['results'][0]['current_version']
    if current_version == version:
        print('OK is up to date')
        return True

    download_link = response_json['data']['results'][0]['current_download_link']
    log.info('Downloading version %s from %s', current_version, download_link)

    try:
        request = urllib.request.Request(download_link)
        response = urllib.request.urlopen(request, timeout=timeout)
    except (urllib.error.HTTPError, urllib.error.URLError, socket_error) as e:
        print('Error when downloading new version of OK')
        log.warning('Error when downloading new version of OK: %s', str(e),
                    stack_info=True)
        return False

    log.info('Writing new version to %s', filename)

    zip_binary = response.read()
    try:
        _write_zip(filename, zip_binary)
    except __HOLE__ as e:
        print('Error when downloading new version of OK')
        log.warning('Error writing to %s: %s', filename, str(e))
        return False
    else:
        print('Updated to version: {}'.format(current_version))
        log.info('Successfully wrote to %s', filename)
        return True
dataset/ETHPy150Open Cal-CS-61A-Staff/ok-client/client/utils/software_update.py/check_version