1
0
mirror of https://github.com/HorlogeSkynet/archey4 synced 2025-05-14 16:00:18 +02:00

Adds compatibility to virtualized environments (run as root needed)

This commit is contained in:
Samuel FORESTIER 2017-08-29 10:04:11 -04:00
parent eed369a45e
commit cc6fea53aa
No known key found for this signature in database
GPG Key ID: 4B6FA04B1AC95DD4

30
archey

@ -421,12 +421,32 @@ class Model:
output = file.read()
hardware = re.search('(?<=Hardware\t: ).*', output)
revision = re.search('(?<=Revision\t: ).*', output)
# If the output contains 'Hardware' and 'Revision'...
if hardware and revision:
# ... let's set a pretty info string with these data
model = 'Raspberry Pi ' + hardware.group(0) + ' (Rev. ' + revision.group(0) + ')'
else:
# If the output contains 'Hardware' and 'Revision'...
if hardware and revision:
# ... let's set a pretty info string with these data
model = 'Raspberry Pi ' + hardware.group(0) + ' (Rev. ' + revision.group(0) + ')'
else:
# A tricky way to retrieve some details about hypervisor (within virtualized contexts)
# `archey` needs to be run as root although...
try:
virtWhat = ', '.join(check_output(['virt-what'], stderr=DEVNULL).decode().rstrip().split())
if virtWhat:
try:
# Sometimes we may gather info added by hosting service provider this way
model = check_output(['dmidecode', '-s', 'system-product-name'], stderr=DEVNULL).decode().rstrip()
except (FileNotFoundError, CalledProcessError):
model = 'Virtualized environment'
model += ' (' + virtWhat + ')'
else:
model = 'Bare-metal environment'
except (FileNotFoundError, CalledProcessError):
model = 'Not detected'
self.value = model