[game-data-packager] 01/11: read only one YAML when user specify an existing game (#779937)

Alexandre Detiste detiste-guest at moszumanska.debian.org
Fri Jun 5 07:57:20 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 3f39b141d36e956a4184224489e3be9dcad9d654
Author: Alexandre Detiste <alexandre.detiste at gmail.com>
Date:   Tue Jun 2 12:49:57 2015 +0200

    read only one YAML when user specify an existing game (#779937)
    
    Now, a dict with shortname + longname could be precomputed somewhere
    to make 'game-data-packager' & 'game-data-packager --help' faster too.
---
 debian/changelog               |  3 ++-
 game_data_packager/__init__.py | 26 +++++++++++++++++++++-----
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index c86843c..166181d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -11,7 +11,8 @@ game-data-packager (42) UNRELEASED; urgency=medium
   * add support for Gobliiins (full game & demo)
   * add support for Leisure Suit Larry 1,2,3,5&6
   * add support for Compet-N PWAD's (Closes: #776061)
-  
+  * only load actually needed YAML files (Closes: #779937)
+
  -- Simon McVittie <smcv at debian.org>  Sun, 03 May 2015 14:34:00 +0200
 
 game-data-packager (41) unstable; urgency=medium
diff --git a/game_data_packager/__init__.py b/game_data_packager/__init__.py
index 28bdf42..c9699b9 100644
--- a/game_data_packager/__init__.py
+++ b/game_data_packager/__init__.py
@@ -2792,11 +2792,12 @@ def iter_fat_mounts(folder):
             if type in ('fat','vfat', 'ntfs'):
                 yield os.path.join(mount, 'Program Files', folder)
 
-def load_games(workdir=None):
+def load_games(workdir=None,game='*'):
     games = {}
 
-    for jsonfile in glob.glob(os.path.join(DATADIR, '*.json')):
-        if sys.stderr.isatty(): print('.', end='', flush=True, file=sys.stderr)
+    for jsonfile in glob.glob(os.path.join(DATADIR, game + '.json')):
+        if game == '*' and sys.stderr.isatty():
+            print('.', end='', flush=True, file=sys.stderr)
         try:
             g = os.path.basename(jsonfile)
             g = g[:len(g) - 5]
@@ -2876,6 +2877,23 @@ def run_command_line():
             dest='verbose', help='hide output from external '
              'tools (default)')
 
+
+    class DumbParser(argparse.ArgumentParser):
+        def error(self, message):
+            pass
+
+    dumb_parser = DumbParser(parents=(base_parser,),add_help=False)
+    dumb_parser.add_argument('game', type=str, nargs='?')
+    dumb_parser.add_argument('paths', type=str, nargs='*')
+    dumb_parser.add_argument('-h', '--help', action='store_true', dest='h')
+    g = dumb_parser.parse_args().game
+    if g is None:
+        games = load_games(None)
+    elif os.path.isfile(os.path.join(DATADIR, '%s.json' % g)):
+        games = load_games(None, game=g)
+    else:
+        games = load_games(None)
+
     parser = argparse.ArgumentParser(prog='game-data-packager',
             description='Package game files.', parents=(base_parser,),
             epilog='Run "game-data-packager GAME --help" to see ' +
@@ -2884,8 +2902,6 @@ def run_command_line():
     game_parsers = parser.add_subparsers(dest='shortname',
             title='supported games', metavar='GAME')
 
-    games = load_games(None)
-
     for g in sorted(games.keys()):
         games[g].add_parser(game_parsers, base_parser)
 

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