Skip to content

Commit

Permalink
fix the missing download
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 committed Nov 5, 2016
1 parent 03af2f1 commit c322eb7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ With this command you will get a report in a file called Mte90-bitbucket-license

With this command you will get a report in a file called my-report

gh-license --licenselist

With this command will be showed the licenses avalaible
gh-license --license GPLv3

With this command, a GPLv3 license will be downloaded, a shields will be added in the readme and if Git is available a commit will be added and the changes will be pushed to the repo.
Expand Down
69 changes: 35 additions & 34 deletions ghlicense/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
epilog = enhanced_description, formatter_class=RawTextHelpFormatter)
err_providers_txt = "(errored providers: %s)" % ", ".join(disabled_providers) if len(disabled_providers) > 0 else ""
parser.add_argument("--scan", help="Scan repo of the user, arguments: [User_nick]", action="store")
parser.add_argument("--license", help="Download a license file, arguments: [License_name]", action="store_true")
parser.add_argument("--license", help="Download a license file, arguments: [License_name]", action="store")
parser.add_argument("--licenselist", help="Show licenses available", action="store_true")
parser.add_argument("--provider", help="Repository provider. Defaults to github. Available providers: %s %s" %
(", ".join(enabled_providers), err_providers_txt), action="store", default="github")
parser.add_argument("--report", help="The report filename for scan (optional)", action="store")
Expand All @@ -50,11 +51,12 @@ def progressBar(current, total):
sys.stdout.flush()
# Download the license
def downloadLicense(url, name, badge):
print('License ' + name + ' download in progress.')
if not os.path.isfile("LICENSE"):
urllib.request.urlretrieve(url, "LICENSE")
print('License ' + name + ' downloaded with filename LICENSE.')
# Search for the readme
readme_files = ['README.md','README.txt','readme','README','readme.txt','readme.md']
readme_files = ['README.md','Readme.md','README.txt','readme','README','readme.txt','readme.md']
for readme_file in readme_files:
if os.path.isfile(readme_file):
f = open(readme_file, 'r+')
Expand All @@ -72,7 +74,7 @@ def downloadLicense(url, name, badge):
os.system('git add LICENSE')
os.system('git add ' + readme_file)
os.system("git commit -m 'missing LICENSE'")
if args.origin == None:
if args.origin != None:
os.system('git push ' + args.origin + ' master')
else:
os.system('git push origin master')
Expand Down Expand Up @@ -133,10 +135,8 @@ def main():
report_file.write("Total Repos: " + str(count_no_license + count_license) + "\n")
report_file.close()

elif args.license:
if args.license == True:
sys.stderr.write(' First parameter is missing: The license:'\
'\n GPLv2\n'\
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.'\
Expand Down Expand Up @@ -173,33 +173,34 @@ def main():
'\n\n MIT\n'\
'\tA short, permissive software license.\n\n')
sys.exit(1)

if args.scan == 'GPLv2':
downloadLicense("http://www.gnu.org/licenses/gpl-2.0.txt", args.scan, '(https://img.shields.io/badge/License-GPL%20v2-blue.svg)](https://img.shields.io/badge/License-GPL%20v2-blue.svg)')
elif args.scan == 'GPLv3':
downloadLicense("http://www.gnu.org/licenses/gpl-3.0.txt", args.scan, '(https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)')
elif args.scan == 'LGPLv3':
downloadLicense("http://www.gnu.org/licenses/lgpl-3.0.txt", args.scan, '(https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](http://www.gnu.org/licenses/lgpl-3.0)')
elif args.scan == 'AGPLv3':
downloadLicense("http://www.gnu.org/licenses/agpl-3.0.txt", args.scan, '(https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](http://www.gnu.org/licenses/agpl-3.0)')
elif args.scan == 'FDLv1.3':
downloadLicense("http://www.gnu.org/licenses/fdl-1.3.txt", args.scan, '(https://img.shields.io/badge/License-FDL%20v1.3-blue.svg)](http://www.gnu.org/licenses/fdl-1.3)')
elif args.scan == 'Apachev2':
downloadLicense("http://www.opensource.apple.com/source/apache2/apache2-19/apache2.txt?txt", args.scan, '(https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)')
elif args.scan == 'CC-BY':
downloadLicense("http://creativecommons.org/licenses/by/3.0/legalcode.txt", args.scan, '(https://img.shields.io/badge/License-CC%20BY%204.0-lightgrey.svg)(http://creativecommons.org/licenses/by/4.0/)')
elif args.scan == 'BSDv2':
downloadLicense("https://spdx.org/licenses/BSD-2-Clause.txt", args.scan, '(https://img.shields.io/badge/License-BSD%20v2-blue.svg)](https://spdx.org/licenses/BSD-2-Clause)')
elif args.scan == 'BSDv3':
downloadLicense("https://spdx.org/licenses/BSD-3-Clause.txt", args.scan, '(https://img.shields.io/badge/License-BSD%20v3-blue.svg)](https://spdx.org/licenses/BSD-3-Clause)')
elif args.scan == 'BSDv4':
downloadLicense("https://spdx.org/licenses/BSD-4-Clause.txt", args.scan, '(https://img.shields.io/badge/License-BSD%20v4-blue.svg)](https://spdx.org/licenses/BSD-4-Clause)')
elif args.scan == 'MPLv2':
downloadLicense("https://www.mozilla.org/media/MPL/2.0/index.815ca599c9df.txt", args.scan, '(https://img.shields.io/badge/License-MozillaPublicLicense%20v2-blue.svg)](https://www.mozilla.org/en-US/MPL/2.0)')
elif args.scan == 'UNLICENSE':
downloadLicense("http://unlicense.org/UNLICENSE", args.scan, '(https://img.shields.io/badge/License-UNLICENSE%20v1-blue.svg)](http://unlicense.org/UNLICENSE)')
elif args.scan == 'MIT':
downloadLicense("https://spdx.org/licenses/MIT.txt", args.scan, '(https://img.shields.io/badge/License-MIT%20v1-blue.svg)](https://spdx.org/licenses/MIT.html#licenseText)')

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!')

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name="gh-license",
version="0.2.2",
version="0.2.3",
author="Mte90",
install_requires=open(os.path.join(BASE_DIR, "requirements.txt")).readlines(),
license="GPLv3",
Expand Down

0 comments on commit c322eb7

Please sign in to comment.