<commit_before>import click

from ckan.lib.cli import load_config, paster_click_group, click_config_option
from ckan.plugins.toolkit import get_action


xroad_commands = paster_click_group(
    summary=u'X-Road related commands'
)

@xroad_commands.command(
    u'update_xroad_organizations',
    help='Updates harvested organizations\' metadata'
)
@click_config_option
@click.pass_context
def update_xroad_organizations(ctx, config):
    load_config(config or ctx.obj['config'])
    get_action('update_xroad_organizations')({'ignore_auth': True}, {})


@xroad_commands.command(
    u'fetch_errors',
    help='Fetches error log from catalog lister'
)
@click_config_option
@click.pass_context
def fetch_errors(ctx, config):
    load_config((config or ctx.obj['config']))
    results = get_action('fetch_xroad_errors')({'ignore_auth': True}, {})

    if results.get("success") is True:
        for result in results.get('results', []):
            print(result['message'])

    else:
        print(results['message'])


@xroad_commands.command(
    u'fetch_stats',
    help='Fetches X-Road stats from catalog lister'
)
@click_config_option
@click.pass_context
@click.option(u'--days', type=int)
def fetch_stats(ctx, config, days):
    load_config((config or ctx.obj['config']))

    data_dict = {}
    if days:
        data_dict['days'] = days

    results = get_action('fetch_xroad_stats')({'ignore_auth': True}, data_dict)

    if results.get("success") is True:
            print(results['message'])

    else:
        print(results['message'])


@xroad_commands.command(
    u'fetch_service_list',
    help='Fetches X-Road services from catalog lister'
)
@click_config_option
@click.pass_context
@click.option(u'--days', type=int)
def fetch_service_list(ctx, config, days):
    load_config((config or ctx.obj['config']))

    data_dict = {}
    if days:
        data_dict['days'] = days

    results = get_action('fetch_xroad_service_list')({'ignore_auth': True}, data_dict)

    if results.get("success") is True:
            print(results['message'])

    else:
        print(results['message'])


@xroad_commands.command(
    u'init_db',
    help="Initializes databases for xroad"
)
@click_config_option
@click.pass_context
def init_db(ctx, config):
    load_config((config or ctx.obj['config']))<commit_msg>Fix fetch_service_list command error handling<commit_after>import click

from ckan.lib.cli import load_config, paster_click_group, click_config_option
from ckan.plugins.toolkit import get_action


xroad_commands = paster_click_group(
    summary=u'X-Road related commands'
)

@xroad_commands.command(
    u'update_xroad_organizations',
    help='Updates harvested organizations\' metadata'
)
@click_config_option
@click.pass_context
def update_xroad_organizations(ctx, config):
    load_config(config or ctx.obj['config'])
    get_action('update_xroad_organizations')({'ignore_auth': True}, {})


@xroad_commands.command(
    u'fetch_errors',
    help='Fetches error log from catalog lister'
)
@click_config_option
@click.pass_context
def fetch_errors(ctx, config):
    load_config((config or ctx.obj['config']))
    results = get_action('fetch_xroad_errors')({'ignore_auth': True}, {})

    if results.get("success") is True:
        for result in results.get('results', []):
            print(result['message'])

    else:
        print(results['message'])


@xroad_commands.command(
    u'fetch_stats',
    help='Fetches X-Road stats from catalog lister'
)
@click_config_option
@click.pass_context
@click.option(u'--days', type=int)
def fetch_stats(ctx, config, days):
    load_config((config or ctx.obj['config']))

    data_dict = {}
    if days:
        data_dict['days'] = days

    results = get_action('fetch_xroad_stats')({'ignore_auth': True}, data_dict)

    if results.get("success") is True:
            print(results['message'])

    else:
        print(results['message'])


@xroad_commands.command(
    u'fetch_service_list',
    help='Fetches X-Road services from catalog lister'
)
@click_config_option
@click.pass_context
@click.option(u'--days', type=int)
def fetch_service_list(ctx, config, days):
    load_config((config or ctx.obj['config']))

    data_dict = {}
    if days:
        data_dict['days'] = days

    results = get_action('fetch_xroad_service_list')({'ignore_auth': True}, data_dict)

    if results.get("success") is True:
            print(results['message'])

    else:
        print("Error fetching service list!")


@xroad_commands.command(
    u'init_db',
    help="Initializes databases for xroad"
)
@click_config_option
@click.pass_context
def init_db(ctx, config):
    load_config((config or ctx.obj['config']))
{'fraction_non_alphanumeric': 0.1321765209940017, 'fraction_numerical': 0.0, 'mean_word_length': 4.454439252336448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6949554', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1489, 'n_words': 300}