# HG changeset patch # User k0s # Date 1255634825 14400 # Node ID c999b2f16159ff7b67c635b98dbee234d3c4fce1 # Parent 660c74f33ed2831249ee8096a24779e65ec4f363 adding functionality to update/clone a bunch of hg repos diff -r 660c74f33ed2 -r c999b2f16159 setup.py --- a/setup.py Sat Oct 03 18:10:11 2009 -0400 +++ b/setup.py Thu Oct 15 15:27:05 2009 -0400 @@ -17,10 +17,12 @@ include_package_data=True, zip_safe=False, install_requires=[ - # -*- Extra requirements: -*- 'martINI', 'netifaces' ], + extras_require={ + 'mirror-hg': [ 'lxml' ], + }, dependency_links=[ 'https://svn.openplans.org/svn/standalone/martINI#egg=martINI', ], @@ -28,7 +30,7 @@ # -*- Entry points: -*- [console_scripts] silvermirror = silvermirror.unify:main - mirror-hg = silvermirror.hg:main + mirror-hg = silvermirror.hg:main [mirror-hg] [silvermirror.reflectors] unison = silvermirror.unison:unison diff -r 660c74f33ed2 -r c999b2f16159 silvermirror/hg.py --- a/silvermirror/hg.py Sat Oct 03 18:10:11 2009 -0400 +++ b/silvermirror/hg.py Thu Oct 15 15:27:05 2009 -0400 @@ -3,6 +3,8 @@ stub for the hg backend of silvermirror """ +import lxml.html +import mercurial import os import sys from mercurial import commands, hg, ui @@ -12,39 +14,72 @@ """ get changes from host on path """ - ui = ui.ui() + _ui = ui.ui() + url = '%s/%s' % (host, path) try: - repo = hg.repository(ui, path) - command = commands.pull + repo = hg.repository(_ui, path) + print 'Updating %s:' % path except mercurial.repo.RepoError: - repo = hg.repository(ui, 'ssh://%s/%s' % (host, path)) - command = commands.clone + repo = hg.repository(_ui, url) + print 'Cloning %s:' % path + commands.clone(_ui, repo, pull=False, uncompressed=False, rev=None, noupdate=False) + return -def repositories(path): - """ - return all hg repositories in a path - """ + commands.pull(_ui, repo, url, rev=None, force=False, update=True) + +# def repositories(path): +# """ +# return all hg repositories in a path +# """ - ui = ui.ui() - files = [ os.path.join(path, f) for f in os.listdir(path) ] - directories = [ f for f in files if os.path.isdir(f) ] +# ui = ui.ui() +# files = [ os.path.join(path, f) for f in os.listdir(path) ] +# directories = [ f for f in files if os.path.isdir(f) ] - repos = [] - for d in directories: - try: - repo = hg.repository(ui, d) - repos.append(os.path.basename(d)) - except mercurial.repo.RepoError: - pass +# repos = [] +# for d in directories: +# try: +# repo = hg.repository(ui, d) +# repos.append(os.path.basename(d)) +# except mercurial.repo.RepoError: +# pass +# return repos + +def repositories(url): + """ + returns the list of reposotories under a URL of an hg server + """ + element = lxml.html.parse(url) + tds = element.xpath('//tr[position() > 1]/td[1]') + repos = [ i.text_content() for i in tds ] return repos + def main(args=sys.argv[1:]): parser = OptionParser() parser.add_option('-H', '--host', dest='host') + parser.add_option('-d', '--directory', dest='directory', + default=os.path.join(os.environ['HOME'], 'hg')) + parser.add_option('--list', dest='list', + action='store_true', default=False) options, args = parser.parse_args(args) - if len(args) != 1: + if not options.host: parser.print_usage() parser.exit() + # kill trailing slash + options.host = options.host.rstrip('/') + + repos = repositories(options.host) + if options.list: + for repo in repos: + print repo + sys.exit(0) + + os.chdir(options.directory) + for repo in repos: + update(options.host, repo) + + if __name__ == '__main__': main()