26 from __future__
import print_function
27 from builtins
import object
29 from future.utils
import with_metaclass
36 attrs[
'_order'] = mcs.nextorder
38 return type.__new__(mcs, name, bases, attrs)
42 def __init__(self, ostype=-1, func=None, inst=None):
49 self.
ostype = ostype
if ostype != -1
else 'posix'
51 if (func
is not None)
and not callable(func):
52 raise TypeError((self.__class__.__name__ +
"() requires a " \
53 "provided function be callable."))
68 return self.__class__(self.
ostype, func, inst)
75 if self.
func is not None:
76 raise TypeError((self.__class__.__name__ +
"() has already " \
77 "been given a processing function"))
78 if (func
is None)
or not callable(func):
79 raise TypeError((self.__class__.__name__ +
"() takes exactly " \
80 "one callable as a function, (0 given)"))
84 raise RuntimeError((self.__class__.__name__ +
"() has not " \
85 "been given a callable function"))
89 if (self.
ostype is not None)
and (os.name != self.
ostype):
98 res = self.
func(*args, **kwargs)
110 _requires_func =
False
111 def __init__(self, filename, ostype='posix', func=None, inst=None):
113 super(OSWithFile, self).
__init__(ostype, func, inst)
122 if not os.path.exists(self.
filename):
129 return super(OSWithFile, self).
do_test(text)
132 self.
inst.name = text
140 except AttributeError:
pass
144 from subprocess
import Popen, PIPE
150 path =
'/usr/bin/uname'
151 if not os.path.exists(path):
156 for k,v
in ((
'OS',
'-s'),
158 p = Popen([path, v], stdout=PIPE)
160 self.
_uname[k] = p.stdout.read().strip()
165 if len(self.
uname) == 0:
172 for k,v
in list(attrs.items()):
173 if isinstance(v, OS):
175 OSs.append((v._order, k))
177 attrs[
'_oslist'] = [i[1]
for i
in sorted(OSs)]
178 return type.__new__(mcs, name, bases, attrs)
183 for attr
in obj._oslist:
185 if getattr(obj, attr)():
202 }[os.sys.getwindowsversion()[3],
203 os.sys.getwindowsversion()[0],
204 os.sys.getwindowsversion()[1] ]
205 return "Windows " + win_version
226 text = open(
'/etc/issue.net').
read().strip()
227 if text.find(
'Ubuntu'):
229 mtext = open(
'/var/log/installer/media-info').
read().strip()
233 if 'Mythbuntu' in mtext:
234 text.replace(
'Ubuntu',
'Mythbuntu')
253 text = text.split(
'\n')[0].strip()
254 return re.sub(
'\(\w*\)$',
'', text)
262 return 'FreeBSD '+version
266 def OSX(self, OS, version):
269 major,minor,point = [int(a)
for a
in version.split(
'.')]
270 return 'OS X 10.%s.%s' % (major-4, minor)
274 from subprocess
import Popen, PIPE
275 executable =
'lsb_release'
276 for path
in os.environ[
'PATH'].split(
':'):
277 fullpath = os.path.join(path, executable)
278 if os.path.exists(fullpath):
283 p = Popen([fullpath,
'--id',
'--codename',
'--release',
'--short'],
284 stdout=PIPE, close_fds=
True)
286 return p.stdout.read().
decode().strip().replace(
'\n',
' ')
291 return 'Unknown Linux '+version
295 if __name__ ==
'__main__':
297 print(
'Test results="{}"'.format(results))