diff options
author | Mario Melara <maamelara@gmail.com> | 2016-02-10 16:14:50 -0800 |
---|---|---|
committer | Mario Melara <maamelara@gmail.com> | 2016-02-10 16:14:50 -0800 |
commit | 2650c60374a0857679d52f98fc5f94b23c7d6660 (patch) | |
tree | 7ca83837dc2e995ba3579601c22e69b50d9e2aff /lib | |
parent | 21a5a3404134c1676a7aa498ec201ed911e80029 (diff) | |
download | spack-2650c60374a0857679d52f98fc5f94b23c7d6660.tar.gz spack-2650c60374a0857679d52f98fc5f94b23c7d6660.tar.bz2 spack-2650c60374a0857679d52f98fc5f94b23c7d6660.tar.xz spack-2650c60374a0857679d52f98fc5f94b23c7d6660.zip |
Added operating system class prototype and some autodetect features for operating system
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/architecture.py | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/lib/spack/spack/architecture.py b/lib/spack/spack/architecture.py index 6b9ae33b3e..2914d36ba2 100644 --- a/lib/spack/spack/architecture.py +++ b/lib/spack/spack/architecture.py @@ -109,8 +109,13 @@ class Platform(object): back_end = None default = None # The default back end target. On cray ivybridge + front_os = None + back_os = None + default_os = None + def __init__(self, name): self.targets = {} + self.operating_sys = {} self.name = name def add_target(self, name, target): @@ -136,10 +141,49 @@ class Platform(object): return self.targets[name] + def _detect_linux_os(self): + return OperatingSystem(py_platform.dist()[0], py_platform.dist()[1]) + + def _detect_mac_os(self): + mac_releases = {'10.6': "snowleopard", + "10.7": "lion", + "10.8": "mountainlion", + "10.9": "mavericks", + "10.10": "yosemite", + "10.11": "elcapitan"} + mac_ver = py_platform.mac_ver()[:-2] + try: + os_name = mac_releases[mac_ver] + return OperatingSystem(os_name, mac_ver) + except KeyError: + os_name = "mac_os" + return OperatingSystem(os_name, mac_ver) + + def add_operating_system(self, name=None, operating_system=None): + if self.name == 'linux': + linux_os = self._detect_linux_os() + self.operating_sys[linux_os.name] = linux_os + elif self.name == 'darwin': + mac_os = self._detect_mac_os() + self.operating_sys[mac_os.name] = mac_os + else: + self.operating_sys[name] = operating_system + + def operating_system(self, name): + if name == 'default': + name = self.default_os + if name == 'front_os': + name = self.front_os + if name == 'back_os': + name = self.back_os + + return self.operating_sys[name] + @classmethod def detect(self): """ Subclass is responsible for implementing this method. - Returns True if the Platform class detects that it is the current platform + Returns True if the Platform class detects that + it is the current platform and False if it's not. """ raise NotImplementedError() @@ -153,6 +197,21 @@ class Platform(object): def _cmp_key(self): return (self.name, (_cmp_key(t) for t in self.targets.values())) + +class OperatingSystem(object): + """ The operating system will contain a name and version. It will + also represent itself simple with it's name + """ + def __init__(self, name, version): + self.name = name + self.version = version + + def __str__(self): + return self.name + + def __repr__(self): + return self.__str__() + def get_sys_type_from_spack_globals(): """Return the SYS_TYPE from spack globals, or None if it isn't set.""" if not hasattr(spack, "sys_type"): |