Closed feross closed 11 years ago
Might be worthwhile for find_interfaces
to return a namedtuple
,
Interface = namedtuple('Interface', [
'port',
'device',
'hard_address',
'soft_address'
])
...instead of unpacking the results each time.
I also wouldn't use PIPE, instead of using grep just use re.match
from python and use check_call
instead of Popen
.
Just my opinion, otherwise it looks fine.
I'm using PIPE to suppress messages to stderr because sometimes ifconfig complains about the device not existing. And I'm using Popen
instead of check_call
because I'm interested in the output of ifconfig. I don't think check_call
gives you output. Is there a better way to do this?
Something simple along the lines of (untested):
result = subprocess.check_output(
'ifconfig {device}'.format(device=device),
stderr=subprocess.STDOUT
)
# Optionally handle that case, no idea what the actual string is:
if 'device does not exist' in result:
# Error out?
pass
<do the regex here>
K, done.
@TkTech – code review for this?