[game-data-packager] 33/51: load_game: Return the game instead of putting it in a dict

Simon McVittie smcv at debian.org
Fri Dec 29 01:23:37 UTC 2017


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 66c3f9c0dade43186cfbc09db0fa1132051ddb6b
Author: Simon McVittie <smcv at debian.org>
Date:   Thu Dec 28 16:07:07 2017 +0000

    load_game: Return the game instead of putting it in a dict
    
    Signed-off-by: Simon McVittie <smcv at debian.org>
---
 game_data_packager/game.py | 29 ++++++++++++++++++++---------
 tools/check_equivalence.py |  6 ++----
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/game_data_packager/game.py b/game_data_packager/game.py
index e5216c2..342bed6 100644
--- a/game_data_packager/game.py
+++ b/game_data_packager/game.py
@@ -1091,7 +1091,11 @@ def load_games(game='*', datadir=DATADIR, use_vfs=True):
         if os.path.basename(yamlfile).startswith('launch-'):
             continue
 
-        load_game(progress, games, yamlfile, None, yaml_file=yamlfile)
+        name = os.path.basename(yamlfile)
+        assert name.endswith('.yaml'), yamlfile
+        name = name[:-5]
+
+        games[name] = load_game(progress, yamlfile, None, yaml_file=yamlfile)
 
     if use_vfs:
         if isinstance(use_vfs, str):
@@ -1103,20 +1107,23 @@ def load_games(game='*', datadir=DATADIR, use_vfs=True):
             if game == '*':
                 for entry in zf.infolist():
                     if entry.filename.endswith('.json'):
-                        if entry.filename[:-5] in games:
+                        name = entry.filename[:-5]
+
+                        if name in games:
                             # shadowed by a YAML file
                             continue
 
                         jsonfile = '%s/%s' % (zip, entry.filename)
                         jsondata = zf.open(entry).read().decode('utf-8')
-                        load_game(progress, games, jsonfile, jsondata)
+                        games[name] = load_game(progress, jsonfile, jsondata)
             elif game in games:
                 # shadowed by a YAML file
                 pass
             else:
                 jsonfile = game + '.json'
                 jsondata = zf.open(jsonfile).read().decode('utf-8')
-                load_game(progress, games, '%s/%s' % (zip, jsonfile), jsondata)
+                games[game] = load_game(
+                        progress, '%s/%s' % (zip, jsonfile), jsondata)
     else:
         vfs = os.path.join(DATADIR, 'vfs')
 
@@ -1124,19 +1131,21 @@ def load_games(game='*', datadir=DATADIR, use_vfs=True):
             vfs = DATADIR
 
         for jsonfile in glob.glob(os.path.join(vfs, game + '.json')):
-            if os.path.basename(jsonfile[:-5]) in games:
+            name = os.path.basename(jsonfile[:-5])
+
+            if name in games:
                 # shadowed by a YAML file
                 continue
 
             jsondata = open(jsonfile, encoding='utf-8').read()
-            load_game(progress, games, jsonfile, jsondata)
+            games[name] = load_game(progress, jsonfile, jsondata)
 
     if progress:
         print('\r%s\r' % (' ' * (len(games) // 4 + 1)), end='', flush=True, file=sys.stderr)
 
     return games
 
-def load_game(progress, games, filename, content, name=None, yaml_file=None):
+def load_game(progress, filename, content, name=None, yaml_file=None):
         if progress:
             animation = ['.','-','*','#']
             modulo = int(load_game.counter) % len(animation)
@@ -1170,10 +1179,12 @@ def load_game(progress, games, filename, content, name=None, yaml_file=None):
                 assert 'game_data_packager.games' in e.msg, e
                 game_data_constructor = GameData
 
-            games[name] = game_data_constructor(name, data)
+            game = game_data_constructor(name, data)
 
             if yaml_file is not None:
-                games[name].yaml_file = yaml_file
+                game.yaml_file = yaml_file
+
+            return game
         except:
             print('Error loading %s:\n' % filename)
             raise
diff --git a/tools/check_equivalence.py b/tools/check_equivalence.py
index 85c128b..8664c05 100755
--- a/tools/check_equivalence.py
+++ b/tools/check_equivalence.py
@@ -151,12 +151,10 @@ if __name__ == '__main__':
         with open('out/%s-unexpanded.txt' % name, 'w') as writer:
             writer.write(json_to_json_unexpanded)
 
-        json_to_json_games = {}
         # JSON is a subset of YAML so we can treat this as if YAML
-        load_game(
-            False, json_to_json_games, 'out/%s-unexpanded.txt' % name,
+        json_to_json_game = load_game(
+            False, 'out/%s-unexpanded.txt' % name,
             None, name=name, yaml_file='out/%s-unexpanded.txt' % name)
-        json_to_json_game = json_to_json_games[name]
         json_to_json_game.load_file_data()
 
         json_to_json_to_data = json_to_json_game.to_data()

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