mirror of
https://github.com/eblot/pybootd.git
synced 2024-09-11 22:17:44 +03:00
Do not use uname()
This commit is contained in:
parent
23b8327ff1
commit
841274ca52
@ -26,15 +26,14 @@ from re import match
|
|||||||
from socket import inet_aton, inet_ntoa
|
from socket import inet_aton, inet_ntoa
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
from struct import pack as spack, unpack as sunpack
|
from struct import pack as spack, unpack as sunpack
|
||||||
from sys import stderr
|
from sys import platform, stderr
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import netifaces
|
import netifaces as nif
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import os
|
if platform == 'darwin':
|
||||||
if os.uname()[0].lower() == 'darwin':
|
|
||||||
raise ImportError('netifaces package is not installed')
|
raise ImportError('netifaces package is not installed')
|
||||||
netifaces = None
|
nif = None
|
||||||
|
|
||||||
|
|
||||||
# String values evaluated as true boolean values
|
# String values evaluated as true boolean values
|
||||||
@ -188,11 +187,11 @@ def inttoip(ipval):
|
|||||||
|
|
||||||
def _netifaces_get_iface_config(address):
|
def _netifaces_get_iface_config(address):
|
||||||
pool = iptoint(address)
|
pool = iptoint(address)
|
||||||
for iface in netifaces.interfaces():
|
for iface in nif.interfaces():
|
||||||
ifinfo = netifaces.ifaddresses(iface)
|
ifinfo = nif.ifaddresses(iface)
|
||||||
if netifaces.AF_INET not in ifinfo:
|
if nif.AF_INET not in ifinfo:
|
||||||
continue
|
continue
|
||||||
for inetinfo in netifaces.ifaddresses(iface)[netifaces.AF_INET]:
|
for inetinfo in nif.ifaddresses(iface)[nif.AF_INET]:
|
||||||
addr_s = inetinfo.get('addr')
|
addr_s = inetinfo.get('addr')
|
||||||
netmask_s = inetinfo.get('netmask')
|
netmask_s = inetinfo.get('netmask')
|
||||||
if addr_s is None or netmask_s is None:
|
if addr_s is None or netmask_s is None:
|
||||||
@ -242,9 +241,8 @@ def _iproute_get_iface_config(address):
|
|||||||
def get_iface_config(address):
|
def get_iface_config(address):
|
||||||
if not address:
|
if not address:
|
||||||
return None
|
return None
|
||||||
if not netifaces:
|
nifcfg = _netifaces_get_iface_config if nif else _iproute_get_iface_config
|
||||||
return _iproute_get_iface_config(address)
|
return nifcfg(address)
|
||||||
return _netifaces_get_iface_config(address)
|
|
||||||
|
|
||||||
|
|
||||||
class EasyConfigParser(SafeConfigParser):
|
class EasyConfigParser(SafeConfigParser):
|
||||||
|
Loading…
Reference in New Issue
Block a user