Skip to content

Commit

Permalink
Merge pull request #4 from jaraco/feature/devices-darwine
Browse files Browse the repository at this point in the history
Add macOS support for devices
  • Loading branch information
jaraco authored Dec 6, 2022
2 parents 4884c8c + 698a6c9 commit 59b235f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v9.2.0
======

#4: Added support for macOS to ``jaraco.net.devices``.

v9.1.0
======

Expand Down
6 changes: 1 addition & 5 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
import importlib
import platform

from jaraco.context import ExceptionTrap

Expand All @@ -17,11 +16,8 @@ def pywin32_missing():
[
'jaraco/net/devices/linux.py',
'jaraco/net/devices/win32.py',
'jaraco/net/devices/darwin.py',
]
+ [
'jaraco/net/devices/__init__.py',
]
* (platform.system() == 'Darwin')
+ [
# modules only import on Windows
'jaraco/net/dns.py',
Expand Down
24 changes: 24 additions & 0 deletions jaraco/net/devices/darwin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import subprocess
import operator

import ifconfigparser

from .base import BaseManager


def if_config():
cfg = subprocess.check_output(['ifconfig'], text=True)
return ifconfigparser.IfconfigParser(cfg)


class Manager(BaseManager):
def get_host_mac_addresses(self):
return self._iface_values('mac_addr')

def get_host_ip_addresses(self):
return self._iface_values('ipv4_addr')

@staticmethod
def _iface_values(key):
ifaces = if_config().get_interfaces().values()
return filter(None, map(operator.attrgetter(key), ifaces))
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ install_requires =
python-dateutil
pathvalidate
pywin32; sys_platform == 'win32' and python_version < "3.12"
ifconfig-parser; sys_platform == 'darwin'
jsonpickle != 3.0.0

[options.packages.find]
Expand Down

0 comments on commit 59b235f

Please sign in to comment.