-from naja.resources.loader import Loader
+from naja.resources.loader import Loader, ResourceNotFound
+
+__all__ = ['resources', 'ResourceNotFound']
resources = Loader('data')
import os
import sys
+import json
try:
from pkg_resources import resource_filename
# time going down this rabbithole already
return os.path.join(os.path.dirname(__file__), '..', '..', 'data',
path)
+
+try:
+ import yaml
+except ImportError:
+ yaml = None
+
import pygame
self._cache[key] = pygame.font.Font(fn, font_size)
return self._cache[key]
+
+ def get_yaml(self, *path_fragments):
+ if yaml is None:
+ raise ResourceNotFound("%s - %s" % (
+ os.path.join(*path_fragments),
+ "YAML module not available"))
+ with self.get_file(*path_fragments) as yaml_file:
+ return yaml.safe_load(yaml_file)
+
+ def get_json(self, *path_fragments):
+ with self.get_file(*path_fragments) as json_file:
+ return json.load(json_file)