accept unknown .deb / .tar.gz

Alexandre Detiste alexandre.detiste at gmail.com
Mon May 25 13:05:53 UTC 2015


Hi,

I've added logic to repack the ugly GOG.com .deb provides for ROTT
("chmod 666 /opt/... " all the way!) into a clean one.

Like for the RAR files, I'm tempted to accept unknown .tar.gz or .deb
but it sometimes doesn't work.

-----------------------------------------------------------------------------------------


http://bugs.python.org/issue10436



./run wolf3d --no-search
./run wolf3d --no-search --no-download wolf3d-demo-data_42_all.deb

-> tarfile.StreamError: seeking backwards is not allowed

repacking other .deb's that way does work

diff --git a/game_data_packager/__init__.py b/game_data_packager/__init__.py
index ca5bd3d..ff233ae 100644
--- a/game_data_packager/__init__.py
+++ b/game_data_packager/__init__.py
@@ -1074,6 +1074,16 @@ class GameData(object):
             if os.path.splitext(path)[1].lower() == '.zip':
                 with zipfile.ZipFile(path, 'r') as zf:
                     self.consider_zip(path, zf)
+            elif path.lower().endswith('.tar.gz'):
+                rf = open(path, 'rb')
+                with tarfile.open(path, mode='r|gz', fileobj=rf) as tar:
+                    self.consider_tar_stream(path, tar)
+            elif os.path.splitext(path)[1].lower() == '.deb':
+                with subprocess.Popen(['dpkg-deb', '--fsys-tarfile', path],
+                            stdout=subprocess.PIPE) as fsys_process:
+                    with tarfile.open(path + '//data.tar.*', mode='r|',
+                           fileobj=fsys_process.stdout) as tar:
+                        self.consider_tar_stream(path, tar)
 
     def _log_not_any_of(self, path, size, hashes, why, candidates):
         message = ('found %s but it is not one of the expected ' +
@@ -1222,14 +1232,19 @@ class GameData(object):
                 logger.error('%s should have provided %s but did not',
                         name, missing)
 
-    def consider_tar_stream(self, name, tar, provider):
-        should_provide = set(provider.provides)
+    def consider_tar_stream(self, name, tar, provider=None):
+        if provider is None:
+            try_to_unpack = self.files
+            should_provide = set()
+        else:
+            try_to_unpack = provider.provides
+            should_provide = set(try_to_unpack)
 
         for entry in tar:
             if not entry.isfile():
                 continue
 
-            for filename in provider.provides:
+            for filename in try_to_unpack:
                 wanted = self.files.get(filename)
 
                 if wanted is None:



More information about the Pkg-games-devel mailing list