Mercurial > hg > PaInt
comparison paint/package.py @ 37:36e70712fc9a
things are just awful
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 30 Mar 2012 15:06:17 -0700 |
parents | f59da9e6be37 |
children | c9d8abb2026f |
comparison
equal
deleted
inserted
replaced
36:f59da9e6be37 | 37:36e70712fc9a |
---|---|
53 tmpfile = src = self.fetch() | 53 tmpfile = src = self.fetch() |
54 | 54 |
55 # unpack if an archive | 55 # unpack if an archive |
56 if self._is_archive(src): | 56 if self._is_archive(src): |
57 try: | 57 try: |
58 self.unpack(src) | 58 self._unpack(src) |
59 finally: | 59 finally: |
60 if tmpfile: | 60 if tmpfile: |
61 os.remove(tmpfile) | 61 os.remove(tmpfile) |
62 return self._tmppath | 62 return self._tmppath |
63 | 63 |
72 resource = urllib2.urlopen(self.src) | 72 resource = urllib2.urlopen(self.src) |
73 fp.write(resource.read()) | 73 fp.write(resource.read()) |
74 fp.close() | 74 fp.close() |
75 return filename | 75 return filename |
76 | 76 |
77 def unpack(self, archive): | 77 def _unpack(self, archive): |
78 """unpack the archive to a temporary destination""" | 78 """unpack the archive to a temporary destination""" |
79 # TODO: should handle zipfile additionally at least | 79 # TODO: should handle zipfile additionally at least |
80 # Ideally, this would be pluggable, etc | 80 # Ideally, this would be pluggable, etc |
81 assert tarfile.is_tarfile(archive), "%s is not an archive" % self.src | 81 assert tarfile.is_tarfile(archive), "%s is not an archive" % self.src |
82 tf = tarfile.TarFile.open(archive) | 82 tf = tarfile.TarFile.open(archive) |
83 self._tmppath = tempfile.mkdtemp() | 83 self._tmppath = tempfile.mkdtemp() |
84 members = tf.getmembers() | 84 members = tf.getmembers() |
85 | 85 |
86 # cut off the top level directory | 86 # cut off the top level directory |
87 assert not [i for i in members if not os.path.sep in i.name] | 87 members = [i for i in members if os.path.sep in i.name] |
88 tld = set() | 88 tld = set() |
89 for member in members: | 89 for member in members: |
90 directory, member.name = member.name.split(os.path.sep, 1) | 90 directory, member.name = member.name.split(os.path.sep, 1) |
91 tld.add(directory) | 91 tld.add(directory) |
92 assert len(tld) == 1 | 92 assert len(tld) == 1 |