Mercurial > hg > fetch
comparison fetch/main.py @ 10:0b534c8881de
make fetchers a dict keyed on class name
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sun, 18 Sep 2011 18:52:08 -0700 |
parents | f8575a78ec06 |
children | 726c3d288733 |
comparison
equal
deleted
inserted
replaced
9:f8575a78ec06 | 10:0b534c8881de |
---|---|
72 fetchers = [FileFetcher, TarballFetcher] | 72 fetchers = [FileFetcher, TarballFetcher] |
73 | 73 |
74 ### VCS fetchers using executable | 74 ### VCS fetchers using executable |
75 | 75 |
76 if which('hg'): | 76 if which('hg'): |
77 pass # TODO: wrap HgFetcher | 77 |
78 | 78 class HgFetcher(Fetcher): |
79 class HgFetcher(Fetcher): | 79 """checkout a mercurial repository""" |
80 """checkout a mercurial repository""" | 80 type = 'hg' |
81 | 81 |
82 type = 'hg' | 82 fetchers.append(HgFetcher) |
83 | 83 |
84 class GitFetcher(Fetcher): | 84 class GitFetcher(Fetcher): |
85 """checkout a git repository""" | 85 """checkout a git repository""" |
86 | |
87 type = 'git' | 86 type = 'git' |
88 | 87 |
89 | 88 |
90 fetcher_names = [cls.__name__ for cls in fetchers] | 89 fetchers = dict([(i.__name__, i) for i in fetchers]) |
91 __all__ += fetcher_names | 90 __all__ += fetchers.keys() |
92 | 91 |
93 | 92 |
94 class Fetch(object): | 93 class Fetch(object): |
95 | 94 |
96 def __init__(self, fetchers, relative_to=None, strict=True): | 95 def __init__(self, fetchers, relative_to=None, strict=True): |
193 action='store_true', default=False, | 192 action='store_true', default=False, |
194 help='list available fetchers and exit') | 193 help='list available fetchers and exit') |
195 options, args = parser.parse_args(args) | 194 options, args = parser.parse_args(args) |
196 | 195 |
197 if options.list_fetchers: | 196 if options.list_fetchers: |
198 for name in fetcher_names: | 197 for name in sorted(fetchers.keys()): |
199 print name | 198 print name |
200 parser.exit() | 199 parser.exit() |
201 | 200 |
202 if not args: | 201 if not args: |
203 parser.print_help() | 202 parser.print_help() |
204 parser.exit() | 203 parser.exit() |
205 | 204 |
206 items = read_manifests(*args) | 205 items = read_manifests(*args) |
207 fetch = Fetch(fetchers, strict=options.strict) | 206 fetch = Fetch(fetchers.values(), strict=options.strict) |
208 | 207 |
209 # download the files | 208 # download the files |
210 fetch.fetch(*items) | 209 fetch.fetch(*items) |
211 | 210 |
212 if __name__ == '__main__': | 211 if __name__ == '__main__': |