Created
June 17, 2018 13:42
-
-
Save aarroyoc/0f46146a475a05813e43966a7472eac0 to your computer and use it in GitHub Desktop.
BitBucket Sync Python
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
from bitbucket.bitbucket import Bitbucket | |
import os | |
import subprocess | |
def cmd(command): | |
print(command) | |
args = command.split(" ") | |
result = subprocess.run(args,stdout=subprocess.PIPE) | |
out = result.stdout.decode("utf-8").strip() | |
print(out) | |
base = "https://bitbucket.org/USERNAME/%s" | |
bb = Bitbucket("USERNAME","PASSWORD") | |
res, repos = bb.repository.all() | |
for repo in repos: | |
slug = repo["slug"] | |
scm = repo["scm"] | |
print("BitBucket: %s" % slug) | |
if scm == "git": | |
if os.path.isdir(slug): | |
os.chdir(slug) | |
cmd("git pull") | |
os.chdir("..") | |
else: | |
url = base % slug | |
cmd("git clone %s %s" % (url,slug)) | |
elif scm == "hg": | |
if os.path.isdir(slug): | |
os.chdir(slug) | |
cmd("hg pull") | |
os.chdir("..") | |
else: | |
url = base % slug | |
cmd("hg clone %s %s" % (url,slug)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment