diff options
Diffstat (limited to 'external/plyer/platforms/linux/uniqueid.py')
-rw-r--r-- | external/plyer/platforms/linux/uniqueid.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/external/plyer/platforms/linux/uniqueid.py b/external/plyer/platforms/linux/uniqueid.py new file mode 100644 index 0000000..f7fff89 --- /dev/null +++ b/external/plyer/platforms/linux/uniqueid.py @@ -0,0 +1,30 @@ +from subprocess import Popen, PIPE +from plyer.facades import UniqueID +from plyer.utils import whereis_exe + +from os import environ + + +class LinuxUniqueID(UniqueID): + def _get_uid(self): + old_lang = environ.get('LANG') + environ['LANG'] = 'C' + lshw_process = Popen(["lshw", "-quiet"], stdout=PIPE, stderr=PIPE) + grep_process = Popen(["grep", "-m1", "serial:"], + stdin=lshw_process.stdout, stdout=PIPE) + lshw_process.stdout.close() + output = grep_process.communicate()[0] + environ['LANG'] = old_lang + + if output: + return output.split()[1] + else: + return None + + +def instance(): + import sys + if whereis_exe('lshw'): + return LinuxUniqueID() + sys.stderr.write("lshw not found.") + return UniqueID() |