# HG changeset patch # User Jeff Hammel # Date 1321394034 28800 # Node ID 8addc3712e756d1f4296c424b785e457f9d57563 # Parent 645d02834042a1788525dfea812497ccc8314df6 partially and borken support for subpaths diff -r 645d02834042 -r 8addc3712e75 example.txt --- a/example.txt Tue Nov 15 12:56:35 2011 -0800 +++ b/example.txt Tue Nov 15 13:53:54 2011 -0800 @@ -1,5 +1,5 @@ # example manifest for fetch -# URL DESTINATION TYPE -http://k0s.org/geekcode . file -https://github.com/mozilla/mozbase/tarball/master . tar +# URL DESTINATION TYPE +http://k0s.org/geekcode . file +https://github.com/mozilla/mozbase/tarball/master#mozprofile . tar diff -r 645d02834042 -r 8addc3712e75 fetch.py --- 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)