[game-data-packager] 12/51: GameData: When loaded from YAML, get per-file details from same YAML
Simon McVittie
smcv at debian.org
Fri Dec 29 01:23:35 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 17873cdb670fb578b05203118fa241e196cccd43
Author: Simon McVittie <smcv at debian.org>
Date: Tue Dec 26 17:00:45 2017 +0000
GameData: When loaded from YAML, get per-file details from same YAML
Signed-off-by: Simon McVittie <smcv at debian.org>
---
game_data_packager/__init__.py | 39 ++++++++++++++++++++++++---------------
1 file changed, 24 insertions(+), 15 deletions(-)
diff --git a/game_data_packager/__init__.py b/game_data_packager/__init__.py
index 2d6c226..9dab182 100644
--- a/game_data_packager/__init__.py
+++ b/game_data_packager/__init__.py
@@ -128,6 +128,9 @@ class GameData(object):
# list: arbitrary options (e.g. -z9 -Zgz -Sfixed)
self.compression = True
+ # YAML filename to use, overriding normal search path
+ self.yaml_file = None
+
for k in ('longname', 'copyright', 'compression', 'help_text', 'disks', 'fanmade',
'engine', 'genre', 'missing_langs', 'franchise', 'wiki', 'wikibase',
'steam', 'gog', 'origin', 'url_misc', 'wikipedia',
@@ -659,11 +662,10 @@ class GameData(object):
logger.debug('loading full data')
- yamlfile = os.path.join(datadir, self.shortname + '.yaml')
-
- if os.path.exists(yamlfile):
- yamldata = open(yamlfile, encoding='utf-8').read()
- data = yaml.load(yamldata, Loader=yaml.CSafeLoader)
+ if self.yaml_file is not None:
+ data = yaml.load(
+ open(self.yaml_file, encoding='utf-8'),
+ Loader=yaml.CSafeLoader)
for group_name, group_data in sorted(
data.get('groups', {}).items()):
@@ -1030,8 +1032,7 @@ def load_games(game='*', datadir=DATADIR, use_vfs=True):
if os.path.basename(yamlfile).startswith('launch-'):
continue
- yamldata = open(yamlfile, encoding='utf-8').read()
- load_game(progress, games, yamlfile, yamldata)
+ load_game(progress, games, yamlfile, None, yaml_file=yamlfile)
if use_vfs:
if isinstance(use_vfs, str):
@@ -1076,7 +1077,7 @@ def load_games(game='*', datadir=DATADIR, use_vfs=True):
return games
-def load_game(progress, games, filename, content):
+def load_game(progress, games, filename, content, name=None, yaml_file=None):
if progress:
animation = ['.','-','*','#']
modulo = int(load_game.counter) % len(animation)
@@ -1085,15 +1086,20 @@ def load_game(progress, games, filename, content):
print(animation[modulo], end='', flush=True, file=sys.stderr)
load_game.counter += 1
try:
- g = os.path.basename(filename)
- g = g[:len(g) - 5]
-
- if filename.endswith('.yaml'):
+ if name is None:
+ name = os.path.basename(filename)
+ name = name[:len(name) - 5]
+
+ if yaml_file is not None:
+ data = yaml.load(
+ open(yaml_file, encoding='utf-8'),
+ Loader=yaml.CSafeLoader)
+ elif filename.endswith('.yaml'):
data = yaml.load(content, Loader=yaml.CSafeLoader)
else:
data = json.loads(content)
- plugin = data.get('plugin', g)
+ plugin = data.get('plugin', name)
plugin = plugin.replace('-', '_')
try:
@@ -1101,11 +1107,14 @@ def load_game(progress, games, filename, content):
plugin)
game_data_constructor = plugin.GAME_DATA_SUBCLASS
except (ImportError, AttributeError) as e:
- logger.debug('No special code for %s: %s', g, e)
+ logger.debug('No special code for %s: %s', name, e)
assert 'game_data_packager.games' in e.msg, e
game_data_constructor = GameData
- games[g] = game_data_constructor(g, data)
+ games[name] = game_data_constructor(name, data)
+
+ if yaml_file is not None:
+ games[name].yaml_file = yaml_file
except:
print('Error loading %s:\n' % filename)
raise
--
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