2006-07-21 21:42:44 +02:00
|
|
|
# Copyright (c) 2006 The Regents of The University of Michigan
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
# met: redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer;
|
|
|
|
# redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution;
|
|
|
|
# neither the name of the copyright holders nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived from
|
|
|
|
# this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
# Authors: Ali Saidi
|
|
|
|
|
|
|
|
import os, sys
|
2015-03-24 00:14:19 +01:00
|
|
|
from os.path import join as joinpath
|
2006-07-21 21:42:44 +02:00
|
|
|
from os import environ as env
|
|
|
|
|
2006-11-08 20:10:25 +01:00
|
|
|
config_path = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
config_root = os.path.dirname(config_path)
|
|
|
|
|
2015-02-06 01:45:12 +01:00
|
|
|
def searchpath(path, filename):
|
2015-02-06 01:45:06 +01:00
|
|
|
for p in path:
|
2015-02-06 01:45:12 +01:00
|
|
|
f = joinpath(p, filename)
|
2015-02-06 01:45:06 +01:00
|
|
|
if os.path.exists(f):
|
|
|
|
return f
|
2015-02-06 01:45:12 +01:00
|
|
|
raise IOError, "Can't find file '%s' on path." % filename
|
2015-02-06 01:45:06 +01:00
|
|
|
|
2015-02-06 01:45:12 +01:00
|
|
|
def disk(filename):
|
2006-07-21 21:42:44 +02:00
|
|
|
system()
|
2015-02-06 01:45:12 +01:00
|
|
|
return searchpath(disk.path, filename)
|
2006-07-21 21:42:44 +02:00
|
|
|
|
2015-02-06 01:45:12 +01:00
|
|
|
def binary(filename):
|
2006-07-21 21:42:44 +02:00
|
|
|
system()
|
2015-02-06 01:45:12 +01:00
|
|
|
return searchpath(binary.path, filename)
|
2006-07-21 21:42:44 +02:00
|
|
|
|
2015-02-06 01:45:12 +01:00
|
|
|
def script(filename):
|
2006-07-21 21:42:44 +02:00
|
|
|
system()
|
2015-02-06 01:45:12 +01:00
|
|
|
return searchpath(script.path, filename)
|
2006-07-21 21:42:44 +02:00
|
|
|
|
|
|
|
def system():
|
2015-02-06 01:45:06 +01:00
|
|
|
if not system.path:
|
2006-07-21 21:42:44 +02:00
|
|
|
try:
|
2015-02-06 01:45:06 +01:00
|
|
|
path = env['M5_PATH'].split(':')
|
2006-07-21 21:42:44 +02:00
|
|
|
except KeyError:
|
2015-02-06 01:45:06 +01:00
|
|
|
path = [ '/dist/m5/system', '/n/poolfs/z/dist/m5/system' ]
|
|
|
|
|
2015-03-24 00:14:19 +01:00
|
|
|
# expand '~' and '~user' in paths
|
|
|
|
path = map(os.path.expanduser, path)
|
|
|
|
|
2015-02-06 01:45:06 +01:00
|
|
|
# filter out non-existent directories
|
|
|
|
system.path = filter(os.path.isdir, path)
|
2006-07-21 21:42:44 +02:00
|
|
|
|
2015-02-06 01:45:06 +01:00
|
|
|
if not system.path:
|
|
|
|
raise IOError, "Can't find a path to system files."
|
2006-07-21 21:42:44 +02:00
|
|
|
|
2015-02-06 01:45:06 +01:00
|
|
|
if not binary.path:
|
|
|
|
binary.path = [joinpath(p, 'binaries') for p in system.path]
|
|
|
|
if not disk.path:
|
|
|
|
disk.path = [joinpath(p, 'disks') for p in system.path]
|
|
|
|
if not script.path:
|
|
|
|
script.path = [joinpath(config_root, 'boot')]
|
2006-07-21 21:42:44 +02:00
|
|
|
|
2015-02-06 01:45:06 +01:00
|
|
|
system.path = None
|
|
|
|
binary.path = None
|
|
|
|
disk.path = None
|
|
|
|
script.path = None
|