Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # description: add MIT licence to all my Github repositories ('master' branch, Year '2018', copyright holders 'Juniper Networks, Inc. All rights reserved'
- # usage python ./github.py
- MIT_licence = """
- MIT License
- Copyright (c) 2018 Juniper Networks, Inc. All rights reserved
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- """
- import git
- import os
- def add_licence(myrepo):
- cwd = os.getcwd()
- print "about to add MIT licence to " + myrepo.name
- repo_dir = cwd + '/' + myrepo.name
- if os.path.isdir(repo_dir):
- print "you already have a local copy of the repository " + myrepo.name
- repo = git.Repo(repo_dir)
- repo.git.pull('origin', 'master')
- else:
- print "cloning the repo " + myrepo.name
- repo = git.Repo.clone_from(item.clone_url, repo_dir)
- f=open(repo_dir + '/LICENSE','w')
- f.write(MIT_licence)
- f.close()
- repo.git.add('LICENSE')
- try:
- repo.git.commit(m = "add MIT licence using Gitpython")
- except git.exc.GitCommandError:
- print ('MIT licence was already there, nothing to commit on ' + myrepo.name)
- else:
- repo.git.push('origin', 'master')
- return "done. MIT licence added to " + myrepo.name
- # repo_list = []
- # for item in repo_list:
- # add_licence(item)
- import pygithub3
- # login =raw_input("github login :")
- # password=raw_input("github password:")
- import getpass
- password=getpass.getpass("Enter your Github password: ")
- gh = pygithub3.Github(login='ksator', password=password)
- all_my_repos = gh.repos.list(user='ksator', type='owner').all()
- for item in all_my_repos:
- # print item.name
- # print item.clone_url
- # print item.ssh_url
- add_licence(item)
Add Comment
Please, Sign In to add comment