コード例 #1
0
def main():
    if args.scan:
        if len(args.args) < 1:
            sys.stderr.write(
                '  First parameter is missing: the nick on GitHub\n')
            sys.stderr.write(
                '  Second optional parameter: name of report file\n')
            sys.exit(1)

        repo_provider = repobase.get_provider(args.provider)
        user = repo_provider(args.args[0])
        if len(args.args) < 2:
            report_file = open(args.args[0] + '-gh-license-report', 'w')
            print(' No report file name found, using default "' +
                  args.args[0] + '-gh-license-report" instead!')
        else:
            report_file = open(args.args[1], 'w')
        report_file.write('Last scan done on: ' + time.strftime("%c") + "\n")
        report_file.write('Scan report of user: '******'LICENSE.txt', 'license', 'LICENSE', 'license.txt',
                'license.md', 'LICENSE.md'
            ]
            repo_url = repo.repo_url
            progressBar(count_current, count_total)
            for license_file in license_files:
                missing = True
                try:
                    urllib.request.urlretrieve(license_url + license_file)
                except urllib.error.HTTPError as err:
                    if err.code == 404:
                        missing = True
                else:
                    makeprint(' ✓ Found: ' + license_url + license_file)
                    report_file.write('Repo: ' + repo.full_name + "\nURL: " +
                                      repo_url + " \n")
                    report_file.write(' ✓ Found: ' + license_url +
                                      license_file + " \n")
                    missing = False
                    count_license += 1
                    break

            if missing:
                makeprint(' ✗ Missing the license, this repo is proprietary!')
                report_file.write('Repo: ' + repo.full_name + "\nURL: " +
                                  repo_url + " \n")
                report_file.write(
                    ' ✗ Missing the license, this repo is proprietary!\n')
                count_no_license += 1
                if repo.fork:
                    print(' ☐ Is a fork, check the original or create a PR!')
                    report_file.write(
                        ' ☐ Is a fork, check the original or create a PR!\n')
                    count_forked += 1
            count_current += 1
            report_file.write("\n")
        print("|" + "#" * 40 + "| Done 100%")
        report_file.write("Statistics: \n")
        report_file.write("Repos with License: " + str(count_license) + "\n")
        report_file.write("Repos without License: " + str(count_no_license) +
                          "\n")
        report_file.write("Repos without License and forked: " +
                          str(count_forked) + "\n")
        report_file.write("Total Repos: " +
                          str(count_no_license + count_license) + "\n")
        report_file.close()

    elif args.license:
        if len(args.args) < 1:
            sys.stderr.write('  First parameter is missing: The license:'\
            '\n  GPLv2\n'\
            '\tYou may copy, distribute and modify the software.\n'\
            '\tAny modifications must also be made available under\n'\
            '\tthe GPL along with build & install instructions.'\
            '\n\n  GPLv3\n'\
            '\tSame of GPLv2 but easily integrable with other license.'\
            '\n\n  LGPLv3\n'\
            '\tThis license is mainly applied to libraries.\n'\
            '\tDerivatives works that use LGPL library can use other license.'\
            '\n\n  AGPLv3\n'\
            '\tThe AGPL license differs from the other GNU licenses in that it was\n'\
            '\tbuilt for network software, the AGPL is the GPL of the web.'\
            '\n\n  FDLv1.3\n'\
            '\tThis License is for a manual, textbook, or other\n'\
            '\tfunctional and useful document "free" in the sense of freedom.'\
            '\n\n  Apachev2\n'\
            '\tYou can do what you like with the software, as long as you include the\n'\
            '\trequired notices.'\
            '\n\n  CC-BY\n'\
            '\tThis is the ‘standard’ creative commons.\n'\
            '\tIt should not be used for the software.'\
            '\n\n  BSDv2\n'\
            '\tThe BSD 2-clause license allows you almost unlimited freedom.'
            '\n\n  BSDv3\n'\
            '\tThe BSD 3-clause license allows you almost unlimited freedom.'
            '\n\n  BSDv4\n'\
            '\tThe BSD 4-clause license is a permissive license with a special \n'\
            '\tobligation to credit the copyright holders of the software.'\
            '\n\n  MPLv2\n'\
            '\tMPL is a copyleft license. You must make the source code for any\n'\
            '\tof your changes available under MPL, but you can combine the\n'\
            '\tMPL software with proprietary code.'\
            '\n\n  UNLICENSE\n'\
            '\tReleases code into the public domain.'\
            '\n\n  MIT\n'\
            '\tA short, permissive software license.\n\n')
            sys.stderr.write(
                '  Second optional parameter: The license: git remote name (this would automatically push LICENSE to master)\n'
            )
            sys.exit(1)

        if args.args[0] == 'GPLv2':
            downloadLicense(
                "http://www.gnu.org/licenses/gpl-2.0.txt", args.args[0],
                '(https://img.shields.io/badge/License-GPL%20v2-blue.svg)](https://img.shields.io/badge/License-GPL%20v2-blue.svg)'
            )
        elif args.args[0] == 'GPLv3':
            downloadLicense(
                "http://www.gnu.org/licenses/gpl-3.0.txt", args.args[0],
                '(https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)'
            )
        elif args.args[0] == 'LGPLv3':
            downloadLicense(
                "http://www.gnu.org/licenses/lgpl-3.0.txt", args.args[0],
                '(https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](http://www.gnu.org/licenses/lgpl-3.0)'
            )
        elif args.args[0] == 'AGPLv3':
            downloadLicense(
                "http://www.gnu.org/licenses/agpl-3.0.txt", args.args[0],
                '(https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](http://www.gnu.org/licenses/agpl-3.0)'
            )
        elif args.args[0] == 'FDLv1.3':
            downloadLicense(
                "http://www.gnu.org/licenses/fdl-1.3.txt", args.args[0],
                '(https://img.shields.io/badge/License-FDL%20v1.3-blue.svg)](http://www.gnu.org/licenses/fdl-1.3)'
            )
        elif args.args[0] == 'Apachev2':
            downloadLicense(
                "http://www.opensource.apple.com/source/apache2/apache2-19/apache2.txt?txt",
                args.args[0],
                '(https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)'
            )
        elif args.args[0] == 'CC-BY':
            downloadLicense(
                "http://creativecommons.org/licenses/by/3.0/legalcode.txt",
                args.args[0],
                '(https://img.shields.io/badge/License-CC%20BY%204.0-lightgrey.svg)(http://creativecommons.org/licenses/by/4.0/)'
            )
        elif args.args[0] == 'BSDv2':
            downloadLicense(
                "https://spdx.org/licenses/BSD-2-Clause.txt", args.args[0],
                '(https://img.shields.io/badge/License-BSD%20v2-blue.svg)](https://spdx.org/licenses/BSD-2-Clause)'
            )
        elif args.args[0] == 'BSDv3':
            downloadLicense(
                "https://spdx.org/licenses/BSD-3-Clause.txt", args.args[0],
                '(https://img.shields.io/badge/License-BSD%20v3-blue.svg)](https://spdx.org/licenses/BSD-3-Clause)'
            )
        elif args.args[0] == 'BSDv4':
            downloadLicense(
                "https://spdx.org/licenses/BSD-4-Clause.txt", args.args[0],
                '(https://img.shields.io/badge/License-BSD%20v4-blue.svg)](https://spdx.org/licenses/BSD-4-Clause)'
            )
        elif args.args[0] == 'MPLv2':
            downloadLicense(
                "https://www.mozilla.org/media/MPL/2.0/index.815ca599c9df.txt",
                args.args[0],
                '(https://img.shields.io/badge/License-MozillaPublicLicense%20v2-blue.svg)](https://www.mozilla.org/en-US/MPL/2.0)'
            )
        elif args.args[0] == 'UNLICENSE':
            downloadLicense(
                "http://unlicense.org/UNLICENSE", args.args[0],
                '(https://img.shields.io/badge/License-UNLICENSE%20v1-blue.svg)](http://unlicense.org/UNLICENSE)'
            )
        elif args.args[0] == 'MIT':
            downloadLicense(
                "https://spdx.org/licenses/MIT.txt", args.args[0],
                '(https://img.shields.io/badge/License-MIT%20v1-blue.svg)](https://spdx.org/licenses/MIT.html#licenseText)'
            )
        else:
            print('License not found!')
    else:
        parser.error('No action requested, add --scan or --license')
コード例 #2
0
def main():
    """Execute the script."""

    # If the script was launched in "scan" mode
    if ARGS.scan:

        # Initialise specified repo provider
        # (or use the default provider, if one is not specified)
        repo_provider = repobase.get_provider(ARGS.provider)

        # Obtain the username passed on the cmd-line in "scan" mode
        user = repo_provider(ARGS.scan)

        # Create the specified license report file
        # (or use the default license report file name, if one is not specified)
        if ARGS.report is None:
            report_file = open(
                ARGS.scan + '-' + ARGS.provider + '-license-report', 'w')
            print(' No report file name found, using default "' + ARGS.scan +
                  '-' + ARGS.provider + '-license-report"!')
        else:
            report_file = open(ARGS.report, 'w')

        # Start scanning user's public repos
        report_file.write('Last scan done on: ' + time.strftime("%c") + "\n")
        report_file.write('Scan report of user: '******'license'
        # This is ordered by the most common extensions
        license_extensions = ['', '.md', '.txt']
        license_files = []

        # This is ordered like this because most license file names are in full caps
        for license_name in [license_base_name.upper(), license_base_name]:
            license_files.extend(
                [license_name + extension for extension in license_extensions])

        # For each repo found
        for repo in user.get_repos():
            print(repo.full_name)
            license_url = repo.raw_base_url
            repo_url = repo.repo_url
            update_progress_bar(count_current, count_total)

            # Look for a License file in the root directory fo the repo
            for license_file in license_files:
                missing = True
                try:
                    urllib.request.urlretrieve(license_url + license_file)
                except urllib.error.HTTPError as err:
                    if err.code == 404:
                        missing = True
                else:
                    print_license_status(' ✓ Found: ' + license_url +
                                         license_file)
                    report_file.write('Repo: ' + repo.full_name + "\nURL: " +
                                      repo_url + " \n")
                    report_file.write(' ✓ Found: ' + license_url +
                                      license_file + " \n")
                    missing = False
                    count_license += 1
                    break

            if missing:
                print_license_status(
                    ' ✗ Missing the license, this repo is proprietary!')
                report_file.write('Repo: ' + repo.full_name + "\nURL: " +
                                  repo_url + " \n")
                report_file.write(
                    ' ✗ Missing the license, this repo is proprietary!\n')
                count_no_license += 1
                if repo.fork:
                    print(' ! Is a fork, check the original or create a PR!')
                    report_file.write(
                        ' ! Is a fork, check the original or create a PR!\n')
                    count_forked += 1
            count_current += 1
            report_file.write("\n")

        # Update progress based on % of repos scanned
        print("|" + "#" * 40 + "| Done 100%")
        report_file.write("Statistics: \n")
        report_file.write("Repos with License: " + str(count_license) + "\n")
        report_file.write("Repos without License: " + str(count_no_license) +
                          "\n")
        report_file.write("Repos without License and forked: " +
                          str(count_forked) + "\n")
        report_file.write("Total Repos: " +
                          str(count_no_license + count_license) + "\n")
        report_file.close()

    # If the script was launched in "licenselist" mode
    elif ARGS.licenselist:
        print_license_list()
        sys.exit(1)

    # If the script was launched in "license" mode
    elif ARGS.license:

        last_used_licenses = load_last_used_licenses()

        # This will be the actual license if explicitly called with a license
        chosen_license = ARGS.license

        # Called without a license. List off the last used licenses and let user select.
        if not ARGS.license:
            chosen_license = pick_license_from_last_used(last_used_licenses)

        # Check which license is being requested and update accordingly
        if chosen_license == 'GPLv2':
            update_license(
                "http://www.gnu.org/licenses/gpl-2.0.txt", chosen_license,
                '(https://img.shields.io/badge/License-GPL%20v2-blue.svg)](https://img.shields.io/badge/License-GPL%20v2-blue.svg)'
            )
        elif chosen_license == 'GPLv3':
            update_license(
                "http://www.gnu.org/licenses/gpl-3.0.txt", chosen_license,
                '(https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)'
            )
        elif chosen_license == 'LGPLv3':
            update_license(
                "http://www.gnu.org/licenses/lgpl-3.0.txt", chosen_license,
                '(https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](http://www.gnu.org/licenses/lgpl-3.0)'
            )
        elif chosen_license == 'AGPLv3':
            update_license(
                "http://www.gnu.org/licenses/agpl-3.0.txt", chosen_license,
                '(https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](http://www.gnu.org/licenses/agpl-3.0)'
            )
        elif chosen_license == 'FDLv1.3':
            update_license(
                "http://www.gnu.org/licenses/fdl-1.3.txt", chosen_license,
                '(https://img.shields.io/badge/License-FDL%20v1.3-blue.svg)](http://www.gnu.org/licenses/fdl-1.3)'
            )
        elif chosen_license == 'Apachev2':
            update_license(
                "http://www.opensource.apple.com/source/apache2/apache2-19/apache2.txt?txt",
                chosen_license,
                '(https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)'
            )
        elif chosen_license == 'CC-BY':
            update_license(
                "http://creativecommons.org/licenses/by/3.0/legalcode.txt",
                chosen_license,
                '(https://img.shields.io/badge/License-CC%20BY%204.0-lightgrey.svg)(http://creativecommons.org/licenses/by/4.0/)'
            )
        elif chosen_license == 'BSDv2':
            update_license(
                "https://spdx.org/licenses/BSD-2-Clause.txt", chosen_license,
                '(https://img.shields.io/badge/License-BSD%20v2-blue.svg)](https://spdx.org/licenses/BSD-2-Clause)'
            )
        elif chosen_license == 'BSDv3':
            update_license(
                "https://spdx.org/licenses/BSD-3-Clause.txt", chosen_license,
                '(https://img.shields.io/badge/License-BSD%20v3-blue.svg)](https://spdx.org/licenses/BSD-3-Clause)'
            )
        elif chosen_license == 'BSDv4':
            update_license(
                "https://spdx.org/licenses/BSD-4-Clause.txt", chosen_license,
                '(https://img.shields.io/badge/License-BSD%20v4-blue.svg)](https://spdx.org/licenses/BSD-4-Clause)'
            )
        elif chosen_license == 'MPLv2':
            update_license(
                "https://www.mozilla.org/media/MPL/2.0/index.815ca599c9df.txt",
                chosen_license,
                '(https://img.shields.io/badge/License-MozillaPublicLicense%20v2-blue.svg)](https://www.mozilla.org/en-US/MPL/2.0)'
            )
        elif chosen_license == 'UNLICENSE':
            update_license(
                "http://unlicense.org/UNLICENSE", chosen_license,
                '(https://img.shields.io/badge/License-UNLICENSE%20v1-blue.svg)](http://unlicense.org/UNLICENSE)'
            )
        elif chosen_license == 'MIT':
            update_license(
                "https://spdx.org/licenses/MIT.txt", chosen_license,
                '(https://img.shields.io/badge/License-MIT%20v1-blue.svg)](https://spdx.org/licenses/MIT.html#licenseText)'
            )
        elif chosen_license == 'EUPL':
            update_license(
                "https://joinup.ec.europa.eu/sites/default/files/inline-files/EUPL%20v1_2%20EN(1).txt",
                chosen_license,
                '(https://img.shields.io/badge/License-EUPL%20v1.1-blue.svg)](https://joinup.ec.europa.eu/page/eupl-guidelines-faq-infographics)'
            )
        else:
            if isinstance(chosen_license) is bool:
                print('No license provided')
            else:
                print('License {license} not found!'.format(
                    license=chosen_license))
            sys.exit(1)

        # Save the three most recently used licenses (remove duplicates, keep order)
        last_used_licenses.insert(0, chosen_license)

        unique_last_used = []
        for item in last_used_licenses:
            if len(unique_last_used) >= 3:
                break

            if item in unique_last_used:
                continue

            unique_last_used.append(item)

        save_last_used_licenses(unique_last_used[:3])
コード例 #3
0
ファイル: cmd.py プロジェクト: Mte90/GH-License
def main():
    if args.scan:
        repo_provider = repobase.get_provider(args.provider)
        user = repo_provider(args.scan)
        if args.report == None:
            report_file = open(args.scan + '-' + args.provider + '-license-report','w')
            print(' No report file name found, using default "'+ args.scan + '-' + args.provider + '-license-report"!')
        else:
            report_file = open(args.report,'w')
        report_file.write('Last scan done on: ' + time.strftime("%c") + "\n")
        report_file.write('Scan report of user: '******'LICENSE.txt','license','LICENSE','license.txt','license.md','LICENSE.md']
            repo_url = repo.repo_url
            progressBar(count_current, count_total)
            for license_file in license_files:
                missing = True
                try:
                    urllib.request.urlretrieve(license_url + license_file)
                except urllib.error.HTTPError as err:
                    if err.code == 404:
                        missing = True
                else:
                    makeprint(' ✓ Found: ' + license_url + license_file)
                    report_file.write('Repo: ' + repo.full_name + "\nURL: " + repo_url + " \n")
                    report_file.write(' ✓ Found: ' + license_url + license_file + " \n")
                    missing = False
                    count_license+=1
                    break

            if missing:
                makeprint(' ✗ Missing the license, this repo is proprietary!')
                report_file.write('Repo: ' + repo.full_name + "\nURL: " + repo_url + " \n")
                report_file.write(' ✗ Missing the license, this repo is proprietary!\n')
                count_no_license+=1
                if repo.fork:
                    print(' ☐ Is a fork, check the original or create a PR!')
                    report_file.write(' ☐ Is a fork, check the original or create a PR!\n')
                    count_forked+=1
            count_current+=1
            report_file.write("\n")
        print ("|" + "#"*40 + "| Done 100%")
        report_file.write("Statistics: \n")
        report_file.write("Repos with License: " + str(count_license) + "\n")
        report_file.write("Repos without License: " + str(count_no_license) + "\n")
        report_file.write("Repos without License and forked: " + str(count_forked) + "\n")
        report_file.write("Total Repos: " + str(count_no_license + count_license) + "\n")
        report_file.close()

    elif args.licenselist == True:
             sys.stderr.write('\n  GPLv2\n'\
             '\tYou may copy, distribute and modify the software.\n'\
             '\tAny modifications must also be made available under\n'\
             '\tthe GPL along with build & install instructions.'\
             '\n\n  GPLv3\n'\
             '\tSame of GPLv2 but easily integrable with other licenses.'\
             '\n\n  LGPLv3\n'\
             '\tThis license is mainly applied to libraries.\n'\
             '\tDerivatives works that use LGPL library can use other licenses.'\
             '\n\n  AGPLv3\n'\
             '\tThe AGPL license differs from the other GNU licenses in that it was\n'\
             '\tbuilt for network software, the AGPL is the GPL of the web.'\
             '\n\n  FDLv1.3\n'\
             '\tThis license is for a manual, textbook, or other\n'\
             '\tfunctional and useful document "free" in the sense of freedom.'\
             '\n\n  Apachev2\n'\
             '\tYou can do what you like with the software, as long as you include the\n'\
             '\trequired notices.'\
             '\n\n  CC-BY\n'\
             '\tThis is the ‘standard’ creative commons.\n'\
             '\tIt should not be used for the software.'\
             '\n\n  BSDv2\n'\
             '\tThe BSD 2-clause license allows you almost unlimited freedom.'
             '\n\n  BSDv3\n'\
             '\tThe BSD 3-clause license allows you almost unlimited freedom.'
             '\n\n  BSDv4\n'\
             '\tThe BSD 4-clause license is a permissive license with a special \n'\
             '\tobligation to credit the copyright holders of the software.'\
             '\n\n  MPLv2\n'\
             '\tMPL is a copyleft license. You must make the source code for any\n'\
             '\tof your changes available under MPL, but you can combine the\n'\
             '\tMPL software with proprietary code.'\
             '\n\n  UNLICENSE\n'\
             '\tReleases code into the public domain.'\
             '\n\n  MIT\n'\
             '\tA short, permissive software license.\n\n')
             sys.exit(1)
             
    elif args.license:
        if args.license == 'GPLv2':
            downloadLicense("http://www.gnu.org/licenses/gpl-2.0.txt", args.license, '(https://img.shields.io/badge/License-GPL%20v2-blue.svg)](https://img.shields.io/badge/License-GPL%20v2-blue.svg)')
        elif args.license == 'GPLv3':
            downloadLicense("http://www.gnu.org/licenses/gpl-3.0.txt", args.license, '(https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)')
        elif args.license == 'LGPLv3':
            downloadLicense("http://www.gnu.org/licenses/lgpl-3.0.txt", args.license, '(https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](http://www.gnu.org/licenses/lgpl-3.0)')
        elif args.license == 'AGPLv3':
            downloadLicense("http://www.gnu.org/licenses/agpl-3.0.txt", args.license, '(https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](http://www.gnu.org/licenses/agpl-3.0)')
        elif args.license == 'FDLv1.3':
            downloadLicense("http://www.gnu.org/licenses/fdl-1.3.txt", args.license, '(https://img.shields.io/badge/License-FDL%20v1.3-blue.svg)](http://www.gnu.org/licenses/fdl-1.3)')
        elif args.license == 'Apachev2':
            downloadLicense("http://www.opensource.apple.com/source/apache2/apache2-19/apache2.txt?txt", args.license, '(https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)')
        elif args.license == 'CC-BY':
            downloadLicense("http://creativecommons.org/licenses/by/3.0/legalcode.txt", args.license, '(https://img.shields.io/badge/License-CC%20BY%204.0-lightgrey.svg)(http://creativecommons.org/licenses/by/4.0/)')
        elif args.license == 'BSDv2':
            downloadLicense("https://spdx.org/licenses/BSD-2-Clause.txt", args.license, '(https://img.shields.io/badge/License-BSD%20v2-blue.svg)](https://spdx.org/licenses/BSD-2-Clause)')
        elif args.license == 'BSDv3':
            downloadLicense("https://spdx.org/licenses/BSD-3-Clause.txt", args.license, '(https://img.shields.io/badge/License-BSD%20v3-blue.svg)](https://spdx.org/licenses/BSD-3-Clause)')
        elif args.license == 'BSDv4':
            downloadLicense("https://spdx.org/licenses/BSD-4-Clause.txt", args.license, '(https://img.shields.io/badge/License-BSD%20v4-blue.svg)](https://spdx.org/licenses/BSD-4-Clause)')
        elif args.license == 'MPLv2':
            downloadLicense("https://www.mozilla.org/media/MPL/2.0/index.815ca599c9df.txt", args.license, '(https://img.shields.io/badge/License-MozillaPublicLicense%20v2-blue.svg)](https://www.mozilla.org/en-US/MPL/2.0)')
        elif args.license == 'UNLICENSE':
            downloadLicense("http://unlicense.org/UNLICENSE", args.license, '(https://img.shields.io/badge/License-UNLICENSE%20v1-blue.svg)](http://unlicense.org/UNLICENSE)')
        elif args.license == 'MIT':
            downloadLicense("https://spdx.org/licenses/MIT.txt", args.license, '(https://img.shields.io/badge/License-MIT%20v1-blue.svg)](https://spdx.org/licenses/MIT.html#licenseText)')
        else:
            print('License not found!')