Created
May 6, 2013 05:17
-
-
Save hersonls/5523491 to your computer and use it in GitHub Desktop.
Git: Clone all bitbucket private repos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pprint | |
from subprocess import call | |
try: | |
from bitbucket.bitbucket import Bitbucket | |
except: | |
raise Exception('You need installl bitbucket api: $ pip install bitbucket-api') | |
USERNAME = '' | |
PASSWORD = '' | |
class CloneAllRepo(): | |
def __init__(self, username=USERNAME, password=PASSWORD, | |
bitbucket_api=Bitbucket): | |
self.username = username | |
self.password = password | |
if not self.username and not self.password: | |
raise Exception('You need set a user and password on this file.') | |
self.bb = bitbucket_api(username=username, password=password) | |
def get_all_repos(self): | |
return self.bb.repository.all() | |
def clone(self): | |
success, response = self.get_all_repos() | |
for repo in response: | |
repo_name = repo['name'] | |
dest_path = os.path.abspath(os.path.join('.', repo_name)) | |
if not os.path.isdir(dest_path): | |
print "Clone: ", repo_name, " to -> ", dest_path | |
call(["git", "clone", "[email protected]:{0}/{1}".format(self.username, repo_name), dest_path]) | |
def run(self): | |
self.clone() | |
if __name__ == '__main__': | |
print "=" * 80 | |
clone_all_repo = CloneAllRepo() | |
clone_all_repo.run() | |
print "=" * 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment