Package.__init__(self, pakfire, repo)
self.filename = filename
- # Place to keep the tarfile handle and cache the metadata
- self._archive = None
+ # Place to cache the metadata
self._metadata = {}
self.check()
def __repr__(self):
return "<%s %s>" % (self.__class__.__name__, self.filename)
- def __del__(self):
- # Close tarfile handle
- if self._archive:
- self._archive.close()
-
@property
def local(self):
# A file package is always local.
return True
- @property
- def archive(self):
- if not self._archive:
- self._archive = tarfile.open(self.filename)
-
- return self._archive
-
- def get_file(self, name):
- """
- Return a file-object for the given filename.
-
- If the file does not exist KeyError is raised.
- """
- return self.archive.extractfile(name)
+ def open_archive(self):
+ return tarfile.open(self.filename)
@property
def file_version(self):
Read-in the metadata from the "info" file and cache it in _metadata.
"""
if not self._metadata:
- f = self.get_file("info")
+ a = self.open_archive()
+ f = a.extractfile("info")
for line in f.readlines():
m = re.match(r"^(\w+)=(.*)$", line)
self._metadata[key] = val.strip("\"")
f.close()
+ a.close()
return self._metadata
return os.path.getsize(self.filename)
def __filelist_from_metadata(self):
- f = self.get_file("filelist")
+ a = self.open_archive()
+ f = a.extractfile("filelist")
ret = []
for line in f.readlines():
ret.append(line)
f.close()
+ a.close()
return ret
# XXX expect uncompressed payload for now
# this is very simple and very slow
- t = tarfile.open(fileobj=self.get_file("data.img"))
+ a = self.open_archive()
+ f = a.extractfile("data.img")
+ t = tarfile.open(fileobj=f)
ret = ["/%s" % n for n in t.getnames()]
t.close()
+ f.close()
+ a.close()
return ret
"""
ret = None
try:
- f = self.get_file("signature")
+ a = self.open_archive()
+ f = a.extractfile("signature")
+
ret = f.read()
+
f.close()
+ a.close()
except KeyError:
# signature file could not be found
"""
ret = None
try:
- f = self.get_file("control")
+ a = self.open_archive()
+ f = a.extractfile("control")
+
ret = f.read()
+
f.close()
+ a.close()
except KeyError:
# scriptlet file could not be found