Mercurial > hg > fetch
diff fetch.py @ 39:8addc3712e75
partially and borken support for subpaths
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 15 Nov 2011 13:53:54 -0800 |
parents | 645d02834042 |
children | e103ae19c2a0 |
line wrap: on
line diff
--- a/fetch.py Tue Nov 15 12:56:35 2011 -0800 +++ b/fetch.py Tue Nov 15 13:53:54 2011 -0800 @@ -78,13 +78,30 @@ assert os.path.isdir(dest), "Destination must be a directory" else: os.makedirs(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) tf = tarfile.open(mode='r', fileobj=buffer) members = tf.getmembers() + if self.subpath: + + # build list of files to extract + _members = [] + + toppath = None + for member in members: + split = member.name.split(os.path.sep) + if toppath: + # ensure that for subpaths that only one top level directory exists + # XXX needed? + assert toppath == split[0], "Multiple top-level archives found" + else: + toppath = split[0] + if split and split[1:len(self.subpath)] == self.subpath: + import pdb; pdb.set_trace() + + members = _members + for member in members: tf.extract(member, dest)