Got rid of methods used to detect mac osx and linux osx. Now those methods are used my operating system subclasses
This commit is contained in:
parent
18ddbae60e
commit
a8de45ce28
1 changed files with 54 additions and 34 deletions
|
@ -148,35 +148,29 @@ def target(self, name):
|
||||||
|
|
||||||
return self.targets[name]
|
return self.targets[name]
|
||||||
|
|
||||||
def _detect_linux_os(self):
|
#def _detect_linux_os(self):
|
||||||
return OperatingSystem(py_platform.dist()[0], py_platform.dist()[1])
|
# return OperatingSystem(py_platform.dist()[0], py_platform.dist()[1])
|
||||||
|
|
||||||
def _detect_mac_os(self):
|
#def _detect_mac_os(self):
|
||||||
mac_releases = {'10.6': "snowleopard",
|
# mac_releases = {'10.6': "snowleopard",
|
||||||
"10.7": "lion",
|
# "10.7": "lion",
|
||||||
"10.8": "mountainlion",
|
# "10.8": "mountainlion",
|
||||||
"10.9": "mavericks",
|
# "10.9": "mavericks",
|
||||||
"10.10": "yosemite",
|
# "10.10": "yosemite",
|
||||||
"10.11": "elcapitan"}
|
# "10.11": "elcapitan"}
|
||||||
mac_ver = py_platform.mac_ver()[:-2]
|
# mac_ver = py_platform.mac_ver()[:-2]
|
||||||
try:
|
# try:
|
||||||
os_name = mac_releases[mac_ver]
|
# os_name = mac_releases[mac_ver]
|
||||||
return OperatingSystem(os_name, mac_ver)
|
# return OperatingSystem(os_name, mac_ver)
|
||||||
except KeyError:
|
# except KeyError:
|
||||||
os_name = "mac_os"
|
# os_name = "mac_os"
|
||||||
return OperatingSystem(os_name, mac_ver)
|
# return OperatingSystem(os_name, mac_ver)
|
||||||
|
|
||||||
def add_operating_system(self, name=None, operating_system=None):
|
def add_operating_system(self, name, os_class):
|
||||||
if self.name == 'linux':
|
""" Add the operating_system class object into the
|
||||||
linux_os = self._detect_linux_os()
|
platform.operating_sys dictionary
|
||||||
self.default_os = linux_os.name
|
"""
|
||||||
self.operating_sys[linux_os.name] = linux_os
|
self.operating_sys[name] = os_class
|
||||||
elif self.name == 'darwin':
|
|
||||||
mac_os = self._detect_mac_os()
|
|
||||||
self.default_os = mac_os.name
|
|
||||||
self.operating_sys[mac_os.name] = mac_os
|
|
||||||
else:
|
|
||||||
self.operating_sys[name] = operating_system
|
|
||||||
|
|
||||||
def operating_system(self, name):
|
def operating_system(self, name):
|
||||||
if name == 'default_os':
|
if name == 'default_os':
|
||||||
|
@ -207,27 +201,37 @@ def _cmp_key(self):
|
||||||
return (self.name, (_cmp_key(t) for t in self.targets.values()),
|
return (self.name, (_cmp_key(t) for t in self.targets.values()),
|
||||||
(_cmp_key(o) for o in self.operating_sys.values()))
|
(_cmp_key(o) for o in self.operating_sys.values()))
|
||||||
|
|
||||||
|
|
||||||
@key_ordering
|
@key_ordering
|
||||||
class OperatingSystem(object):
|
class OperatingSystem(object):
|
||||||
""" Operating System class. It will include the name and version.
|
""" Operating System will be like a class similar to platform extended
|
||||||
The biggest attribute to this class will be the compiler finding
|
by subclasses for the specifics. Operating System will contain the
|
||||||
strategy. At the moment the compiler finding strategy is going to
|
compiler finding logic. Instead of calling two separate methods to
|
||||||
be a string.
|
find compilers we call find_compilers method for each operating system
|
||||||
"""
|
"""
|
||||||
def __init__(self, name, version):
|
def __init__(self, name, version):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.version = version
|
self.version = version
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name + self.version
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
||||||
|
def compiler_strategy(self):
|
||||||
|
""" The compiler strategy will be overwritten by the subclass.
|
||||||
|
Depending on where it comes from it will either use compilers
|
||||||
|
based off of MODULES search method or the PATH search method
|
||||||
|
"""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
def _cmp_key(self):
|
def _cmp_key(self):
|
||||||
return (self.name, self.version)
|
return (self.name, self.version)
|
||||||
|
|
||||||
|
|
||||||
|
#NOTE: Key error caused because Architecture has no comparison method
|
||||||
|
@key_ordering
|
||||||
class Arch(namedtuple("Arch", "platform platform_os target")):
|
class Arch(namedtuple("Arch", "platform platform_os target")):
|
||||||
""" namedtuple for Architecture. Will have it's own __str__ method
|
""" namedtuple for Architecture. Will have it's own __str__ method
|
||||||
to make printing out the tuple easier and also won't make directory
|
to make printing out the tuple easier and also won't make directory
|
||||||
|
@ -238,6 +242,22 @@ def __str__(self):
|
||||||
return (self.platform.name +"-"+
|
return (self.platform.name +"-"+
|
||||||
self.platform_os.name + "-" + self.target.name)
|
self.platform_os.name + "-" + self.target.name)
|
||||||
|
|
||||||
|
def _cmp_key(self):
|
||||||
|
return (self.platform.name, self.platform_os.name, self.target.name)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def to_dict(platform, os_name, target):
|
||||||
|
""" This function will handle all the converting of dictionaries
|
||||||
|
for each of the architecture classes. This is better than having
|
||||||
|
each class have a to_dict method when creating the dict of dicts
|
||||||
|
arch class
|
||||||
|
"""
|
||||||
|
d = {}
|
||||||
|
d['platform'] = platform
|
||||||
|
d['operating_system'] = os_name
|
||||||
|
d['target'] = target.to_dict()
|
||||||
|
return d
|
||||||
|
|
||||||
@memoized
|
@memoized
|
||||||
def all_platforms():
|
def all_platforms():
|
||||||
modules = []
|
modules = []
|
||||||
|
|
Loading…
Reference in a new issue