Last active
December 10, 2015 22:29
-
-
Save klausbrunner/4502394 to your computer and use it in GitHub Desktop.
Pull all the Mercurial repos listed in the TortoiseHg registry. Convenient if you're tracking lots of repositories.
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 | |
""" | |
Pull all the Mercurial repos listed in the TortoiseHg registry, in parallel. | |
Convenient if you're tracking lots of repositories. | |
""" | |
from __future__ import print_function | |
import subprocess | |
import os | |
import sys | |
import xml.etree.ElementTree as ET | |
import multiprocessing | |
def get_repo_paths(reporegistry_xml_path): | |
with open(reporegistry_xml_path, 'r') as f: | |
root = ET.parse(f).getroot() | |
repos = root.findall('.//repo') | |
repopaths = [repo.attrib['root'] for repo in repos] | |
return repopaths | |
def spawn_pull(repopath, pull_args): | |
cmd_args = ['hg', '--repository', repopath, 'pull'] + pull_args | |
output = subprocess.check_output(args=cmd_args) | |
return [cmd_args, output] | |
def pull_repo_paths(repopaths, pull_args=(), process_count=5): | |
pool = multiprocessing.Pool(processes=process_count) | |
for repopath in repopaths: | |
pool.apply_async(func=spawn_pull, args=[repopath, pull_args], callback=lambda r: print(*r)) | |
pool.close() | |
pool.join() | |
if __name__ == '__main__': | |
pull_args = sys.argv[1:] | |
thgregistry = os.path.expanduser('~/.config/TortoiseHg/thg-reporegistry.xml') | |
repopaths = get_repo_paths(thgregistry) | |
pull_repo_paths(repopaths, pull_args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment