# HG changeset patch # User Jeff Hammel # Date 1320886491 28800 # Node ID e2af4bc5159cf4a2147c6f3c95ef749b9972aa26 # Parent c77d29a10e088e8946d19357a22eea33c5d8896b more polishing diff -r c77d29a10e08 -r e2af4bc5159c fetch.py --- a/fetch.py Wed Nov 09 16:33:29 2011 -0800 +++ b/fetch.py Wed Nov 09 16:54:51 2011 -0800 @@ -24,11 +24,20 @@ def match(cls, _type): return _type == cls.type - def __init__(self, url): + def __init__(self, url, clobber=False): + self.subpath = None + if '#' in url: + url, self.subpath = url.rsplit('#') self.url = url def __call__(self, dest): - raise NotImplementedError + raise NotImplementedError("Should be called by implementing class") + + @classmethod + def doc(cls): + """return docstring for the instance""" + retval = getattr(cls, '__doc__', '').strip() + return ' '.join(retval.split()) ### standard dispatchers - always available @@ -61,6 +70,8 @@ def __call__(self, dest): assert os.path.isdir(dest) + if self.subpath: + raise NotImplementedError("should extract only a subpath of a tarball but I haven't finished it yet") buffer = StringIO() buffer.write(self.download(self.url)) buffer.seek(0) @@ -73,24 +84,35 @@ import subprocess +class VCSFetcher(Fetcher): + def __init__(self, url, export=True): + """ + - export : whether to strip the versioning information + """ + Fetcher.__init__(self, url) + self.export = export + if which('hg'): - class HgFetcher(Fetcher): + class HgFetcher(VCSFetcher): """checkout a mercurial repository""" type = 'hg' def __call__(self, dest): if os.path.exits(dest): assert os.path.isdir(dest) and os.path.exists(os.path.join(dest, '.hg')) - pass # TODO + raise NotImplementedError("TODO! Sorry!") fetchers.append(HgFetcher) if which('git'): + class GitFetcher(Fetcher): """checkout a git repository""" type = 'git' + fetchers + __all__ += [i.__name__ for i in fetchers] class Fetch(object): @@ -181,7 +203,7 @@ parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) parser.add_option('-o', '--output', help="output relative to this location vs. the manifest location") - parser.add_option('-d', '--dest', + parser.add_option('-d', '--dest', # XXX unused action='append', help="output only these destinations") parser.add_option('-s', '--strict', @@ -193,12 +215,16 @@ options, args = parser.parse_args(args) if options.list_fetchers: - - for name in sorted(fetchers.keys()): - print name + types = set() + for fetcher in fetchers: + if fetcher.type in types: + continue # occluded, should probably display separately + print '%s : %s' % (fetcher.type, fetcher.doc()) + types.add(fetcher.type) parser.exit() if not args: + # TODO: could read from stdin parser.print_help() parser.exit()