Пример #1
0
def print_sync_result(skipped, created, updated, errors):
    msg = SYNC_RESULT_OUTPUT

    errors_count = len(errors)
    processed = skipped + created + updated + errors_count
    row = '|{module}|{processed}|{created}|{updated}|{deleted}|{skipped}|{errors}|\n'
    msg += row.format(
        module='Customers Synchronizer',
        processed=processed,
        created=created,
        updated=updated,
        deleted=0,
        skipped=skipped,
        errors=errors_count,
    )
    click.echo(f'\n{render(msg)}\n', )
    if len(errors) > 0:
        msg = f'\nSync operation had {len(errors)} errors, do you want to see them?'
        fg = 'yellow'

        click.secho(msg, fg=fg)

        print_errors = continue_or_quit()

        if print_errors:
            for row_idx, messages in errors.items():
                click.echo(f'  Errors at row #{row_idx}')
                for msg in messages:
                    click.echo(f'    - {msg}')
                click.echo(' ')
Пример #2
0
def cmd_list_products(config, query, page_size, always_continue):
    acc_id = config.active.id
    acc_name = config.active.name
    if not config.silent:
        click.echo(
            click.style(
                f'Current active account: {acc_id} - {acc_name}\n',
                fg='blue',
            ), )
    client = ConnectClient(
        api_key=config.active.api_key,
        endpoint=config.active.endpoint,
        use_specs=False,
        max_retries=3,
    )

    if acc_id.startswith('VA'):
        default_query = R().visibility.owner.eq(True) & R().version.null(True)
    else:
        default_query = R().visibility.listing.eq(
            True) | R().visibility.syndication.eq(True)

    query = query or default_query
    paging = 0
    query_products = client.products.filter(query).limit(page_size)

    for prod in query_products:
        paging += 1
        click.echo(f"{prod['id']} - {prod['name']}", )
        if paging % page_size == 0 and paging != query_products.count(
        ) and not always_continue:
            if not continue_or_quit():
                return
Пример #3
0
def print_results(  # noqa: CCR001
        silent,
        product_id,
        results_tracker,
):
    if not silent:
        msg = f'''
# Results of synchronizing {product_id}


| Module | Processed | Created | Updated | Deleted | Skipped | Errors |
|:--------|--------:| --------:|--------:|----------:|----------:|----------:|
        '''
        errors = 0
        for result in results_tracker:
            errors_count = len(result['errors'])
            errors += errors_count
            processed = result['skipped'] + result['created']
            processed += result['updated'] + result['deleted']
            processed += errors_count
            row = '|{module}|{processed}|{created}|{updated}|{deleted}|{skipped}|{errors}|\n'
            msg += row.format(
                module=result['module'],
                processed=processed,
                created=result['created'],
                updated=result['updated'],
                deleted=result['deleted'],
                skipped=result['skipped'],
                errors=errors_count,
            )
        click.echo(f'\n{render(msg)}\n', )

        if errors > 0:
            msg = f'\nSync operation had {errors} errors, do you want to see them?'
            fg = 'yellow'

            click.echo(click.style(msg, fg=fg))

            print_errors = continue_or_quit()

            if print_errors:
                for result in results_tracker:
                    if len(result['errors']) > 0:
                        click.echo(
                            click.style(f'\nModule {result["module"]}:\n',
                                        fg='magenta'), )
                        for row_idx, messages in result["errors"].items():
                            click.echo(f'  Errors at row #{row_idx}')
                            for msg in messages:
                                click.echo(f'    - {msg}')
                            click.echo(' ')
Пример #4
0
def cmd_list_translations(config, query, page_size, always_continue):
    acc_id = config.active.id
    acc_name = config.active.name
    if not config.silent:
        click.secho(
            f'Current active account: {acc_id} - {acc_name}\n',
            fg='blue',
        )
    client = ConnectClient(
        api_key=config.active.api_key,
        endpoint=config.active.endpoint,
        use_specs=False,
        max_retries=3,
        logger=RequestLogger() if config.verbose else None,
    )

    default_query = client.ns('localization').translations.all()
    query_translations = default_query.filter(
        query) if query else default_query

    translation_list = [TRANSLATION_TABLE_HEADER]
    count_of_translations = query_translations.count()

    for paging, resource in enumerate(query_translations, 1):
        owner = field_to_check_mark(acc_id == resource["owner"]["id"])
        primary = field_to_check_mark(resource["primary"])
        row = row_format_resource(
            resource["id"],
            resource["context"]["instance_id"],
            resource["context"]["type"],
            resource["context"]["name"],
            resource["locale"]["name"],
            resource["auto"]["status"],
            resource["status"],
            primary,
            owner,
        )
        translation_list.append(row)
        table_formater_resource(translation_list, count_of_translations,
                                paging, page_size)
        if paging % page_size == 0 and paging != count_of_translations and not always_continue:
            if not continue_or_quit():
                return
Пример #5
0
    def print_errors(self):  # noqa: CCR001
        total_error_count = sum(
            len(module_stats._errors) + len(module_stats._row_errors)
            for module_stats in self.values())
        if total_error_count == 0:
            return
        click.secho(
            f'\n{self.operation} operation had {total_error_count} errors, do you want to see them?',
            fg='yellow',
        )
        if not continue_or_quit():
            return  # pragma: no cover

        click.echo('')
        for module_stats in filter(lambda ms: ms._errors or ms._row_errors,
                                   self.values()):
            click.secho(f'Module {module_stats.name}:\n', fg='magenta')

            if module_stats._errors:
                click.echo('  Errors')
                click.echo("\n".join(f'    - {msg}'
                                     for msg in module_stats._errors))
                click.echo('')

            # group rows with same error message to avoid long prints in bulk errors
            first_row = None
            current_error = None
            for row_idx, messages in module_stats._row_errors.items():
                error = "\n".join(f'    - {msg}' for msg in messages)
                if not first_row:
                    first_row = row_idx
                if not current_error:
                    current_error = error
                if error != current_error:
                    self._print_error(current_error, first_row, row_idx - 1)
                    current_error = error
                    first_row = row_idx
            if current_error:
                self._print_error(current_error, first_row, row_idx)
Пример #6
0
def cmd_list_locales(config, query, page_size, always_continue):
    acc_id = config.active.id
    acc_name = config.active.name
    if not config.silent:
        click.secho(
            f'Current active account: {acc_id} - {acc_name}\n',
            fg='blue',
        )
    client = ConnectClient(
        api_key=config.active.api_key,
        endpoint=config.active.endpoint,
        use_specs=False,
        max_retries=3,
        logger=RequestLogger() if config.verbose else None,
    )

    default_query = client.ns('localization').locales.all()
    query_locales = default_query.filter(query) if query else default_query

    locales_list = [LOCALES_TABLE_HEADER]
    count_of_locales = query_locales.count()

    for paging, resource in enumerate(query_locales, 1):
        auto = field_to_check_mark(resource["auto_translation"],
                                   false_value='\u2716')
        translations_count = resource["stats"]["translations"] or '-'
        row = row_format_resource(resource["id"], resource["name"], auto,
                                  translations_count)
        locales_list.append(row)
        table_formater_resource(
            locales_list,
            count_of_locales,
            paging,
            page_size,
        )
        if paging % page_size == 0 and paging != count_of_locales and not always_continue:
            if not continue_or_quit():
                return
Пример #7
0
def test_continue_or_quit_c(mocker):
    mocker.patch('connect.cli.core.utils.click.echo')
    mocker.patch('connect.cli.core.utils.click.getchar', return_value='c')
    assert utils.continue_or_quit() is True
Пример #8
0
def test_continue_or_quit_invalid_plus_q(mocker):
    mocker.patch('connect.cli.core.utils.click.echo')
    mocker.patch('connect.cli.core.utils.click.getchar',
                 side_effect=['z', 'q'])
    assert utils.continue_or_quit() is False