summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configs/common/SysPaths.py44
1 files changed, 26 insertions, 18 deletions
diff --git a/configs/common/SysPaths.py b/configs/common/SysPaths.py
index e5d9f83b2..0a6778941 100644
--- a/configs/common/SysPaths.py
+++ b/configs/common/SysPaths.py
@@ -37,6 +37,7 @@ config_root = os.path.dirname(config_path)
class PathSearchFunc(object):
_sys_paths = None
+ environment_variable = 'M5_PATH'
def __init__(self, subdirs, sys_paths=None):
if isinstance(subdirs, string_types):
@@ -46,29 +47,36 @@ class PathSearchFunc(object):
self._sys_paths = sys_paths
def __call__(self, filename):
- if self._sys_paths is None:
- try:
- paths = os.environ['M5_PATH'].split(':')
- except KeyError:
- paths = [ '/dist/m5/system', '/n/poolfs/z/dist/m5/system' ]
+ if os.sep in filename:
+ return filename
+ else:
+ if self._sys_paths is None:
+ try:
+ paths = os.environ[self.environment_variable].split(':')
+ except KeyError:
+ paths = [ '/dist/m5/system', '/n/poolfs/z/dist/m5/system' ]
- # expand '~' and '~user' in paths
- paths = map(os.path.expanduser, paths)
+ # expand '~' and '~user' in paths
+ paths = map(os.path.expanduser, paths)
- # filter out non-existent directories
- paths = filter(os.path.isdir, paths)
+ # filter out non-existent directories
+ paths = filter(os.path.isdir, paths)
- if not paths:
- raise IOError("Can't find a path to system files.")
+ if not paths:
+ raise IOError(
+ "Can't find system files directory, "
+ "check your {} environment variable"
+ .format(self.environment_variable))
- self._sys_paths = list(paths)
+ self._sys_paths = list(paths)
- filepath = os.path.join(self._subdir, filename)
- paths = (os.path.join(p, filepath) for p in self._sys_paths)
- try:
- return next(p for p in paths if os.path.exists(p))
- except StopIteration:
- raise IOError("Can't find file '%s' on path." % filename)
+ filepath = os.path.join(self._subdir, filename)
+ paths = (os.path.join(p, filepath) for p in self._sys_paths)
+ try:
+ return next(p for p in paths if os.path.exists(p))
+ except StopIteration:
+ raise IOError("Can't find file '{}' on {}."
+ .format(filename, self.environment_variable))
disk = PathSearchFunc('disks')
binary = PathSearchFunc('binaries')