Skip to content

Instantly share code, notes, and snippets.

@bertonha
Created May 10, 2012 05:25
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 bertonha/2651207 to your computer and use it in GitHub Desktop.
Save bertonha/2651207 to your computer and use it in GitHub Desktop.
update projects with version control
#!/usr/bin/env python
import os
import sys
from subprocess import Popen, PIPE
if len(sys.argv) > 1:
path = os.path.abspath(sys.argv[1])
else:
path = os.path.dirname(__file__)
dirs = []
for dir_ in os.listdir(path):
dir_ = os.path.join(path, dir_)
if os.path.isdir(dir_):
dirs.append(dir_)
SCMS = {
'git': 'git pull',
'hg': 'hg pull -u',
'svn': 'svn update',
}
def get_versioning(path):
for scm in SCMS.keys():
if os.path.exists(os.path.join(path, '.%s' % scm)):
return scm
return None
def has_upstream(path):
cmd = Popen('git remote'.split(), cwd=path, stdout=PIPE)
remotes, _ = cmd.communicate()
if b'upstream' in remotes:
return True
return False
for dir_ in dirs:
scm = get_versioning(dir_)
dir_name = os.path.basename(dir_)
if scm is not None:
if scm == 'git' and has_upstream(dir_):
cmd = 'git pull upstream master'
else:
cmd = SCMS[scm]
print('Updating %s with %s' % (dir_name, scm))
print(cmd)
Popen(cmd.split(), cwd=dir_).communicate()
else:
print("No SCM in %s" % dir_name)
print('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment