Fixed the output of sys_type(), might need to add back the error handling part

This commit is contained in:
Mario Melara 2015-10-15 15:25:13 -07:00
parent ccdf105759
commit fec197ccac

View File

@ -60,7 +60,7 @@ def add_arch_strategy(self):
elif 'linux' in n.lower() or 'x86_64' in n.lower():
self.arch_dict[n] = "PATH"
else:
self.arch_dict[n] = None
self.arch_dict[n] = ""
def get_arch_dict(self):
""" Grab the dictionary from the Architecture class, rather than access the internal Architecture attributes """
@ -72,6 +72,7 @@ def __eq__(self, other):
else:
return self.arch_name == self.arch_name
def get_sys_type_from_spack_globals():
"""Return the SYS_TYPE from spack globals, or None if it isn't set. Front-end"""
if not hasattr(spack, "sys_type"):
@ -86,6 +87,7 @@ def get_sys_type_from_spack_globals():
# """Return $SYS_TYPE or None if it's not defined."""
# return os.environ.get('SYS_TYPE')
def get_mac_sys_type():
"""Return a Mac OS SYS_TYPE or None if this isn't a mac.
Front-end config
@ -97,12 +99,14 @@ def get_mac_sys_type():
return Architecture("macosx_%s_%s" % (Version(mac_ver).up_to(2), py_platform.machine()))
def get_sys_type_from_uname():
""" Returns a sys_type from the uname argument
Front-end config
"""
return Architecture(os.uname()[0] + " " + os.uname()[-1])
def get_sys_type_from_config_file():
""" Should read in a sys_type from the config yaml file. This should be the first thing looked at since
The user can specify that the architecture is a cray-xc40. A template yaml should be created when spack
@ -110,21 +114,22 @@ def get_sys_type_from_config_file():
"""
spack_home_dir = os.environ["HOME"] + "/.spack"
yaml_file = os.path.join(spack_home_dir, "architecture.yaml")
yaml_file = os.path.join(spack_home_dir, 'architecture.yaml')
try:
config_dict = yaml.load(open(yaml_file)) # Fix this to have yaml.load()
arch = config_dict['architecture']
front = arch['front']
back = arch['back']
return Architecture(front,back)
except:
print "No architecture.yaml config file found"
return None
return Architecture(front,back)
@memoized
def sys_type():
def sys_type(): # This function is going to give me issues isn't it??
"""Priority of gathering sys-type.
1. YAML file that the user specifies the name of the architecture. e.g Cray-XC40 or Cray-XC30
2. UNAME
@ -133,25 +138,19 @@ def sys_type():
Yaml should be a priority here because we want the user to be able to specify the type of architecture to use.
If there is no yaml present then it should move on to the next function and stop immediately once it gets a
arch name
"""
methods = [get_sys_type_from_config_file,
# Try to create an architecture object using the config file FIRST
functions = [get_sys_type_from_config_file,
get_sys_type_from_uname,
get_sys_type_from_spack_globals,
get_mac_sys_type]
# search for a method that doesn't return None
# TODO: Test for mac OSX system type but I'm sure it will be okay
for func in functions:
sys_type = None
for method in methods:
sys_type = method()
if sys_type: break
# Couldn't determine the sys_type for this machine.
if sys_type is None:
return "unknown_arch"
if not isinstance(sys_type, basestring):
raise InvalidSysTypeError(sys_type)
sys_type = func()
if sys_type:
break
return sys_type