Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
language: python
before_install:
- pip install tox
script:
- py.test tests.py
- tox

52 changes: 28 additions & 24 deletions dmidecode.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from __future__ import print_function
import os, sys
import os
import sys

__version__ = "0.9.0"

TYPE = {
0: 'bios',
1: 'system',
2: 'base board',
3: 'chassis',
4: 'processor',
7: 'cache',
8: 'port connector',
9: 'system slot',
0: 'bios',
1: 'system',
2: 'base board',
3: 'chassis',
4: 'processor',
7: 'cache',
8: 'port connector',
9: 'system slot',
10: 'on board device',
11: 'OEM strings',
#13: 'bios language',
# 13: 'bios language',
15: 'system event log',
16: 'physical memory array',
17: 'memory device',
Expand All @@ -24,7 +25,7 @@
27: 'cooling device',
32: 'system boot',
41: 'onboard device',
}
}


def parse_dmi(content):
Expand Down Expand Up @@ -58,7 +59,9 @@ def _parse_handle_section(lines):
"""
data = {
'_title': next(lines).rstrip(),
}
}

k = None

for line in lines:
line = line.rstrip()
Expand Down Expand Up @@ -91,13 +94,13 @@ def _get_output():
import subprocess
try:
output = subprocess.check_output(
'PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin '
'sudo dmidecode', shell=True)
'PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin '
'sudo dmidecode', shell=True)
except Exception as e:
print(e, file=sys.stderr)
if str(e).find("command not found") == -1:
print("please install dmidecode", file=sys.stderr)
print("e.g. sudo apt install dmidecode",file=sys.stderr)
print("e.g. sudo apt install dmidecode", file=sys.stderr)

sys.exit(1)
return output.decode()
Expand All @@ -108,26 +111,26 @@ def _get(i):
return [v for j, v in info if j == i]

system = _get('system')[0]
print ('%s %s (SN: %s, UUID: %s)' % (
print('%s %s (SN: %s, UUID: %s)' % (
system['Manufacturer'],
system['Product Name'],
system['Serial Number'],
system['UUID'],
))
))

for cpu in _get('processor'):
#fix for output in virtual machine environments
# fix for output in virtual machine environments
if 'Thread Count' in cpu:
threads = cpu['Thread Count']
else:
threads = "-"
print ('%s %s %s (Core: %s, Thead: %s)' % (
print('%s %s %s (Core: %s, Thead: %s)' % (
cpu['Manufacturer'],
cpu['Family'],
cpu['Max Speed'],
cpu['Core Count'],
threads,
))
))

cnt, total, unit = 0, 0, None
for mem in _get('memory device'):
Expand All @@ -136,18 +139,19 @@ def _get(i):
i, unit = mem['Size'].split()
cnt += 1
total += int(i)
print ('%d memory stick(s), %d %s in total' % (
print('%d memory stick(s), %d %s in total' % (
cnt,
total,
unit,
))
))
bios = _get('bios')[0]
print ('BIOS: %s v.%s %s Systemversion: %s' % (
print('BIOS: %s v.%s %s Systemversion: %s' % (
bios['Vendor'],
bios['Version'],
bios['Release Date'],
system['Version']
))
))


if __name__ == '__main__':
profile()
Empty file added requirements.txt
Empty file.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Utilities',
],
)
],
)
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pytest
flake8

22 changes: 22 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[tox]
minversion = 2.0
envlist = pep8
skipsdist = True

[testenv]
passenv = CI TRAVIS TRAVIS_*
usedevelop = True
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
setenv = LANGUAGE=en

[testenv:pep8]
basepython = python2.7
commands =
flake8 *.py

[flake8]
show-source = True
ignore = E402,E501,E722
exclude = tests.py