Last active
September 24, 2015 07:37
-
-
Save skaslev/713322 to your computer and use it in GitHub Desktop.
Update all local repositories in parallel
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
#!/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