1 from __future__ import absolute_import
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
7 __all__ = ['getPathForResource', 'getPathForImage', 'getPathForMesh']
10 if sys.platform.startswith('darwin'):
11 if hasattr(sys, 'frozen'):
13 #Foundation import can crash on some MacOS installs
14 from Foundation import *
15 resourceBasePath = NSBundle.mainBundle().resourcePath()
17 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../../../../")
19 resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
21 if hasattr(sys, 'frozen'):
22 resourceBasePath = os.path.join(os.path.dirname(__file__), "../../resources")
24 resourceBasePath = os.path.join(os.path.dirname(__file__), "../resources")
26 def getPathForResource(dir, subdir, resource_name):
27 assert os.path.isdir(dir), "{p} is not a directory".format(p=dir)
28 path = os.path.normpath(os.path.join(dir, subdir, resource_name))
29 assert os.path.isfile(path), "{p} is not a file.".format(p=path)
32 def getPathForImage(name):
33 return getPathForResource(resourceBasePath, 'images', name)
35 def getPathForMesh(name):
36 return getPathForResource(resourceBasePath, 'meshes', name)
38 def getPathForFirmware(name):
39 return getPathForResource(resourceBasePath, 'firmware', name)