comparison paint/package.py @ 9:562230cc2e86

now the package class should at least extracts things. it doesnt actually do anything useful
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 23 Feb 2012 17:49:05 -0800
parents c1181e9c9ca2
children d63ae03cc300
comparison
equal deleted inserted replaced
8:c1181e9c9ca2 9:562230cc2e86
1 """ 1 """
2 package model for python PAckage INTrospection 2 package model for python PAckage INTrospection
3 """ 3 """
4 4
5 import os 5 import os
6 import shutil
6 import tarfile 7 import tarfile
7 import tempfile 8 import tempfile
8 import urllib2 9 import urllib2
9 import utils 10 import utils
10 11
50 def unpack(self, archive): 51 def unpack(self, archive):
51 """unpack the archive to a temporary destination""" 52 """unpack the archive to a temporary destination"""
52 # TODO: should handle zipfile additionally at least 53 # TODO: should handle zipfile additionally at least
53 # Ideally, this would be pluggable, etc 54 # Ideally, this would be pluggable, etc
54 assert tarfile.is_tarfile(archive), "%s is not an archive" % self.src 55 assert tarfile.is_tarfile(archive), "%s is not an archive" % self.src
55 tarfile.TarFile.open(archive) 56 tf = tarfile.TarFile.open(archive)
57 self._tmppath = tempfile.mkdtemp()
58 tf.extractall(path=self._tmppath)
56 59
57 def is_archive(self, path): 60 def is_archive(self, path):
58 """returns if the filesystem path is an archive""" 61 """returns if the filesystem path is an archive"""
59 # TODO: should handle zipfile additionally at least 62 # TODO: should handle zipfile additionally at least
60 # Ideally, this would be pluggable, etc 63 # Ideally, this would be pluggable, etc
61 return tarfile.is_tarfile(path) 64 return tarfile.is_tarfile(path)
65
66 def cleanup(self):
67 if self._tmppath:
68 shutil.rmtree(self._tmppath)
69 self._tmppath = None
70
71 __del__ = cleanup