[game-data-packager] 15/39: Add the ability to load a GameData subclass for particular games

Simon McVittie smcv at debian.org
Sun Jan 11 01:52: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 7516067db67b6453d356974983dd4d1666fc25ce
Author: Simon McVittie <smcv at debian.org>
Date:   Sat Jan 10 19:15:42 2015 +0000

    Add the ability to load a GameData subclass for particular games
    
    This lets us do things like Tyrian's special command-line parsing.
---
 lib/game_data_packager/__init__.py       | 11 ++++++++--
 lib/game_data_packager/games/__init__.py |  0
 lib/game_data_packager/games/tyrian.py   | 37 ++++++++++++++++++++++++++++++++
 supported/tyrian                         | 35 +-----------------------------
 4 files changed, 47 insertions(+), 36 deletions(-)

diff --git a/lib/game_data_packager/__init__.py b/lib/game_data_packager/__init__.py
index f02e6ca..c7ec5a9 100644
--- a/lib/game_data_packager/__init__.py
+++ b/lib/game_data_packager/__init__.py
@@ -1080,7 +1080,7 @@ class GameData(object):
         self.compress_deb = (self.compress_deb and
                 getattr(args, 'compress', True))
 
-        if args.repack:
+        if getattr(args, 'repack', False):
             can_repack = False
             absent = set()
 
@@ -1243,7 +1243,14 @@ def run_command_line():
         g = os.path.basename(yamlfile)
         g = g[:len(g) - 5]
 
-        games[g] = GameData(g, datadir=datadir, etcdir=etcdir,
+        try:
+            plugin = importlib.import_module('game_data_packager.games.%s' % g)
+            game_data_constructor = plugin.GAME_DATA_SUBCLASS
+        except (ImportError, AttributeError) as e:
+            logger.debug('No special code for %s: %s', g, e)
+            game_data_constructor = GameData
+
+        games[g] = game_data_constructor(g, datadir=datadir, etcdir=etcdir,
                 workdir=workdir)
 
     game_parsers = parser.add_subparsers(dest='shortname',
diff --git a/lib/game_data_packager/games/__init__.py b/lib/game_data_packager/games/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/lib/game_data_packager/games/tyrian.py b/lib/game_data_packager/games/tyrian.py
new file mode 100644
index 0000000..4e3ec9a
--- /dev/null
+++ b/lib/game_data_packager/games/tyrian.py
@@ -0,0 +1,37 @@
+#!/usr/bin/python3
+# vim:set fenc=utf-8:
+#
+# Copyright © 2014 Simon McVittie <smcv at debian.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# You can find the GPL license text on a Debian system under
+# /usr/share/common-licenses/GPL-2.
+
+import logging
+
+from .. import GameData
+
+logger = logging.getLogger('game-data-packager.games.tyrian')
+
+class TyrianGameData(GameData):
+    def add_parser(self, parsers):
+        parser = parsers.add_parser(self.shortname,
+                help=self.longname)
+        parser.add_argument('-f', action='append', dest='paths',
+                help='Path to tyrian21.zip')
+        parser.add_argument('-w', dest='download', action='store_true',
+                help='Download tyrian21.zip (done automatically if necessary)')
+        parser.add_argument('--repack', action='store_true',
+                help='Locate installed game files automatically')
+        parser.add_argument('paths', nargs='*',
+                metavar='DIRECTORY|FILE')
+
+GAME_DATA_SUBCLASS = TyrianGameData
diff --git a/supported/tyrian b/supported/tyrian
index 91de79c..f91b307 100644
--- a/supported/tyrian
+++ b/supported/tyrian
@@ -4,39 +4,6 @@ deb=tyrian-data
 
 . $LIBDIR/via-python
 
-tyrian_usage() {
-	echo "game-data-packager ${SHORTNAME} arguments:"
-	printf "\tgame-data-packager ${SHORTNAME} [ -f path ] | [ -w ]
-\t\t-f path\t\tpath to your existing copy of tyrian21.zip\n\
-\t\t-w\t\tfetch tyrian21.zip from the World Wide Web\n"
-}
-
 go() {
-    case $# in
-        0)
-            tyrian_usage
-            exit 0
-            ;;
-        1)
-            if [ "$1" != "-w" ]; then
-                    usage >&2
-                    tyrian_usage >&2
-                    exit 1
-            fi
-            gdp_data_driven tyrian --
-            ;;
-        2)
-            if [ "$1" != "-f" ]; then
-                usage >&2
-                tyrian_usage >&2
-                exit 1
-            fi
-            gdp_data_driven tyrian "$2"
-            ;;
-        *)
-            usage >&2
-            tyrian_usage >&2
-            exit 1
-            ;;
-    esac
+    gdp_data_driven tyrian "$@"
 }

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