def check_if_version_up_to_date() -> VersionCheckResult: """Checks if there is a newer Rotkehlchen version available for download If there is a remote query error return only our version. If there is no newer version for download returns only our current version and latest version. If yes returns (our_version_str, latest_version_str, download_url) """ our_version_str = get_system_spec()['rotkehlchen'] our_version = parse_version(our_version_str) github = Github() try: latest_version_str, url = github.get_latest_release() except RemoteError: # Completely ignore all remote errors. If Github has problems we just don't check now return VersionCheckResult(our_version=our_version_str) latest_version = parse_version(latest_version_str) if latest_version <= our_version: return VersionCheckResult(our_version=our_version_str, latest_version=latest_version_str) return VersionCheckResult( our_version=our_version_str, latest_version=latest_version_str, download_url=url, )
def get_current_version(check_for_updates: bool) -> VersionCheckResult: """Get current version of rotki. If check_for_updates is set to true it also checks if a new version is available. If there is a remote query error return only our version. If there is no newer version for download returns only our current version and latest version. If yes returns (our_version_str, latest_version_str, download_url) """ our_version_str = get_system_spec()['rotkehlchen'] if check_for_updates: our_version = parse_version(our_version_str) github = Github() try: latest_version_str, url = github.get_latest_release() except RemoteError: # Completely ignore all remote errors. If Github has problems we just don't check now return VersionCheckResult(our_version=our_version_str) latest_version = parse_version(latest_version_str) if latest_version <= our_version: return VersionCheckResult( our_version=our_version_str, latest_version=latest_version_str, ) return VersionCheckResult( our_version=our_version_str, latest_version=latest_version_str, download_url=url, ) return VersionCheckResult(our_version=our_version_str)
def test_query_version_when_update_required(rotkehlchen_api_server): """Test that endpoint to query version works when a new version is available""" rotki = rotkehlchen_api_server.rest_api.rotkehlchen def patched_get_latest_release(_klass): new_latest = 'v99.99.99' return new_latest, f'https://github.com/rotki/rotki/releases/tag/{new_latest}' release_patch = patch( 'rotkehlchen.externalapis.github.Github.get_latest_release', patched_get_latest_release, ) with release_patch: response = requests.get( api_url_for( rotkehlchen_api_server, 'inforesource', ), ) result = assert_proper_response_with_result(response) our_version = get_system_spec()['rotkehlchen'] assert result == { 'version': { 'our_version': our_version, 'latest_version': 'v99.99.99', 'download_url': 'https://github.com/rotki/rotki/releases/tag/v99.99.99', }, 'data_directory': str(rotki.data_dir), }
def test_query_version_when_update_required(rotkehlchen_api_server): """Test that endpoint to query version works when a new version is available""" def patched_get_latest_release(_klass): new_latest = 'v99.99.99' return new_latest, f'https://github.com/rotki/rotki/releases/tag/{new_latest}' release_patch = patch( 'rotkehlchen.externalapis.github.Github.get_latest_release', patched_get_latest_release, ) with release_patch: response = requests.get( api_url_for( rotkehlchen_api_server, "versionresource", ), ) assert_proper_response(response) our_version = get_system_spec()['rotkehlchen'] data = response.json() assert data['message'] == '' assert len(data['result']) == 3 assert data['result']['our_version'] == our_version assert data['result']['latest_version'] == 'v99.99.99' assert 'v99.99.99' in data['result']['download_url']
def __call__(self, parser, namespace, values, option_string=None): # Only command we have at the moment is version if values != 'version': parser.print_usage() print(f'Unrecognized command: {values}.') sys.exit(0) print(get_system_spec()['rotkehlchen']) sys.exit(0)
def test_create_usage_analytics(): analytics = create_usage_analytics() assert 'system_os' in analytics assert 'system_release' in analytics assert 'system_version' in analytics assert analytics['rotki_version'] == get_system_spec()['rotkehlchen'] assert analytics['country'] != 'unknown' assert analytics['city'] != 'unknown'
def test_create_usage_analytics(data_dir): analytics = create_usage_analytics(data_dir) assert 'system_os' in analytics assert 'system_release' in analytics assert 'system_version' in analytics assert analytics['rotki_version'] == get_system_spec()['rotkehlchen'] if sys.platform != 'darwin': assert analytics['city'] == 'unknown' else: assert analytics['country'] is not None assert analytics['city'] is not None
def __call__( self, parser: argparse.ArgumentParser, namespace: argparse.Namespace, values: Union[str, Sequence[Any], None], option_string: str = None, ) -> None: # Only command we have at the moment is version if values != 'version': parser.print_usage() print(f'Unrecognized command: {values}.') sys.exit(0) print(get_system_spec()['rotkehlchen']) sys.exit(0)
def create_usage_analytics() -> Dict[str, Any]: analytics = dict() analytics['system_os'] = platform.system() analytics['system_release'] = platform.release() analytics['system_version'] = platform.version() analytics['rotki_version'] = get_system_spec()['rotkehlchen'] location_data = retrieve_location_data() if not location_data: location_data = GeolocationData('unknown', 'unknown') analytics['country'] = location_data.country_code analytics['city'] = location_data.city return analytics
def create_usage_analytics(data_dir: Path) -> Dict[str, Any]: analytics = {} analytics['system_os'] = platform.system() analytics['system_release'] = platform.release() analytics['system_version'] = platform.version() analytics['rotki_version'] = get_system_spec()['rotkehlchen'] location_data = retrieve_location_data(data_dir) if location_data is None: location_data = GeolocationData('unknown') analytics['country'] = location_data.country_code analytics['city'] = 'unknown' # deprecated -- we no longer use it return analytics
def test_query_version(rotkehlchen_api_server): """Test that endpoint to query the rotki version works fine""" # Test for the case that the version is up to date response = requests.get( api_url_for( rotkehlchen_api_server, "versionresource", ), ) assert_proper_response(response) our_version = get_system_spec()['rotkehlchen'] data = response.json() assert data['message'] == '' assert len(data['result']) == 3 assert data['result']['our_version'] == our_version cmd = ['git', 'describe', '--abbrev=0', '--tags'] expected_latest = subprocess.check_output(cmd, stderr=subprocess.STDOUT) expected_latest = expected_latest[:-1].decode() assert data['result']['latest_version'] == expected_latest assert data['result']['download_url'] is None # Test for the case that a newer version exists def patched_get_latest_release(_klass): new_latest = 'v99.99.99' return new_latest, f'https://github.com/rotki/rotki/releases/tag/{new_latest}' release_patch = patch( 'rotkehlchen.externalapis.github.Github.get_latest_release', patched_get_latest_release, ) with release_patch: response = requests.get( api_url_for( rotkehlchen_api_server, "versionresource", ), ) assert_proper_response(response) data = response.json() assert data['message'] == '' assert len(data['result']) == 3 assert data['result']['our_version'] == our_version assert data['result']['latest_version'] == 'v99.99.99' assert 'v99.99.99' in data['result']['download_url']
def check_if_version_up_to_date() -> Optional[Tuple[str, str, str]]: """Checks if there is a newer Rotkehlchen version available for download If not returns None If yes returns a tuple: (our_version_str, latest_version_str, url) """ our_version_str = get_system_spec()['rotkehlchen'] our_version = parse_version(our_version_str) github = Github() try: latest_version_str, url = github.get_latest_release() except RemoteError: # Completely ignore all remote errors. If Github has problems we just don't check now return None latest_version = parse_version(latest_version_str) if latest_version <= our_version: return None return our_version_str, latest_version_str, url
def __call__(self, parser, namespace, values, option_string=None): print(get_system_spec()['rotkehlchen']) sys.exit(0)