From a45819ecb5580aeeb09c6c2201929257f5d311d2 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Tue, 21 Jun 2011 10:06:36 +0200 Subject: 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 --- pifconfig.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'pifconfig.py') 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 -''' +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() -- cgit