def start(message): global spinner if config.has_option('settings', 'non_interactive') and config.get('settings', 'non_interactive') is True: print(message) else: spinner = _new_spinner() spinner.start(message)
def _get_import_action(file_name): file_name = file_name.rstrip('.gz') file_name = file_name.rstrip('.zip') for file_type, action in _IMPORT_ACTIONS.items(): if file_name.endswith(file_type): return action return config.get('settings', 'import_action')
def raise_if_non_interactive(message: str): if config.is_loaded() and config.get('settings', 'non_interactive'): raise McmdError( 'User input required but running in non-interactive mode. Message: {}' .format(message), info= "Please specify your command more precisely or switch to interactive mode with 'mcmd " "config set interactive'")
def test_ping_online(capsys): exit_code = run_commander('ping') assert exit_code == 1 captured = capsys.readouterr().out assert 'Online' in captured assert 'Version' in captured assert config.get('host', 'selected') in captured assert config.username() in captured
def succeed(): global spinner if spinner: if config.has_option('settings', 'unicorn_mode') and config.get('settings', 'unicorn_mode'): spinner.stop_and_persist(symbol='🦄'.encode('utf-8')) else: spinner.succeed() spinner = None
def config_set_host(args): if args.url: url = args.url else: auths = config.get('host', 'auth') urls = [auth['url'] for auth in auths] url = ask.multi_choice('Please select a host:', urls) io.start("Switching to host {}".format(highlight(url))) config.set_host(url)
def _get_version(): try: response = requests.get(urljoin(config.get('host', 'selected'), 'api/v2/version'), headers={'Content-Type': 'application/json'}) response.raise_for_status() global _version global _version_number _version = response.json()['molgenisVersion'] _version_number = _extract_version_number(_version) except HTTPError as e: raise McmdError(str(e)) except requests.exceptions.ConnectionError: raise MolgenisOfflineError()
def ping(args): host = config.get('host', 'selected') user = config.username() status = Fore.LIGHTGREEN_EX + 'Online' + Fore.RESET try: version = get_version() except McmdError: status = Fore.LIGHTRED_EX + 'Offline' + Fore.RESET version = None print(' Host: ' + highlight(host)) print(' Status: ' + status) if version: print('Version: ' + highlight(version)) print(' User: ' + highlight(user))
def _do_import(file_path, package): io.start('Importing %s' % (highlight(file_path.name))) params = { 'action': _get_import_action(file_path.name), 'metadataAction': 'upsert' } if package: params['packageId'] = package response = post_file(config.api('import'), file_path.resolve(), params) import_run_url = urljoin(config.get('host', 'selected'), response.text) status, message = _poll_for_completion(import_run_url) if status == 'FAILED': raise McmdError(message)
def _do_import(file_path, package, entity_type_id, import_action): io.start('Importing %s' % (highlight(file_path.name))) if import_action: action = import_action else: action = _get_import_action(file_path.name) params = {'action': action, 'metadataAction': 'upsert'} if package: params['packageId'] = package if entity_type_id: params['entityTypeId'] = entity_type_id response = post_file(api.import_(), file_path.resolve(), params) import_run_url = urljoin(config.get('host', 'selected'), response.text) status, message = _poll_for_completion(import_run_url) if status == 'FAILED': raise McmdError(message)
def _import_from_url(args): file_url = args.resource file_name = file_url.split("/")[-1] io.start('Importing from URL %s' % highlight(file_url)) params = { 'action': _get_import_action(file_name), 'metadataAction': 'upsert' } if args.to_package: params['packageId'] = args.to_package params['url'] = file_url response = import_by_url(params) import_run_url = urljoin(config.get('host', 'selected'), response.text) status, message = _poll_for_completion(import_run_url) if status == 'FAILED': raise McmdError(message)
def wrapper(*args, **kwargs): return urljoin(config.get('host', 'selected'), quote(func(*args, **kwargs)))
def get_resource_folders(self) -> List[Path]: return [ Path(folder) for folder in config.get('resources', 'resource_folders') ]
def _get_dataset_folders(): return [ Path(folder) for folder in config.get('resources', 'dataset_folders') ]
def _get_import_action(file_name): if '.owl' in file_name or '.obo' in file_name: return 'add' else: return config.get('settings', 'import_action')