Guest User

Untitled

a guest
Sep 30th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. # description: add MIT licence to all my Github repositories ('master' branch, Year '2018', copyright holders 'Juniper Networks, Inc. All rights reserved'
  2. # usage python ./github.py
  3.  
  4.  
  5. MIT_licence = """
  6. MIT License
  7.  
  8. Copyright (c) 2018 Juniper Networks, Inc. All rights reserved
  9.  
  10. Permission is hereby granted, free of charge, to any person obtaining a copy
  11. of this software and associated documentation files (the "Software"), to deal
  12. in the Software without restriction, including without limitation the rights
  13. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. copies of the Software, and to permit persons to whom the Software is
  15. furnished to do so, subject to the following conditions:
  16.  
  17. The above copyright notice and this permission notice shall be included in all
  18. copies or substantial portions of the Software.
  19.  
  20. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26. SOFTWARE.
  27. """
  28. import git
  29. import os
  30.  
  31. def add_licence(myrepo):
  32. cwd = os.getcwd()
  33. print "about to add MIT licence to " + myrepo.name
  34. repo_dir = cwd + '/' + myrepo.name
  35. if os.path.isdir(repo_dir):
  36. print "you already have a local copy of the repository " + myrepo.name
  37. repo = git.Repo(repo_dir)
  38. repo.git.pull('origin', 'master')
  39. else:
  40. print "cloning the repo " + myrepo.name
  41. repo = git.Repo.clone_from(item.clone_url, repo_dir)
  42. f=open(repo_dir + '/LICENSE','w')
  43. f.write(MIT_licence)
  44. f.close()
  45. repo.git.add('LICENSE')
  46. try:
  47. repo.git.commit(m = "add MIT licence using Gitpython")
  48. except git.exc.GitCommandError:
  49. print ('MIT licence was already there, nothing to commit on ' + myrepo.name)
  50. else:
  51. repo.git.push('origin', 'master')
  52. return "done. MIT licence added to " + myrepo.name
  53.  
  54.  
  55. # repo_list = []
  56. # for item in repo_list:
  57. # add_licence(item)
  58.  
  59. import pygithub3
  60.  
  61. # login =raw_input("github login :")
  62. # password=raw_input("github password:")
  63. import getpass
  64. password=getpass.getpass("Enter your Github password: ")
  65.  
  66. gh = pygithub3.Github(login='ksator', password=password)
  67. all_my_repos = gh.repos.list(user='ksator', type='owner').all()
  68. for item in all_my_repos:
  69. # print item.name
  70. # print item.clone_url
  71. # print item.ssh_url
  72. add_licence(item)
Add Comment
Please, Sign In to add comment