def check_cli_version(): """ Check if the current cli version satisfies the server requirements """ server_version = VersionClient().get_cli_version() current_version = get_cli_version() if LooseVersion(current_version) < LooseVersion( server_version.min_version): print(""" Your version of CLI (%s) is no longer compatible with server.""" % current_version) if click.confirm('Do you want to upgrade to version %s now?' % server_version.latest_version): upgrade() sys.exit(0) else: print("""Your can manually run: pip install -U floyd-cli (or if you prefer to use conda): conda install -y -c conda-forge -c floydhub floyd-cli to upgrade to the latest version (%s)""" % server_version.latest_version) sys.exit(0) elif LooseVersion(current_version) < LooseVersion( server_version.latest_version): print(""" New version of CLI (%s) is now available. To upgrade run: pip install -U floyd-cli Or if you prefer to use conda: conda install -y -c conda-forge -c floydhub floyd-cli """ % server_version.latest_version)
def request(self, method, url, params=None, data=None, files=None, json=None, timeout=5, headers=None, skip_auth=False): """ Execute the request using requests library """ request_url = self.base_url + url floyd_logger.debug( "Starting request to url: %s with params: %s, data: %s", request_url, params, data) request_headers = {'x-floydhub-cli-version': get_cli_version()} # Auth headers if access_token is present if self.access_token: request_headers[ "Authorization"] = "Bearer " + self.access_token.token # Add any additional headers if headers: request_headers.update(headers) try: response = requests.request(method, request_url, params=params, data=data, json=json, headers=request_headers, files=files, timeout=timeout) except requests.exceptions.ConnectionError as exception: floyd_logger.debug("Exception: %s", exception, exc_info=True) sys.exit( "Cannot connect to the Floyd server. Check your internet connection." ) except requests.exceptions.Timeout as exception: floyd_logger.debug("Exception: %s", exception, exc_info=True) sys.exit( "Connection to FloydHub server timed out. Please retry or check your internet connection." ) floyd_logger.debug("Response Content: %s, Headers: %s" % (response.content, response.headers)) self.check_response_status(response) return response
def cli(host, verbose): """ Floyd CLI interacts with FloydHub server and executes your commands. More help is available under each command listed below. """ import raven raven.Client( dsn='https://*****:*****@sentry.io/226940', release=get_cli_version(), environment='prod', processors=('raven.processors.SanitizePasswordsProcessor',)) floyd.floyd_host = host configure_logger(verbose) check_cli_version()
def check_cli_version(): """ Check if the current cli version satisfies the server requirements """ should_exit = False server_version = VersionClient().get_cli_version() current_version = get_cli_version() if LooseVersion(current_version) < LooseVersion( server_version.min_version): print( "\nYour version of CLI (%s) is no longer compatible with server." % current_version) should_exit = True elif LooseVersion(current_version) < LooseVersion( server_version.latest_version): print("\nNew version of CLI (%s) is now available." % server_version.latest_version) else: return # new version is ready if should_exit and click.confirm( '\nDo you want to upgrade to version %s now?' % server_version.latest_version): auto_upgrade() sys.exit(0) else: msg_parts = [] msg_parts.append("\nTo manually upgrade run:") msg_parts.append(" pip install -U floyd-cli") if is_conda_env(): msg_parts.append("Or if you prefer to use conda:") msg_parts.append( " conda install -y -c conda-forge -c floydhub floyd-cli") print("\n".join(msg_parts)) print("") if should_exit: sys.exit(0)
def check_cli_version(): """ Check if the current cli version satisfies the server requirements """ server_version = VersionClient().get_cli_version() current_version = get_cli_version() if LooseVersion(current_version) < LooseVersion(server_version.min_version): print(""" Your version of CLI (%s) is no longer compatible with server.""" % current_version) if click.confirm('Do you want to upgrade to version %s now?' % server_version.latest_version): from floyd.cli.version import pip_upgrade pip_upgrade() sys.exit(0) else: print("""Your can manually run: pip install -U floyd-cli to upgrade to the latest version (%s))""" % server_version.latest_version) sys.exit(0) elif LooseVersion(current_version) < LooseVersion(server_version.latest_version): print(""" New version of CLI (%s) is now available. To upgrade run: pip install -U floyd-cli """ % server_version.latest_version)