blob: 507ac69cd5c5eab08aa0743b18120bbe067b257e [file] [log] [blame]
Daniel Dunbar4ed45ea2009-01-09 01:00:40 +00001class HostInfo(object):
2 """HostInfo - Config information about a particular host which may
3 interact with driver behavior. This can be very different from the
4 target(s) of a particular driver invocation."""
5
6 def __init__(self):
7 pass
8
9 def getArchName(self):
10 abstract
11
12 def useDriverDriver(self):
13 abstract
14
15# Darwin
16
17class DarwinHostInfo(HostInfo):
18 def useDriverDriver(self):
19 return True
20
21class DarwinPPCHostInfo(DarwinHostInfo):
22 def getArchName(self):
23 return 'ppc'
24
25class DarwinPPC_64HostInfo(DarwinHostInfo):
26 def getArchName(self):
27 return 'ppc64'
28
29class DarwinX86HostInfo(DarwinHostInfo):
30 def getArchName(self):
31 return 'i386'
32
33class DarwinX86_64HostInfo(DarwinHostInfo):
34 def getArchName(self):
35 return 'x86_64'
36
Daniel Dunbardbc9ee92009-01-09 22:21:24 +000037def getDarwinHostInfo(driver):
38 machine = driver.getHostMachine()
39 bits = driver.getHostBits()
Daniel Dunbar4ed45ea2009-01-09 01:00:40 +000040 if machine == 'i386':
41 if bits == '32':
42 return DarwinX86HostInfo()
43 if bits == '64':
44 return DarwinX86_64HostInfo()
45 elif machine == 'ppc':
46 if bits == '32':
47 return DarwinPPCHostInfo()
48 if bits == '64':
49 return DarwinPPC_64HostInfo()
50
Daniel Dunbardbc9ee92009-01-09 22:21:24 +000051 raise RuntimeError,'Unrecognized Darwin platform: %r:%r' % (machine, bits)
Daniel Dunbar4ed45ea2009-01-09 01:00:40 +000052
53# Unknown
54
55class UnknownHostInfo(HostInfo):
56 def getArchName(self):
57 raise RuntimeError,'getArchName() unsupported on unknown host.'
58
59 def useDriverDriver(self):
60 return False
61
Daniel Dunbardbc9ee92009-01-09 22:21:24 +000062def getUnknownHostInfo(driver):
Daniel Dunbar4ed45ea2009-01-09 01:00:40 +000063 return UnknownHostInfo()
64
65####
66
67kSystems = {
68 'darwin' : getDarwinHostInfo,
69 'unknown' : getUnknownHostInfo,
70 }
71
Daniel Dunbardbc9ee92009-01-09 22:21:24 +000072def getHostInfo(driver):
73 system = driver.getHostSystemName()
Daniel Dunbar4ed45ea2009-01-09 01:00:40 +000074 handler = kSystems.get(system)
75 if handler:
Daniel Dunbardbc9ee92009-01-09 22:21:24 +000076 return handler(driver)
Daniel Dunbar4ed45ea2009-01-09 01:00:40 +000077
78 driver.warning('Unknown host %r, using generic host information.' % system)
79 return UnknownHostInfo()