Skip to content

Commit ded4f15

Browse files
mjolivercopybara-github
authored andcommitted
Add CPU arch pin to build info so you can pin against CPU type (e.g. ARM64)
PiperOrigin-RevId: 698925500
1 parent 2ca6a23 commit ded4f15

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

gwinpy/wmi/hw_info.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,41 @@ def MacAddresses(self, pci_only=False):
241241
addresses.append(address)
242242
return addresses
243243

244+
def Architecture(self):
245+
"""Get the architecture of the local machine.
246+
247+
Returns:
248+
The architecture string if found; else None.
249+
"""
250+
# https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-processor
251+
architecture_map = {
252+
0: 'x86',
253+
1: 'MIPS',
254+
2: 'Alpha',
255+
3: 'PowerPC',
256+
5: 'ARM',
257+
6: 'ia64',
258+
9: 'x64',
259+
12: 'ARM64',
260+
}
261+
query = 'SELECT Architecture FROM Win32_Processor'
262+
results = self.wmi.Query(query)
263+
if results:
264+
logging.debug(
265+
'Win32_ComputerSystem/win32-processor: %s',
266+
results[0].Architecture.rstrip(),
267+
)
268+
try:
269+
archtype = architecture_map[int(results[0].Architecture.rstrip())]
270+
except KeyError:
271+
logging.warning(
272+
'Invalid architecture %s.', results[0].Architecture.rstrip()
273+
)
274+
return 'unknown'
275+
return archtype
276+
logging.warning('No results for %s.', query)
277+
return None
278+
244279
def PciDevices(self):
245280
"""Get local PCI devices.
246281

gwinpy/wmi/hw_info_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ def testBiosSerial(self):
4747
self.hwinfo.wmi.Query.return_value = None
4848
self.assertIsNone(self.hwinfo.BiosSerial())
4949

50+
def testArchType(self):
51+
self.hwinfo.wmi.Query.return_value = [mock.Mock(Architecture='0')]
52+
self.assertEqual(self.hwinfo.Architecture(), 'x86')
53+
self.hwinfo.wmi.Query.return_value = [mock.Mock(Architecture='12')]
54+
self.assertEqual(self.hwinfo.Architecture(), 'ARM64')
55+
self.hwinfo.wmi.Query.return_value = [mock.Mock(Architecture='1337')]
56+
self.assertEqual(self.hwinfo.Architecture(), 'Unknown')
57+
5058
def testBIOSVersion(self):
5159
self.hwinfo.wmi.Query.return_value = [mock.Mock(SMBIOSBIOSVersion='12345')]
5260
self.assertEqual(self.hwinfo.BIOSVersion(), '12345')

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
distutils.core.setup(
1919
name='gwinpy',
20-
version='0.3.7',
20+
version='0.3.8',
2121
packages=['gwinpy', 'gwinpy.net', 'gwinpy.registry', 'gwinpy.wmi'],
2222
license='Apache License',
2323
url='https://github.com/google/winops/',

0 commit comments

Comments
 (0)