Skip to content

Instantly share code, notes, and snippets.

@KlausBrunner KlausBrunner/pullall.py
Last active Dec 10, 2015

Embed
What would you like to do?
Pull all the Mercurial repos listed in the TortoiseHg registry. Convenient if you're tracking lots of repositories.
#!/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
You can’t perform that action at this time.