<commit_before>#!/usr/bin/env python

"""Copy a snippet (in its latest version) from one site to another.

:Copyright: 2006-2021 <NAME>
:License: Revised BSD (see `LICENSE` file for details)
"""

import click

from byceps.services.snippet import service as snippet_service
from byceps.services.snippet.transfer.models import Scope, SnippetType
from byceps.util.system import get_config_filename_from_env_or_exit

from _util import app_context
from _validators import validate_site


@click.command()
@click.pass_context
@click.argument('source_site', callback=validate_site)
@click.argument('target_site', callback=validate_site)
@click.argument('snippet_names', nargs=-1, required=True)
def execute(ctx, source_site, target_site, snippet_names):
    source_scope = Scope.for_site(source_site.id)
    target_scope = Scope.for_site(target_site.id)

    snippet_versions = [
        get_snippet_version(source_scope, name) for name in snippet_names
    ]

    for snippet_version in snippet_versions:
        copy_snippet(target_scope, snippet_version)

    click.secho('Done.', fg='green')


def get_snippet_version(source_scope, snippet_name):
    snippet_version = snippet_service.find_current_version_of_snippet_with_name(
        source_scope, snippet_name
    )

    if snippet_version is None:
        raise click.BadParameter(
            f'Snippet "{snippet_name}" not found '
            f'in scope "{scope_as_string(source_scope)}".'
        )

    return snippet_version


def copy_snippet(target_scope, snippet_version):
    snippet_type = snippet_version.snippet.type_

    if snippet_type == SnippetType.document:
        pass#create_document(target_scope, snippet_version)
    elif snippet_type == SnippetType.fragment:
        pass#create_fragment(target_scope, snippet_version)
    else:
        ctx.fail(f"Unknown snippet type '{snippet_type}'.")

    click.secho(
        f'Copied snippet "{snippet_version.snippet.name}" '
        f'to scope "{scope_as_string(target_scope)}".',
        fg='green',
    )

<commit_msg>Remove debug code that prevents snippet copying<commit_after>#!/usr/bin/env python

"""Copy a snippet (in its latest version) from one site to another.

:Copyright: 2006-2021 <NAME>
:License: Revised BSD (see `LICENSE` file for details)
"""

import click

from byceps.services.snippet import service as snippet_service
from byceps.services.snippet.transfer.models import Scope, SnippetType
from byceps.util.system import get_config_filename_from_env_or_exit

from _util import app_context
from _validators import validate_site


@click.command()
@click.pass_context
@click.argument('source_site', callback=validate_site)
@click.argument('target_site', callback=validate_site)
@click.argument('snippet_names', nargs=-1, required=True)
def execute(ctx, source_site, target_site, snippet_names):
    source_scope = Scope.for_site(source_site.id)
    target_scope = Scope.for_site(target_site.id)

    snippet_versions = [
        get_snippet_version(source_scope, name) for name in snippet_names
    ]

    for snippet_version in snippet_versions:
        copy_snippet(target_scope, snippet_version)

    click.secho('Done.', fg='green')


def get_snippet_version(source_scope, snippet_name):
    snippet_version = snippet_service.find_current_version_of_snippet_with_name(
        source_scope, snippet_name
    )

    if snippet_version is None:
        raise click.BadParameter(
            f'Snippet "{snippet_name}" not found '
            f'in scope "{scope_as_string(source_scope)}".'
        )

    return snippet_version


def copy_snippet(target_scope, snippet_version):
    snippet_type = snippet_version.snippet.type_

    if snippet_type == SnippetType.document:
        create_document(target_scope, snippet_version)
    elif snippet_type == SnippetType.fragment:
        create_fragment(target_scope, snippet_version)
    else:
        ctx.fail(f"Unknown snippet type '{snippet_type}'.")

    click.secho(
        f'Copied snippet "{snippet_version.snippet.name}" '
        f'to scope "{scope_as_string(target_scope)}".',
        fg='green',
    )


{'fraction_non_alphanumeric': 0.09370424597364568, 'fraction_numerical': 0.004392386530014641, 'mean_word_length': 4.3302990897269185, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '779855', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1249, 'n_words': 272}