[game-data-packager] 01/02: add support for virtual multilang packages

Alexandre Detiste detiste-guest at moszumanska.debian.org
Tue Apr 14 14:21:42 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 99a078cfbc20f5b607c7828ddd37fd345f78e96e
Author: Alexandre Detiste <alexandre.detiste at gmail.com>
Date:   Tue Apr 14 16:16:41 2015 +0200

    add support for virtual multilang packages
---
 game_data_packager/__init__.py | 27 ++++++++++++++++++++++++++-
 game_data_packager/util.py     | 14 ++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/game_data_packager/__init__.py b/game_data_packager/__init__.py
index 69639bf..6639b94 100644
--- a/game_data_packager/__init__.py
+++ b/game_data_packager/__init__.py
@@ -51,6 +51,7 @@ from .util import (MEBIBYTE,
         rm_rf,
         human_size,
         is_installed,
+        prefered_lang,
         which)
 from .version import GAME_PACKAGE_VERSION
 
@@ -342,6 +343,9 @@ class GameDataPackage(object):
         # This optional value will overide the game global copyright
         self.copyright = None
 
+        # Language, ISO-639 code
+        self.lang = 'en'
+
         # Where we install files.
         # For instance, if this is 'usr/share/games/quake3' and we have
         # a WantedFile with install_as='baseq3/pak1.pk3' then we would
@@ -764,7 +768,7 @@ class GameData(object):
         for k in ('expansion_for', 'longname', 'symlinks', 'install_to',
                 'install_to_docdir', 'install_contents_of', 'steam', 'debian',
                 'rip_cd', 'architecture', 'aliases', 'better_version',
-                'copyright', 'engine', 'gog', 'origin'):
+                'copyright', 'engine', 'gog', 'origin', 'lang'):
             if k in d:
                 setattr(package, k, d[k])
 
@@ -2335,6 +2339,27 @@ class GameData(object):
         if not possible:
             raise NoPackagesPossible()
 
+        # keep only prefered language
+        if len(possible) > 1:
+            for lang in prefered_lang():
+                for package in set(possible):
+                    if package.lang == lang:
+                        continue
+                    virtual = package.debian.get('provides')
+                    if not virtual:
+                        continue
+                    for other_package in possible:
+                        if other_package.name == package.name:
+                            continue
+                        other_virtual = other_package.debian.get('provides')
+                        if other_virtual != virtual:
+                            continue
+                        logger.info('discarding %s '
+                                    'because %s is prefered language',
+                                     package.name, lang)
+                        possible.discard(package)
+                        break
+
         ready = set()
 
         for package in possible:
diff --git a/game_data_packager/util.py b/game_data_packager/util.py
index 809c96b..691a517 100644
--- a/game_data_packager/util.py
+++ b/game_data_packager/util.py
@@ -90,3 +90,17 @@ def is_installed(package):
              or is_installed('doomsday'))
 
     return os.path.isdir(os.path.join('/usr/share/doc', package))
+
+def prefered_lang():
+    lang_pref = []
+    if 'LANGUAGE' in os.environ:
+        for lang in os.getenv('LANGUAGE').split(':'):
+            if lang and lang not in lang_pref:
+                lang_pref.append(lang.split('_')[0])
+    if 'LANG' in os.environ:
+        lang = os.getenv('LANG').split('_')[0]
+        if lang and lang != 'C' and lang not in lang_pref:
+            lang_pref.append(lang)
+    if 'en' not in lang_pref:
+        lang_pref.append('en')
+    return lang_pref

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