Browse Source

forgot to add this w/ a previous commit..

main
John-Mark Gurney 2 years ago
parent
commit
ab539f5ef7
1 changed files with 38 additions and 0 deletions
  1. +38
    -0
      ui/medashare/hostid.py

+ 38
- 0
ui/medashare/hostid.py View File

@@ -0,0 +1,38 @@
import uuid

from ctypes import CDLL, Structure, POINTER
from ctypes import c_uint8, c_int, c_long, c_int64

uuid_t = c_uint8 * 16

_clib = CDLL(None)

__all__ = [ 'hostuuid']

class timespec(Structure):
_fields_ = [
('tv_sec', c_int64),
('tv_nsec', c_long),
]
pass

timespec_p = POINTER(timespec)

def hostuuid():
ts = timespec()
hid = uuid_t()

r = _clib.gethostuuid(hid, ts)

if r:
raise OSErrorException()

return uuid.UUID(bytes=bytes(hid))

for r, f, a in (
(c_int, 'gethostuuid', (uuid_t, timespec_p)),
):
fun = getattr(_clib, f)
setattr(fun, 'restype', r)
setattr(fun, 'argtypes', a)
locals()[f] = fun

Loading…
Cancel
Save