# HG changeset patch # User Jeff Hammel # Date 1316396791 25200 # Node ID cf00d46b1bfb1f569b5a1f13f2a4c0b0b6d901ef # Parent 4d3d0e1324f535b1512ace2199eaa7fc9b738562 pretend like we have a pluggable system to start debugging it diff -r 4d3d0e1324f5 -r cf00d46b1bfb fetch/main.py --- a/fetch/main.py Sun Sep 18 18:37:02 2011 -0700 +++ b/fetch/main.py Sun Sep 18 18:46:31 2011 -0700 @@ -8,7 +8,16 @@ import sys import optparse -__all__ = ['Fetcher', 'FileFetcher', 'main'] +__all__ = ['Fetcher', 'Fetch', 'main'] + +def which(executable, path=os.environ['PATH']): + """python equivalent of which; should really be in the stdlib""" + # XXX from https://github.com/mozautomation/mozmill/blob/master/mozrunner/mozrunner/utils.py + dirs = path.split(os.pathsep) + for dir in dirs: + if os.path.isfile(os.path.join(dir, fileName)): + return os.path.join(dir, fileName) + class Fetcher(object): """abstract base class for resource fetchers""" @@ -60,6 +69,13 @@ tf = tarfile.open(mode='r', fileobj=buffer) tf.extract(dest) +fetchers = [FileFetcher, TarballFetcher] + +### VCS fetchers using executable + +if which('hg'): + pass # TODO: wrap HgFetcher + class HgFetcher(Fetcher): """checkout a mercurial repository""" @@ -70,7 +86,10 @@ type = 'git' -fetchers = [FileFetcher] + +fetcher_names = [cls.__name__ for cls in fetchers] +__all__ += fetcher_names + class Fetch(object): @@ -170,8 +189,16 @@ parser.add_option('-s', '--strict', action='store_true', default=False, help="fail on error") + parser.add_option('--list-fetchers', dest='list_fetchers', + action='store_true', default=False, + help='list available fetchers and exit') options, args = parser.parse_args(args) + if options.list_fetchers: + for name in fetcher_names: + print name + parser.exit() + if not args: parser.print_help() parser.exit()