[game-data-packager] 01/01: scummvm: auto-generate language auto-detection shell-script

Alexandre Detiste detiste-guest at moszumanska.debian.org
Sun Jun 21 21:07:11 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 19f0e5330e619aad031f0845ec5baef14703bece
Author: Alexandre Detiste <alexandre.detiste at gmail.com>
Date:   Sun Jun 21 23:05:54 2015 +0200

    scummvm: auto-generate language auto-detection shell-script
---
 data/kyrandia2.yaml                        |  1 +
 data/kyrandia3.yaml                        |  1 +
 data/scummvm-common.desktop.in             |  9 -----
 game_data_packager/games/scummvm_common.py | 59 +++++++++++++++++++++++-------
 4 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/data/kyrandia2.yaml b/data/kyrandia2.yaml
index 81b6d6b..8844a64 100644
--- a/data/kyrandia2.yaml
+++ b/data/kyrandia2.yaml
@@ -6,6 +6,7 @@ gameid: kyra2
 
 packages:
   kyrandia2-data:
+    langs: [en,de,fr]
     gog:
       url: legend_of_kyrandia
       game: legend_of_kyrandia_hand_of_fate
diff --git a/data/kyrandia3.yaml b/data/kyrandia3.yaml
index fd25a7e..42d2172 100644
--- a/data/kyrandia3.yaml
+++ b/data/kyrandia3.yaml
@@ -6,6 +6,7 @@ gameid: kyra3
 
 packages:
   kyrandia3-data:
+    langs: [en,de,fr]
     gog:
       url: legend_of_kyrandia
       game: legend_of_kyrandia_malcolms_revenge
diff --git a/data/scummvm-common.desktop.in b/data/scummvm-common.desktop.in
deleted file mode 100644
index 8e8e398..0000000
--- a/data/scummvm-common.desktop.in
+++ /dev/null
@@ -1,9 +0,0 @@
-[Desktop Entry]
-Name=LONG
-GenericName=Adventure Game
-TryExec=scummvm
-Exec=scummvm -p /PATH GAME
-Icon=scummvm
-Terminal=false
-Type=Application
-Categories=Game
diff --git a/game_data_packager/games/scummvm_common.py b/game_data_packager/games/scummvm_common.py
index 90c5bb2..ccd6723 100644
--- a/game_data_packager/games/scummvm_common.py
+++ b/game_data_packager/games/scummvm_common.py
@@ -16,12 +16,12 @@
 # You can find the GPL license text on a Debian system under
 # /usr/share/common-licenses/GPL-2.
 
+import configparser
 import logging
 import os
 
 from .. import GameData
-from ..paths import DATADIR
-from ..util import (TemporaryUmask, copy_with_substitutions, mkdir_p)
+from ..util import mkdir_p
 
 logger = logging.getLogger('game-data-packager.games.scummvm-common')
 
@@ -45,24 +45,30 @@ class ScummvmGameData(GameData):
     def _populate_package(self, package, d):
         super(ScummvmGameData, self)._populate_package(package, d)
         package.gameid = d.get('gameid')
+        package.langs = d.get('langs',['en'])
+        assert type(package.langs) is list
 
     def fill_extra_files(self, package, destdir):
         super(ScummvmGameData, self).fill_extra_files(package, destdir)
         if package.type == 'expansion':
             return
 
-        with TemporaryUmask(0o022):
-            appdir = os.path.join(destdir, 'usr/share/applications')
-            mkdir_p(appdir)
-            from_ = os.path.join(DATADIR, 'scummvm-common.desktop.in')
-            copy_with_substitutions(open(from_,
-                    encoding='utf-8'),
-                        open(os.path.join(appdir, '%s.desktop' % package.name),
-                            'w', encoding='utf-8'),
-                        GAME=package.gameid or self.gameid,
-                        PATH=package.install_to,
-                        LONG=(package.longname or self.longname))
+        appdir = os.path.join(destdir, 'usr/share/applications')
+        mkdir_p(appdir)
 
+        desktop = configparser.RawConfigParser()
+        desktop.optionxform = lambda option: option
+        desktop['Desktop Entry'] = {}
+        entry = desktop['Desktop Entry']
+        entry['Name'] = package.longname or self.longname
+        entry['GenericName'] = self.genre + ' game'
+        entry['TryExec'] = 'scummvm'
+        entry['Icon'] = 'scummvm'
+        entry['Terminal'] = 'false'
+        entry['Categories'] = 'game'
+        gameid = package.gameid or self.gameid
+        if package.langs == ['en']:
+            entry['Exec'] = 'scummvm -p /%s %s' % (package.install_to, gameid)
             lintiandir = os.path.join(destdir, 'usr/share/lintian/overrides')
             mkdir_p(lintiandir)
             with open(os.path.join(lintiandir, package.name),
@@ -70,5 +76,32 @@ class ScummvmGameData(GameData):
                  o.write('%s: desktop-command-not-in-package '
                          'usr/share/applications/%s.desktop scummvm\n'
                          % (package.name, package.name))
+        else:
+            pgm = package.name[0:len(package.name)-len('-data')]
+            entry['Exec'] = pgm
+            bindir = os.path.join(destdir, 'usr/games')
+            mkdir_p(bindir)
+            path = os.path.join(bindir, pgm)
+            if 'en' not in package.langs:
+                package.langs.append('en')
+            with open(path, 'w') as f:
+                f.write('#!/bin/sh\n')
+                f.write('GAME_LANG=$(\n')
+                f.write("echo $LANGUAGE $LANG en | tr ': ' '\\n' | cut -c1-2 | while read lang\n")
+                f.write('do\n')
+                for lang in package.langs:
+                    f.write('[ "$lang" = "%s" ] && echo $lang && return\n' % lang)
+                f.write('done\n')
+                f.write(')\n')
+                f.write('if [ "$GAME_LANG" = "en" ]; then\n')
+                f.write('  scummvm -p /%s %s\n' % (package.install_to, gameid))
+                f.write('else\n')
+                f.write('  scummvm -q $GAME_LANG -p /%s %s\n' % (package.install_to, gameid))
+                f.write('fi\n')
+            os.chmod(path, 0o755)
+
+        with open(os.path.join(appdir, '%s.desktop' % package.name),
+                  'w', encoding='utf-8') as output:
+             desktop.write(output, space_around_delimiters=False)
 
 GAME_DATA_SUBCLASS = ScummvmGameData

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