[game-data-packager] 01/01: unzip produce mojibake, specify encoding in yaml and decode comment in python

Alexandre Detiste detiste-guest at moszumanska.debian.org
Mon May 18 06:53:18 UTC 2015


This is an automated email from the git hooks/post-receive script.

detiste-guest pushed a commit to branch master
in repository game-data-packager.

commit c98e7e0ce7ea9d6bc6e91c73e4cddc5639083bc0
Author: Alexandre Detiste <alexandre.detiste at gmail.com>
Date:   Mon May 18 08:51:49 2015 +0200

    unzip produce mojibake, specify encoding in yaml and decode comment in python
---
 data/wolf3d.yaml               |  1 +
 game_data_packager/__init__.py | 15 +++++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/data/wolf3d.yaml b/data/wolf3d.yaml
index f795728..48bafb9 100644
--- a/data/wolf3d.yaml
+++ b/data/wolf3d.yaml
@@ -114,6 +114,7 @@ files:
     sha256: df595db7ded05a7af36f8c7cbbf136366ffb5ab9d765325b104d27ad8fc00924
     unpack:
       format: unzip
+      encoding: cp437
       # 'zip' trigger this: NotImplementedError: compression type 6 (implode)
       unpack:
       - maphead.wl6
diff --git a/game_data_packager/__init__.py b/game_data_packager/__init__.py
index 3d295e7..2774af0 100644
--- a/game_data_packager/__init__.py
+++ b/game_data_packager/__init__.py
@@ -1168,11 +1168,6 @@ class GameData(object):
         else:
             try_to_unpack = provider.provides
             should_provide = set(try_to_unpack)
-            # an unknown file could maybe include
-            # a malicious ANSI escape sequence
-            if VERBOSE and zf.comment:
-                print(zf.comment)
-
 
         for entry in zf.infolist():
             if not entry.file_size:
@@ -1487,6 +1482,14 @@ class GameData(object):
                         provider_name, found_name)
                 fmt = provider.unpack['format']
 
+                if VERBOSE and fmt in ('zip', 'unzip'):
+                    with zipfile.ZipFile(found_name, 'r') as zf:
+                        if zf.comment:
+                            try:
+                                print(zf.comment.decode(provider.unpack.get('encoding', 'utf-8')))
+                            except (UnicodeDecodeError,UnicodeEncodeError):
+                                logger.warning("can't decode zip comment")
+
                 if fmt == 'dos2unix':
                     tmp = os.path.join(self.get_workdir(),
                             'tmp', wanted.name)
@@ -1618,7 +1621,7 @@ class GameData(object):
                     tmpdir = os.path.join(self.get_workdir(), 'tmp',
                             provider_name + '.d')
                     mkdir_p(tmpdir)
-                    quiet = [] if VERBOSE else ['-qq']
+                    quiet = ['-q'] if VERBOSE else ['-qq']
                     subprocess.check_call(['unzip', '-j', '-C', '-LL'] +
                                 quiet + [os.path.abspath(found_name)] +
                             list(to_unpack), cwd=tmpdir)

-- 
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