SysPaths.py revision 10681
12931Sktlim@umich.edu# Copyright (c) 2006 The Regents of The University of Michigan 22931Sktlim@umich.edu# All rights reserved. 32931Sktlim@umich.edu# 42931Sktlim@umich.edu# Redistribution and use in source and binary forms, with or without 52931Sktlim@umich.edu# modification, are permitted provided that the following conditions are 62931Sktlim@umich.edu# met: redistributions of source code must retain the above copyright 72931Sktlim@umich.edu# notice, this list of conditions and the following disclaimer; 82931Sktlim@umich.edu# redistributions in binary form must reproduce the above copyright 92931Sktlim@umich.edu# notice, this list of conditions and the following disclaimer in the 102931Sktlim@umich.edu# documentation and/or other materials provided with the distribution; 112931Sktlim@umich.edu# neither the name of the copyright holders nor the names of its 122931Sktlim@umich.edu# contributors may be used to endorse or promote products derived from 132931Sktlim@umich.edu# this software without specific prior written permission. 142931Sktlim@umich.edu# 152931Sktlim@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162931Sktlim@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172931Sktlim@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182931Sktlim@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192931Sktlim@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202931Sktlim@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212931Sktlim@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222931Sktlim@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232931Sktlim@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242931Sktlim@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252931Sktlim@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262931Sktlim@umich.edu# 272931Sktlim@umich.edu# Authors: Ali Saidi 282931Sktlim@umich.edu 292774SN/Aimport os, sys 302774SN/Afrom os.path import isdir, join as joinpath 312774SN/Afrom os import environ as env 322566SN/A 333510Shsul@eecs.umich.educonfig_path = os.path.dirname(os.path.abspath(__file__)) 343510Shsul@eecs.umich.educonfig_root = os.path.dirname(config_path) 353510Shsul@eecs.umich.edu 3610681Ssteve.reinhardt@amd.comdef searchpath(path, file): 3710681Ssteve.reinhardt@amd.com for p in path: 3810681Ssteve.reinhardt@amd.com f = joinpath(p, file) 3910681Ssteve.reinhardt@amd.com if os.path.exists(f): 4010681Ssteve.reinhardt@amd.com return f 4110681Ssteve.reinhardt@amd.com raise IOError, "Can't find file '%s' on path." % file 4210681Ssteve.reinhardt@amd.com 432902SN/Adef disk(file): 442902SN/A system() 4510681Ssteve.reinhardt@amd.com return searchpath(disk.path, file) 462566SN/A 472902SN/Adef binary(file): 482902SN/A system() 4910681Ssteve.reinhardt@amd.com return searchpath(binary.path, file) 502902SN/A 512902SN/Adef script(file): 522902SN/A system() 5310681Ssteve.reinhardt@amd.com return searchpath(script.path, file) 542902SN/A 552902SN/Adef system(): 5610681Ssteve.reinhardt@amd.com if not system.path: 572774SN/A try: 5810681Ssteve.reinhardt@amd.com path = env['M5_PATH'].split(':') 592774SN/A except KeyError: 6010681Ssteve.reinhardt@amd.com path = [ '/dist/m5/system', '/n/poolfs/z/dist/m5/system' ] 612566SN/A 6210681Ssteve.reinhardt@amd.com # filter out non-existent directories 6310681Ssteve.reinhardt@amd.com system.path = filter(os.path.isdir, path) 642566SN/A 6510681Ssteve.reinhardt@amd.com if not system.path: 6610681Ssteve.reinhardt@amd.com raise IOError, "Can't find a path to system files." 672566SN/A 6810681Ssteve.reinhardt@amd.com if not binary.path: 6910681Ssteve.reinhardt@amd.com binary.path = [joinpath(p, 'binaries') for p in system.path] 7010681Ssteve.reinhardt@amd.com if not disk.path: 7110681Ssteve.reinhardt@amd.com disk.path = [joinpath(p, 'disks') for p in system.path] 7210681Ssteve.reinhardt@amd.com if not script.path: 7310681Ssteve.reinhardt@amd.com script.path = [joinpath(config_root, 'boot')] 7410681Ssteve.reinhardt@amd.com 7510681Ssteve.reinhardt@amd.comsystem.path = None 7610681Ssteve.reinhardt@amd.combinary.path = None 7710681Ssteve.reinhardt@amd.comdisk.path = None 7810681Ssteve.reinhardt@amd.comscript.path = None 79