summaryrefslogtreecommitdiffstats
path: root/pifconfig.py
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2011-06-21 10:06:36 +0200
committerDavid Sommerseth <davids@redhat.com>2011-06-21 10:09:29 +0200
commita45819ecb5580aeeb09c6c2201929257f5d311d2 (patch)
treea47ce3b433e9ceacb22f0a3daaef3bffe1b0f71d /pifconfig.py
parent8441ab7cfab41dce94b72694933a648eb130568b (diff)
downloadpython-ethtool-a45819ecb5580aeeb09c6c2201929257f5d311d2.tar.gz
python-ethtool-a45819ecb5580aeeb09c6c2201929257f5d311d2.tar.xz
python-ethtool-a45819ecb5580aeeb09c6c2201929257f5d311d2.zip
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>
Diffstat (limited to 'pifconfig.py')
-rwxr-xr-xpifconfig.py34
1 files changed, 14 insertions, 20 deletions
diff --git a/pifconfig.py b/pifconfig.py
index cfaa2a6..d509483 100755
--- a/pifconfig.py
+++ b/pifconfig.py
@@ -15,11 +15,7 @@
# General Public License for more details.
import getopt, ethtool, sys
-
-def usage():
- print '''Usage:
- pifconfig <interface>
-'''
+from optparse import OptionParser
def flags2str(flags):
string = ""
@@ -76,23 +72,21 @@ def show_config(device):
def main():
global all_devices
- try:
- opts, args = getopt.getopt(sys.argv[1:],
- "h",
- ("help",))
- except getopt.GetoptError, err:
- usage()
- print str(err)
- sys.exit(2)
+ usage="usage: %prog [interface [interface [interface] ...]]"
+ parser = OptionParser(usage=usage)
+ (opts, args) = parser.parse_args()
- for o, a in opts:
- if o in ("-h", "--help"):
- usage()
- return
+ if args is None or len(args) == 0:
+ sel_devs = ethtool.get_active_devices()
+ else:
+ sel_devs = args
- active_devices = ethtool.get_active_devices()
- for device in active_devices:
- show_config(device)
+ for device in sel_devs:
+ try:
+ show_config(device)
+ except Exception, ex:
+ print "** ERROR ** [Device %s]: %s" % (device, str(ex))
+ sys.exit(2)
if __name__ == '__main__':
main()