Skip to content

Commit a45819e

Browse files
author
David Sommerseth
committed
Make pifconfig respect interface arguments from the command line
pifconfig did not pay attention to any arguments give on the command line, which should only list selected devices. This patch revamps the argument parsing, to behave as described in usage and man page. Signed-off-by: David Sommerseth <davids@redhat.com>
1 parent 8441ab7 commit a45819e

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

man/pifconfig.8.asciidoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pifconfig - display information about a network interface
88

99
SYNOPSIS
1010
--------
11-
pifconfig [INTERFACE]
11+
pifconfig [INTERFACE [INTERFACE [INTERFACE] ...]]
1212

1313

1414
DESCRIPTION
@@ -22,8 +22,8 @@ OPTIONS
2222
-------
2323

2424
INTERFACE::
25-
Display information about only this interface. If no interface is given
26-
then all interfaces are displayed.
25+
Display information about only the listed interfaces. If no interface is given
26+
all interfaces are displayed.
2727

2828
-h, --help::
2929
Show help message and exit.
@@ -39,4 +39,4 @@ AUTHORS
3939
-------
4040
Arnaldo Carvalho de Melo <acme@redhat.com>
4141

42-
Man page written by Miroslav Suchý <msuchy@redhat.com>
42+
Man page written by Miroslav Suchý <msuchy@redhat.com>, David Sommerseth <davids@redhat.com>

pifconfig.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
# General Public License for more details.
1616

1717
import getopt, ethtool, sys
18-
19-
def usage():
20-
print '''Usage:
21-
pifconfig <interface>
22-
'''
18+
from optparse import OptionParser
2319

2420
def flags2str(flags):
2521
string = ""
@@ -76,23 +72,21 @@ def show_config(device):
7672
def main():
7773
global all_devices
7874

79-
try:
80-
opts, args = getopt.getopt(sys.argv[1:],
81-
"h",
82-
("help",))
83-
except getopt.GetoptError, err:
84-
usage()
85-
print str(err)
86-
sys.exit(2)
75+
usage="usage: %prog [interface [interface [interface] ...]]"
76+
parser = OptionParser(usage=usage)
77+
(opts, args) = parser.parse_args()
8778

88-
for o, a in opts:
89-
if o in ("-h", "--help"):
90-
usage()
91-
return
79+
if args is None or len(args) == 0:
80+
sel_devs = ethtool.get_active_devices()
81+
else:
82+
sel_devs = args
9283

93-
active_devices = ethtool.get_active_devices()
94-
for device in active_devices:
95-
show_config(device)
84+
for device in sel_devs:
85+
try:
86+
show_config(device)
87+
except Exception, ex:
88+
print "** ERROR ** [Device %s]: %s" % (device, str(ex))
89+
sys.exit(2)
9690

9791
if __name__ == '__main__':
9892
main()

0 commit comments

Comments
 (0)