Exemplo n.º 1
0
def generate(license, fullname, year, email, project):
    """Generate the specified license."""
    response = send_request(
        'https://api.github.com/licenses/{0}'.format(license))

    try:
        license_template = response.json()['body']
    except KeyError:
        raise click.ClickException("Invalid license name, use `license show` "
                                   "to get the all available licenses.")

    if license not in LICENSE_WITH_CONTEXT:
        echo(license_template, nl=False)
    else:
        context_variable = re.findall(r'\[(\w+)\]', response.json()['body'])
        raw_context = {'fullname': fullname, 'year': year, 'email': email,
                       'project': project}
        user_context = {key: value for (key, value) in raw_context.items()
                        if value is not None}
        context = get_default_context()
        context.update(user_context)
        for item in context_variable:
            license_template = license_template.replace('[{0}]'.format(item),
                                                        context[item])
        echo(license_template, nl=False)
Exemplo n.º 2
0
def generate(license, fullname, year, email, project):
    """Generate the specified license."""
    response = send_request(
        'https://api.github.com/licenses/{0}'.format(license))

    try:
        license_template = response.json()['body']
    except KeyError:
        raise click.ClickException("Invalid license name, use `license show` "
                                   "to get the all available licenses.")

    if license not in LICENSE_WITH_CONTEXT:
        echo(license_template, nl=False)
    else:
        context_variable = re.findall(r'\[(\w+)\]', response.json()['body'])
        raw_context = {
            'fullname': fullname,
            'year': year,
            'email': email,
            'project': project
        }
        user_context = {
            key: value
            for (key, value) in raw_context.items() if value is not None
        }
        context = get_default_context()
        context.update(user_context)
        for item in context_variable:
            license_template = license_template.replace(
                '[{0}]'.format(item), context[item])
        echo(license_template, nl=False)
Exemplo n.º 3
0
    def test_generate_license(self, runner):
        all_the_licenses = [
            'agpl-3.0', 'apache-2.0', 'artistic-2.0', 'bsd-2-clause',
            'bsd-3-clause', 'cc0-1.0', 'epl-1.0', 'gpl-2.0', 'gpl-3.0', 'isc',
            'lgpl-2.1', 'lgpl-3.0', 'mit', 'mpl-2.0', 'unlicense'
        ]

        all_the_licences_upper_cased = [
            licence.upper() for licence in all_the_licenses
        ]

        for license in all_the_licenses + all_the_licences_upper_cased:
            result = runner.invoke(generate, [license])
            output, exit_code = result.output, result.exit_code
            assert exit_code == 0

            if license not in LICENSE_WITH_CONTEXT:
                pass

            else:
                defaults = get_default_context()

                if license.lower() in ['mit', 'artistic-2.0', 'bsd-2-clause']:
                    assert defaults['fullname'] in output
                    assert defaults['year'] in output

                if license.lower() == 'isc':
                    assert defaults['fullname'] in output
                    assert defaults['year'] in output
                    assert defaults['email'] in output

                if license.lower() == 'bsd-3-clause':
                    assert defaults['fullname'] in output
                    assert defaults['year'] in output
                    assert defaults['project'] in output
Exemplo n.º 4
0
    def test_generate_license(self, runner):
        all_the_licenses = (
            'agpl-3.0, apache-2.0, artistic-2.0, bsd-2-clause, '
            'bsd-3-clause, cc0-1.0, epl-1.0, gpl-2.0, gpl-3.0, '
            'isc, lgpl-2.1, lgpl-3.0, mit, mpl-2.0, unlicense')
        for license in all_the_licenses.split(', '):
            result = runner.invoke(generate, [license])
            output, exit_code = result.output, result.exit_code
            assert exit_code == 0

            if license not in LICENSE_WITH_CONTEXT:
                pass

            else:
                defaults = get_default_context()

                if license in ['mit', 'artistic-2.0', 'bsd-2-clause']:
                    assert defaults['fullname'] in output
                    assert defaults['year'] in output

                if license == 'isc':
                    assert defaults['fullname'] in output
                    assert defaults['year'] in output
                    assert defaults['email'] in output

                if license == 'bsd-3-clause':
                    assert defaults['fullname'] in output
                    assert defaults['year'] in output
                    assert defaults['project'] in output
Exemplo n.º 5
0
    def test_generate_license(self, runner):
        all_the_licenses = (
            'agpl-3.0, apache-2.0, artistic-2.0, bsd-2-clause, '
            'bsd-3-clause, cc0-1.0, epl-1.0, gpl-2.0, gpl-3.0, '
            'isc, lgpl-2.1, lgpl-3.0, mit, mpl-2.0, unlicense')
        for license in all_the_licenses.split(', '):
            result = runner.invoke(generate, [license])
            output, exit_code = result.output, result.exit_code
            assert exit_code == 0

            if license not in LICENSE_WITH_CONTEXT:
                pass

            else:
                defaults = get_default_context()

                if license in ['mit', 'artistic-2.0', 'bsd-2-clause']:
                    assert defaults['fullname'] in output
                    assert defaults['year'] in output

                if license == 'isc':
                    assert defaults['fullname'] in output
                    assert defaults['year'] in output
                    assert defaults['email'] in output

                if license == 'bsd-3-clause':
                    assert defaults['fullname'] in output
                    assert defaults['year'] in output
                    assert defaults['project'] in output
Exemplo n.º 6
0
def context(license):
    """Show the default context for the license."""
    if license not in LICENSE_WITH_CONTEXT:
        echo("Just use it, there's no context for the license.")
    else:
        response = send_request(
            'https://api.github.com/licenses/{0}'.format(license))
        context = re.findall(r'\[(\w+)\]', response.json()['body'])
        default_context = get_default_context()
        echo('The template has following defaults:')
        for item in context:
            echo('\t{0}: {1}'.format(item, default_context[item]))
        echo('You can overwrite them at your ease.')
Exemplo n.º 7
0
def context(license):
    """Show the default context for the license."""
    if license not in LICENSE_WITH_CONTEXT:
        echo("Just use it, there's no context for the license.")
    else:
        response = send_request(
            'https://api.github.com/licenses/{0}'.format(license))
        context = re.findall(r'\[(\w+)\]', response.json()['body'])
        default_context = get_default_context()
        echo('The template has following defaults:')
        for item in context:
            echo('\t{0}: {1}'.format(item, default_context[item]))
        echo('You can overwrite them at your ease.')
Exemplo n.º 8
0
    def test_show_license_context(self, runner):
        all_the_licenses = (
            'agpl-3.0, apache-2.0, artistic-2.0, bsd-2-clause, '
            'bsd-3-clause, cc0-1.0, epl-1.0, gpl-2.0, gpl-3.0, '
            'isc, lgpl-2.1, lgpl-3.0, mit, mpl-2.0, unlicense')
        for license in all_the_licenses.split(', '):
            result = runner.invoke(context, [license])
            output, exit_code = result.output, result.exit_code
            assert exit_code == 0
            if license not in LICENSE_WITH_CONTEXT:
                assert output == ("Just use it, there's no context "
                                  "for the license.\n")
            else:
                defaults = get_default_context()

                if license in ['mit', 'artistic-2.0', 'bsd-2-clause']:
                    assert output == (
                        "The template has following defaults:\n"
                        "\tyear: {0}\n"
                        "\tfullname: {1}\n"
                        "You can overwrite them at your ease.\n").format(
                            defaults['year'], defaults['fullname'])

                if license == 'isc':
                    assert output == (
                        "The template has following defaults:\n"
                        "\tyear: {0}\n"
                        "\tfullname: {1}\n"
                        "\temail: {2}\n"
                        "You can overwrite them at your ease.\n").format(
                            defaults['year'], defaults['fullname'],
                            defaults['email'])

                if license == 'bsd-3-clause':
                    assert output == (
                        "The template has following defaults:\n"
                        "\tyear: {0}\n"
                        "\tfullname: {1}\n"
                        "\tproject: {2}\n"
                        "You can overwrite them at your ease.\n").format(
                            defaults['year'], defaults['fullname'],
                            defaults['project'])
Exemplo n.º 9
0
    def test_show_license_context(self, runner):
        all_the_licenses = ('agpl-3.0, apache-2.0, bsd-2-clause, '
                            'bsd-3-clause, epl-2.0, gpl-2.0, gpl-3.0, '
                            'lgpl-2.1, lgpl-3.0, mit, mpl-2.0, unlicense')
        for license in all_the_licenses.split(', '):
            result = runner.invoke(context, [license])
            output, exit_code = result.output, result.exit_code
            assert exit_code == 0
            if license not in LICENSE_WITH_CONTEXT:
                assert output == ("Just use it, there's no context "
                                  "for the license.\n")
            else:
                defaults = get_default_context()

                if license in ['mit', 'artistic-2.0', 'bsd-2-clause']:
                    assert output == (
                        "The template has following defaults:\n"
                        "\tyear: {0}\n"
                        "\tfullname: {1}\n"
                        "You can overwrite them at your ease.\n").format(
                            defaults['year'], defaults['fullname'])

                if license == 'isc':
                    assert output == (
                        "The template has following defaults:\n"
                        "\tyear: {0}\n"
                        "\tfullname: {1}\n"
                        "\temail: {2}\n"
                        "You can overwrite them at your ease.\n").format(
                            defaults['year'], defaults['fullname'],
                            defaults['email'])

                if license == 'bsd-3-clause':
                    assert output == (
                        "The template has following defaults:\n"
                        "\tyear: {0}\n"
                        "\tfullname: {1}\n"
                        "You can overwrite them at your ease.\n").format(
                            defaults['year'], defaults['fullname'])
Exemplo n.º 10
0
    def test_show_license_context(self, runner):
        all_the_licenses = ('agpl-3.0, apache-2.0, bsd-2-clause, '
                            'bsd-3-clause, epl-2.0, gpl-2.0, gpl-3.0, '
                            'lgpl-2.1, lgpl-3.0, mit, mpl-2.0, unlicense')
        for license in all_the_licenses.split(', '):
            result = runner.invoke(context, [license])
            output, exit_code = result.output, result.exit_code
            assert exit_code == 0
            if license not in LICENSE_WITH_CONTEXT:
                assert output == ("Just use it, there's no context "
                                  "for the license.\n")
            else:
                defaults = get_default_context()

                if license in [
                        'mit', 'artistic-2.0', 'bsd-2-clause', 'bsd-3-clause'
                ]:
                    assert output == context_template.format(
                        defaults['year'], defaults['fullname'])

                if license == 'isc':
                    assert output == context_with_email_template.format(
                        defaults['year'], defaults['fullname'],
                        defaults['email'])