+""" Utilities for loading resource files. """
+
+import json
+import os
+
+
+class Loader(object):
+ """ Load data files from beneath a prefix. """
+
+ def __init__(self, prefix):
+ self._prefix = prefix
+
+ def full_path(self, *parts):
+ path = "/".join(parts)
+ rel_path = os.path.join(*path.split("/"))
+ abs_path = os.path.join(self._prefix, rel_path)
+ print abs_path
+ return abs_path
+
+ def open_file(self, *parts):
+ return file(self.full_path(*parts), "rb")
+
+ def load_station(self, *parts):
+ with self.open_file("stations", *parts) as f:
+ return json.load(f)
+
+
+_DATA_PREFIX = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), "..", "data"))
+
+loader = Loader(_DATA_PREFIX)