Mercurial > hg > fetch
comparison 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 |
comparison
equal
deleted
inserted
replaced
38:645d02834042 | 39:8addc3712e75 |
---|---|
76 def __call__(self, dest): | 76 def __call__(self, dest): |
77 if os.path.exists(dest): | 77 if os.path.exists(dest): |
78 assert os.path.isdir(dest), "Destination must be a directory" | 78 assert os.path.isdir(dest), "Destination must be a directory" |
79 else: | 79 else: |
80 os.makedirs(dest) | 80 os.makedirs(dest) |
81 if self.subpath: | |
82 raise NotImplementedError("should extract only a subpath of a tarball but I haven't finished it yet") | |
83 buffer = StringIO() | 81 buffer = StringIO() |
84 buffer.write(self.download(self.url)) | 82 buffer.write(self.download(self.url)) |
85 buffer.seek(0) | 83 buffer.seek(0) |
86 tf = tarfile.open(mode='r', fileobj=buffer) | 84 tf = tarfile.open(mode='r', fileobj=buffer) |
87 members = tf.getmembers() | 85 members = tf.getmembers() |
86 if self.subpath: | |
87 | |
88 # build list of files to extract | |
89 _members = [] | |
90 | |
91 toppath = None | |
92 for member in members: | |
93 split = member.name.split(os.path.sep) | |
94 if toppath: | |
95 # ensure that for subpaths that only one top level directory exists | |
96 # XXX needed? | |
97 assert toppath == split[0], "Multiple top-level archives found" | |
98 else: | |
99 toppath = split[0] | |
100 if split and split[1:len(self.subpath)] == self.subpath: | |
101 import pdb; pdb.set_trace() | |
102 | |
103 members = _members | |
104 | |
88 for member in members: | 105 for member in members: |
89 tf.extract(member, dest) | 106 tf.extract(member, dest) |
90 | 107 |
91 fetchers = [FileFetcher, TarballFetcher] | 108 fetchers = [FileFetcher, TarballFetcher] |
92 | 109 |