[game-data-packager] 11/17: gdp.unpack: add format property and seekable method
Simon McVittie
smcv at debian.org
Wed Dec 30 22:57:22 UTC 2015
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch master
in repository game-data-packager.
commit b878c129044ffcd0fb1e3e1bba511d111926e850
Author: Simon McVittie <smcv at debian.org>
Date: Wed Dec 30 22:34:39 2015 +0000
gdp.unpack: add format property and seekable method
---
game_data_packager/unpack/__init__.py | 31 +++++++++++++++++++++++++++++++
game_data_packager/unpack/umod.py | 8 ++++++++
2 files changed, 39 insertions(+)
diff --git a/game_data_packager/unpack/__init__.py b/game_data_packager/unpack/__init__.py
index 54cf3a7..f08ff85 100644
--- a/game_data_packager/unpack/__init__.py
+++ b/game_data_packager/unpack/__init__.py
@@ -94,6 +94,13 @@ class StreamUnpackable(metaclass=ABCMeta):
"""Iterate through UnpackableEntry objects."""
raise NotImplementedError
+ @property
+ @abstractmethod
+ def format(self):
+ """Return the YAML "format" entry for this file.
+ """
+ raise NotImplementedError
+
@abstractmethod
def open(self, member):
"""Open a binary file-like entry for the name or entry.
@@ -162,6 +169,11 @@ class StreamUnpackable(metaclass=ABCMeta):
print('%s %s %s %s' % (entry.type_indicator, size, mtime,
shlex.quote(entry.name)))
+ def seekable(self):
+ """Return True if the unpacker is able to seek.
+ """
+ return False
+
class WrapperUnpacker(StreamUnpackable):
"""Base class for a StreamUnpackable that wraps a TarFile-like object."""
@@ -221,6 +233,8 @@ class TarEntry(UnpackableEntry):
class TarUnpacker(WrapperUnpacker):
def __init__(self, name, reader=None, compression='*', skip=0):
super(TarUnpacker, self).__init__()
+ self.skip = skip
+ self.compression = compression
if reader is None:
reader = open(name, 'rb')
@@ -232,6 +246,10 @@ class TarUnpacker(WrapperUnpacker):
self._impl = tarfile.open(name, mode='r|' + compression,
fileobj=reader)
+ @property
+ def format(self):
+ return 'tar.' + self.compression
+
def open(self, entry):
assert isinstance(entry, TarEntry)
return self._impl.extractfile(entry.impl)
@@ -271,6 +289,12 @@ class ZipEntry(UnpackableEntry):
class ZipUnpacker(WrapperUnpacker):
def __init__(self, file_or_name):
super(ZipUnpacker, self).__init__()
+ if hasattr(file_or_name, 'seekable') and not file_or_name.seekable():
+ self.__seekable = False
+ else:
+ # zip files based on an on-disk file are seekable
+ self.__seekable = True
+
self._impl = zipfile.ZipFile(file_or_name, 'r')
def __iter__(self):
@@ -282,3 +306,10 @@ class ZipUnpacker(WrapperUnpacker):
def _wrap_entry(self, entry):
return ZipEntry(self)
+
+ @property
+ def format(self):
+ return 'zip'
+
+ def seekable(self):
+ return self.__seekable
diff --git a/game_data_packager/unpack/umod.py b/game_data_packager/unpack/umod.py
index a0bc84b..086765f 100644
--- a/game_data_packager/unpack/umod.py
+++ b/game_data_packager/unpack/umod.py
@@ -454,6 +454,14 @@ class Umod(StreamUnpackable):
return -value
return value
+ @property
+ def format(self):
+ return 'umod'
+
+ def seekable(self):
+ # umods are always seekable
+ return True
+
def is_umod(path_or_file):
try:
_open(path_or_file)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git
More information about the Pkg-games-commits
mailing list