コード例 #1
0
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)
コード例 #2
0
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')
コード例 #3
0
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'")
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
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)
コード例 #7
0
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()
コード例 #8
0
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))
コード例 #9
0
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)
コード例 #10
0
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)
コード例 #11
0
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)
コード例 #12
0
 def wrapper(*args, **kwargs):
     return urljoin(config.get('host', 'selected'),
                    quote(func(*args, **kwargs)))
コード例 #13
0
 def get_resource_folders(self) -> List[Path]:
     return [
         Path(folder)
         for folder in config.get('resources', 'resource_folders')
     ]
コード例 #14
0
def _get_dataset_folders():
    return [
        Path(folder) for folder in config.get('resources', 'dataset_folders')
    ]
コード例 #15
0
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')