Skip to content

Instantly share code, notes, and snippets.

@aarroyoc
Created June 17, 2018 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarroyoc/0f46146a475a05813e43966a7472eac0 to your computer and use it in GitHub Desktop.
Save aarroyoc/0f46146a475a05813e43966a7472eac0 to your computer and use it in GitHub Desktop.
BitBucket Sync Python
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