From 1b1a5e31e296546ac89fb1e4a665ab24c1c573f5 Mon Sep 17 00:00:00 2001 From: skomoroh Date: Wed, 8 Nov 2006 23:28:56 +0000 Subject: [PATCH] * accelerated game registration git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@90 efabe8c0-fbe8-4139-b769-b5e6d273206e --- Makefile | 1 + pysollib/gamedb.py | 16 +++++++++++----- pysollib/init.py | 9 +++++++++ pysollib/main.py | 15 +++++++++------ pysollib/settings.py | 2 ++ 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 2f182e32..de785276 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ # Makefile for PySolFC override LANG=C +override PYSOL_DEBUG=1 PYSOLLIB_FILES=pysollib/tk/*.py pysollib/*.py \ pysollib/games/*.py pysollib/games/special/*.py \ diff --git a/pysollib/gamedb.py b/pysollib/gamedb.py index b0baddfa..9e2e9c44 100644 --- a/pysollib/gamedb.py +++ b/pysollib/gamedb.py @@ -40,6 +40,7 @@ import sys, imp, os, types # PySol imports from mfxutil import Struct, latin1_to_ascii from resource import CSI +from settings import CHECK_GAMES gettext = _ n_ = lambda x: x @@ -486,11 +487,8 @@ class GameManager: def get(self, key): return self.__all_games.get(key) - def register(self, gi): - ##print gi.id, gi.short_name - if not isinstance(gi, GameInfo): - raise GameInfoException, "wrong GameInfo class" - gi.plugin = self.loading_plugin + def _check_game(self, gi): + ##print 'check game:', gi.id, gi.short_name.encode('utf-8') if self.__all_games.has_key(gi.id): raise GameInfoException, "duplicate game ID %s: %s and %s" % \ (gi.id, str(gi.gameclass), @@ -508,6 +506,14 @@ class GameManager: if self.__all_gamenames.has_key(n): raise GameInfoException, "duplicate game altname %s: %s" % \ (gi.id, n) + + def register(self, gi): + ##print gi.id, gi.short_name.encode('utf-8') + if not isinstance(gi, GameInfo): + raise GameInfoException, "wrong GameInfo class" + gi.plugin = self.loading_plugin + if self.loading_plugin or CHECK_GAMES: + self._check_game(gi) ##if 0 and gi.si.game_flags & GI.GT_XORIGINAL: ## return ##print gi.id, gi.name diff --git a/pysollib/init.py b/pysollib/init.py index 9294ff01..f5a67758 100644 --- a/pysollib/init.py +++ b/pysollib/init.py @@ -51,6 +51,15 @@ def init(): ##if locale_dir: locale_dir = os.path.normpath(locale_dir) gettext.install('pysol', locale_dir, unicode=True) + if os.environ.has_key('PYSOL_CHECK_GAMES') or \ + os.environ.has_key('PYSOL_DEBUG'): + settings.CHECK_GAMES = True + if os.environ.has_key('PYSOL_DEBUG'): + try: + settings.DEBUG = int(os.environ['PYSOL_DEBUG']) + except: + settings.DEBUG = 1 + ## init toolkit if '--gtk' in sys.argv: settings.TOOLKIT = 'gtk' diff --git a/pysollib/main.py b/pysollib/main.py index 2026f297..56a9f410 100644 --- a/pysollib/main.py +++ b/pysollib/main.py @@ -43,6 +43,7 @@ import gettext # PySol imports from mfxutil import destruct, EnvError from util import CARDSET, DataLoader +import settings from settings import PACKAGE, TOOLKIT, VERSION, SOUND_MOD from resource import Tile from gamedb import GI @@ -110,7 +111,7 @@ def parse_option(argv): "noplugins": False, "nosound": False, "sound-mod": None, - "debug": 0, + "debug": None, } for i in optlist: if i[0] in ("-h", "--help"): @@ -137,7 +138,10 @@ def parse_option(argv): assert i[1] in ('pss', 'pygame', 'oss', 'win') opts["sound-mod"] = i[1] elif i[0] in ("-D", "--debug"): - opts["debug"] = i[1] + try: + opts["debug"] = int(i[1]) + except: + print >> sys.stderr, 'WARNING: invalid argument for debug' if opts["help"]: print _("""Usage: %s [OPTIONS] [FILE] @@ -202,10 +206,9 @@ def pysol_init(app, args): app.commandline.gameid = int(opts['gameid']) except: print >> sys.stderr, 'WARNING: invalid game id:', opts['gameid'] - try: - app.debug = int(opts['debug']) - except: - print >> sys.stderr, 'invalid argument for debug' + if not opts['debug'] is None: + settings.DEBUG = opts['debug'] + app.debug = settings.DEBUG # init games database import games diff --git a/pysollib/settings.py b/pysollib/settings.py index 25759f8a..c1137aab 100644 --- a/pysollib/settings.py +++ b/pysollib/settings.py @@ -57,3 +57,5 @@ if os.name == 'mac': TOP_SIZE = 10 TOP_TITLE = n_('Top 10') +DEBUG = 0 # must be integer +CHECK_GAMES = False