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(): elif 'linux' in n.lower() or 'x86_64' in n.lower():
self.arch_dict[n] = "PATH" self.arch_dict[n] = "PATH"
else: else:
self.arch_dict[n] = None self.arch_dict[n] = ""
def get_arch_dict(self): def get_arch_dict(self):
""" Grab the dictionary from the Architecture class, rather than access the internal Architecture attributes """ """ Grab the dictionary from the Architecture class, rather than access the internal Architecture attributes """
@ -72,6 +72,7 @@ def __eq__(self, other):
else: else:
return self.arch_name == self.arch_name return self.arch_name == self.arch_name
def get_sys_type_from_spack_globals(): def get_sys_type_from_spack_globals():
"""Return the SYS_TYPE from spack globals, or None if it isn't set. Front-end""" """Return the SYS_TYPE from spack globals, or None if it isn't set. Front-end"""
if not hasattr(spack, "sys_type"): 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 $SYS_TYPE or None if it's not defined."""
# return os.environ.get('SYS_TYPE') # return os.environ.get('SYS_TYPE')
def get_mac_sys_type(): def get_mac_sys_type():
"""Return a Mac OS SYS_TYPE or None if this isn't a mac. """Return a Mac OS SYS_TYPE or None if this isn't a mac.
Front-end config 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())) return Architecture("macosx_%s_%s" % (Version(mac_ver).up_to(2), py_platform.machine()))
def get_sys_type_from_uname(): def get_sys_type_from_uname():
""" Returns a sys_type from the uname argument """ Returns a sys_type from the uname argument
Front-end config Front-end config
""" """
return Architecture(os.uname()[0] + " " + os.uname()[-1]) return Architecture(os.uname()[0] + " " + os.uname()[-1])
def get_sys_type_from_config_file(): 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 """ 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 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" 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: try:
config_dict = yaml.load(open(yaml_file)) # Fix this to have yaml.load() config_dict = yaml.load(open(yaml_file)) # Fix this to have yaml.load()
arch = config_dict['architecture'] arch = config_dict['architecture']
front = arch['front'] front = arch['front']
back = arch['back'] back = arch['back']
return Architecture(front,back)
except: except:
print "No architecture.yaml config file found" print "No architecture.yaml config file found"
return None
return Architecture(front,back)
@memoized @memoized
def sys_type(): def sys_type(): # This function is going to give me issues isn't it??
"""Priority of gathering sys-type. """Priority of gathering sys-type.
1. YAML file that the user specifies the name of the architecture. e.g Cray-XC40 or Cray-XC30 1. YAML file that the user specifies the name of the architecture. e.g Cray-XC40 or Cray-XC30
2. UNAME 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. 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 If there is no yaml present then it should move on to the next function and stop immediately once it gets a
arch name arch name
""" """
methods = [get_sys_type_from_config_file, # Try to create an architecture object using the config file FIRST
get_sys_type_from_uname, functions = [get_sys_type_from_config_file,
get_sys_type_from_spack_globals, get_sys_type_from_uname,
get_mac_sys_type] get_sys_type_from_spack_globals,
get_mac_sys_type]
# search for a method that doesn't return None
sys_type = None # TODO: Test for mac OSX system type but I'm sure it will be okay
for method in methods: for func in functions:
sys_type = method() sys_type = None
if sys_type: break sys_type = func()
if sys_type:
# Couldn't determine the sys_type for this machine. break
if sys_type is None:
return "unknown_arch"
if not isinstance(sys_type, basestring):
raise InvalidSysTypeError(sys_type)
return sys_type return sys_type