changeset 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
files example.txt fetch.py
diffstat 2 files changed, 22 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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)