python: Use os.path.basename instead of open-coding it.
authorBen Pfaff <blp@nicira.com>
Wed, 12 Jan 2011 21:43:22 +0000 (13:43 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 12 Jan 2011 21:51:42 +0000 (13:51 -0800)
Reported-by: Justin Pettit <jpettit@nicira.com>
build-aux/check-structs
python/ovs/util.py

index f582e2b..536045f 100755 (executable)
@@ -1,5 +1,6 @@
 #! /usr/bin/python
 
+import os.path
 import sys
 import re
 
@@ -193,10 +194,7 @@ def checkStructs():
         sys.exit(1)
 
     if '--help' in sys.argv:
-        argv0 = sys.argv[0]
-        slash = argv0.rfind('/')
-        if slash:
-            argv0 = argv0[slash + 1:]
+        argv0 = os.path.basename(sys.argv[0])
         print '''\
 %(argv0)s, for checking struct and struct member alignment
 usage: %(argv0)s HEADER [HEADER]...
index d4460f3..aa4b9bc 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2010 Nicira Networks
+# Copyright (c) 2010, 2011 Nicira Networks
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # limitations under the License.
 
 import os
+import os.path
 import sys
 
-_argv0 = sys.argv[0]
-PROGRAM_NAME = _argv0[_argv0.rfind('/') + 1:]
+PROGRAM_NAME = os.path.basename(sys.argv[0])
 
 def abs_file_name(dir, file_name):
     """If 'file_name' starts with '/', returns a copy of 'file_name'.