Skip to content

Instantly share code, notes, and snippets.

@skaslev
Last active September 24, 2015 07:37
Show Gist options
  • Save skaslev/713322 to your computer and use it in GitHub Desktop.
Save skaslev/713322 to your computer and use it in GitHub Desktop.
Update all local repositories in parallel
#!/usr/bin/env python
import os
import subprocess
src = os.path.expandvars('$HOME/src')
ignored = set(['x'])
repo_cmd = { '.git': 'git pull',
'.bzr': 'bzr pull',
'.hg': 'hg pull -u',
'.svn': 'svn up' }
def main():
ps = {}
ds = [d for d in os.listdir(src)
if d not in ignored and os.path.isdir(os.path.join(src, d))]
for d in ds:
ls = os.listdir(os.path.join(src, d))
for repo in repo_cmd.keys():
if repo in ls:
p = subprocess.Popen(repo_cmd[repo], shell=True,
cwd=os.path.join(src, d),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
ps[p.pid] = (p, d)
break
else:
print 'Skipping %s.\n' % d
while ps:
(pid, ret) = os.wait()
(p, d) = ps[pid]
print 'Updating %s:' % d
print p.stdout.read()
del ps[pid]
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment