parent
112cfb3a4b
commit
3c6341953d
1 changed files with 42 additions and 0 deletions
|
|
@ -584,6 +584,48 @@ class osTicket():
|
||||||
|
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
def get_ram_details():
|
||||||
|
"""Get RAM details via dmidecode, returns dict."""
|
||||||
|
cmd = ['sudo', 'dmidecode', '--type', 'memory']
|
||||||
|
manufacturer = 'UNKNOWN'
|
||||||
|
ram_details = {'Total': 0}
|
||||||
|
size = 0
|
||||||
|
|
||||||
|
# Get DMI data
|
||||||
|
result = run_program(cmd, encoding='utf-8', errors='ignore')
|
||||||
|
dmi_data = result.stdout.splitlines()
|
||||||
|
|
||||||
|
# Testing
|
||||||
|
with open('dmi_mem.log', 'r') as f:
|
||||||
|
dmi_data = f.readlines()
|
||||||
|
|
||||||
|
# Parse data
|
||||||
|
for line in dmi_data:
|
||||||
|
line = line.strip()
|
||||||
|
if line == 'Memory Device':
|
||||||
|
# Reset vars
|
||||||
|
manufacturer = 'UNKNOWN'
|
||||||
|
size = 0
|
||||||
|
elif line.startswith('Size:'):
|
||||||
|
size = convert_to_bytes(line.replace('Size: ', ''))
|
||||||
|
elif line.startswith('Manufacturer:'):
|
||||||
|
manufacturer = line.replace('Manufacturer: ', '')
|
||||||
|
if size > 0:
|
||||||
|
# Add RAM to list if slot populated
|
||||||
|
ram_str = '{} {}'.format(
|
||||||
|
human_readable_size(size).strip(),
|
||||||
|
manufacturer,
|
||||||
|
)
|
||||||
|
ram_details['Total'] += size
|
||||||
|
if ram_str in ram_details:
|
||||||
|
ram_details[ram_str] += 1
|
||||||
|
else:
|
||||||
|
ram_details[ram_str] = 1
|
||||||
|
|
||||||
|
# Done
|
||||||
|
return ram_details
|
||||||
|
|
||||||
|
|
||||||
def pad_with_dots(s, pad_right=False):
|
def pad_with_dots(s, pad_right=False):
|
||||||
"""Replace space padding with dots, returns str."""
|
"""Replace space padding with dots, returns str."""
|
||||||
s = str(s).replace(' ', '..')
|
s = str(s).replace(' ', '..')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue