Mercurial > hg > silvermirror
view silvermirror/hg.py @ 5:660c74f33ed2
adding more to skeleton for main program
author | k0s <k0scist@gmail.com> |
---|---|
date | Sat, 03 Oct 2009 18:10:11 -0400 |
parents | 8a5d2083fbd1 |
children | c999b2f16159 |
line wrap: on
line source
#!/usr/bin/env python """ stub for the hg backend of silvermirror """ import os import sys from mercurial import commands, hg, ui from optparse import OptionParser def update(host, path): """ get changes from host on path """ ui = ui.ui() try: repo = hg.repository(ui, path) command = commands.pull except mercurial.repo.RepoError: repo = hg.repository(ui, 'ssh://%s/%s' % (host, path)) command = commands.clone 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) ] 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 main(args=sys.argv[1:]): parser = OptionParser() parser.add_option('-H', '--host', dest='host') options, args = parser.parse_args(args) if len(args) != 1: parser.print_usage() parser.exit() if __name__ == '__main__': main()