Mercurial > hg > fetch
changeset 7:4d3d0e1324f5
flush out tarfile
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sun, 18 Sep 2011 18:37:02 -0700 |
parents | 86f6f99e421b |
children | cf00d46b1bfb |
files | fetch/main.py |
diffstat | 1 files changed, 13 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/fetch/main.py Sun Sep 18 18:27:57 2011 -0700 +++ b/fetch/main.py Sun Sep 18 18:37:02 2011 -0700 @@ -8,6 +8,8 @@ import sys import optparse +__all__ = ['Fetcher', 'FileFetcher', 'main'] + class Fetcher(object): """abstract base class for resource fetchers""" @@ -21,8 +23,11 @@ def __call__(self, dest): raise NotImplementedError +### standard dispatchers - always available +import tarfile import urllib2 +from StringIO import StringIO class FileFetcher(Fetcher): """fetch a single file""" @@ -47,6 +52,14 @@ type = 'tar' + def __call__(self, dest): + assert os.path.isdir(dest) + buffer = StringIO() + buffer.write(self.download(self.url)) + buffer.seek(0) + tf = tarfile.open(mode='r', fileobj=buffer) + tf.extract(dest) + class HgFetcher(Fetcher): """checkout a mercurial repository"""