Advertisement
Guest User

Untitled

a guest
May 30th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. __author__ = 'schwa'
  2.  
  3. import os
  4. import subprocess
  5. import glob
  6. from github import Github # pip install PyGithub
  7. from bitbucket.bitbucket import Bitbucket # pip install --user bitbucket-api
  8.  
  9. GH_USERNAME = 'jwight@mac.com'
  10. GH_PASSWORD = '1234'
  11.  
  12. BB_USERNAME = 'jwight@mac.com'
  13. BB_PASSWORD = '5678'
  14.  
  15. ## Set up
  16. d = os.path.expanduser('~/Desktop/Private Repos')
  17. if not os.path.exists(d):
  18. os.makedirs(d)
  19. os.chdir(d)
  20.  
  21. ## Get list of all your github private repos.
  22. ## By default we filter out public repos and repos where you are not the owner. You can change this.
  23. g = Github(GH_USERNAME, GH_PASSWORD)
  24. theRepos = []
  25. for repo in g.get_user().get_repos():
  26. if not repo.private:
  27. continue
  28. if repo.owner.name != g.get_user().name:
  29. continue
  30. theRepos.append((repo.name, repo.clone_url))
  31.  
  32. ### CLOWN ALL THE THIGNS
  33. for theName, theCloneURL in theRepos:
  34. print theName
  35. subprocess.check_call(['git', 'clone', theCloneURL, theName])
  36.  
  37. ### Go through all the cloned directories, create a bitbucket repo and then push them
  38. ### If the repo already exists on github this will skip it.
  39. bb = Bitbucket(BB_USERNAME, BB_PASSWORD, 'private_slug')
  40. for name in glob.iglob('*'):
  41. print name
  42. result, r = bb.repository.create(name, scm='git', private=True)
  43. if not result:
  44. print 'Could not create repo, skipping'
  45. continue
  46. push_url = 'git@bitbucket.org:{owner}/{name}.git'.format(owner = r['owner'], name = r['name'])
  47. os.chdir(name)
  48. subprocess.check_call(['git', 'remote', 'set-url', 'origin', push_url])
  49. subprocess.check_call(['git', 'push'])
  50. os.chdir(d)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement