[ovs-dev] [PATCH 1/2] ovs-dev.py: PEP-8ify.

Joe Stringer joe at ovn.org
Mon May 16 21:56:58 UTC 2016


Signed-off-by: Joe Stringer <joe at ovn.org>
---
 utilities/ovs-dev.py | 54 +++++++++++++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/utilities/ovs-dev.py b/utilities/ovs-dev.py
index 524f574ff092..0ba4280a8ddf 100755
--- a/utilities/ovs-dev.py
+++ b/utilities/ovs-dev.py
@@ -1,5 +1,5 @@
-#! /usr/bin/env python
-# Copyright (c) 2013, 2014, 2015 Nicira, Inc.
+#!/usr/bin/env python
+# Copyright (c) 2013, 2014, 2015, 2016 Nicira, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -34,13 +34,15 @@ options = None
 parser = None
 commands = []
 
+
 def set_path(build):
     PATH = "%(ovs)s/utilities:%(ovs)s/ovsdb:%(ovs)s/vswitchd" % {"ovs": build}
 
     ENV["PATH"] = PATH + ":" + ENV["PATH"]
 
+
 def _sh(*args, **kwargs):
-    print "------> " + " ".join(args)
+    print("------> " + " ".join(args))
     shell = len(args) == 1
     if kwargs.get("capture", False):
         proc = subprocess.Popen(args, stdout=subprocess.PIPE, shell=shell)
@@ -60,6 +62,7 @@ def sudo():
         _sh(" ".join(["sudo"] + sys.argv), check=True)
         sys.exit(0)
 
+
 def conf():
     tag()
 
@@ -87,7 +90,7 @@ def conf():
 
     if options.with_dpdk:
         configure.append("--with-dpdk=" + options.with_dpdk)
-        cflags += " -Wno-cast-align -Wno-bad-function-cast" # DPDK warnings.
+        cflags += " -Wno-cast-align -Wno-bad-function-cast"  # DPDK warnings.
 
     if options.optimize is None:
         options.optimize = 0
@@ -101,7 +104,7 @@ def conf():
     try:
         os.mkdir(BUILD_GCC)
     except OSError:
-        pass # Directory exists.
+        pass  # Directory exists.
 
     os.chdir(BUILD_GCC)
     _sh(*(configure + ["--with-linux=/lib/modules/%s/build" % uname()]))
@@ -122,7 +125,7 @@ def conf():
         try:
             os.mkdir(BUILD_CLANG)
         except OSError:
-            pass # Directory exists.
+            pass  # Directory exists.
 
         ENV["CC"] = "clang"
         os.chdir(BUILD_CLANG)
@@ -235,9 +238,9 @@ def run():
     if (options.user == "") or (options.user == "root:root"):
         _sh("chown", "root:root", "-R", RUNDIR)
         if '--user' in sys.argv:
-           sys.argv.remove("--user")
+            sys.argv.remove("--user")
     else:
-        _sh("chown", options.user, "-R", RUNDIR);
+        _sh("chown", options.user, "-R", RUNDIR)
         opts = ["--user", options.user] + opts
 
     if (options.monitor):
@@ -251,7 +254,7 @@ def run():
            "--bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert",
            "--detach", "-vconsole:off"] + opts))
 
-    _sh("ovs-vsctl --no-wait --bootstrap set-ssl %s/ovsclient-privkey.pem" \
+    _sh("ovs-vsctl --no-wait --bootstrap set-ssl %s/ovsclient-privkey.pem"
         " %s/ovsclient-cert.pem %s/vswitchd.cacert"
         % (pki_dir, pki_dir, pki_dir))
     version = _sh("ovs-vsctl --no-wait --version", capture=True)
@@ -265,12 +268,12 @@ def run():
     cmd = [build + "/vswitchd/ovs-vswitchd"]
 
     if options.dpdk:
-        _sh("ovs-vsctl --no-wait set Open_vSwitch %s " \
+        _sh("ovs-vsctl --no-wait set Open_vSwitch %s "
             "other_config:dpdk-init=true" % root_uuid)
-        _sh("ovs-vsctl --no-wait set Open_vSwitch %s other_config:" \
+        _sh("ovs-vsctl --no-wait set Open_vSwitch %s other_config:"
             "dpdk-extra=\"%s\"" % (root_uuid, ' '.join(options.dpdk)))
     else:
-        _sh("ovs-vsctl --no-wait set Open_vSwitch %s " \
+        _sh("ovs-vsctl --no-wait set Open_vSwitch %s "
             "other_config:dpdk-init=false" % root_uuid)
 
     if options.gdb:
@@ -287,7 +290,7 @@ commands.append(run)
 
 def modinst():
     if not os.path.exists("/lib/modules"):
-        print "Missing modules directory.  Is this a Linux system?"
+        print("Missing modules directory.  Is this a Linux system?")
         sys.exit(1)
 
     sudo()
@@ -308,19 +311,19 @@ def modinst():
 
     _sh("modprobe", "openvswitch")
     _sh("dmesg | grep openvswitch | tail -1")
-    _sh("find /lib/modules/%s/ -iname vport-*.ko -exec insmod '{}' \;" % uname())
+    _sh("find /lib/modules/%s/ -iname vport-*.ko -exec insmod '{}' \;"
+        % uname())
 commands.append(modinst)
 
 
 def env():
-    print "export PATH=" + ENV["PATH"]
+    print("export PATH=" + ENV["PATH"])
 commands.append(env)
 
 
 def doc():
     parser.print_help()
-    print \
-"""
+    print("""
 This program is designed to help developers build and run Open vSwitch without
 necessarily needing to know the gory details. Given some basic requirements
 (described below), it can be used to build and run Open vSwitch, keeping
@@ -368,10 +371,11 @@ Commands:
 Note:
     If running as non-root user, "kill", "reset", "run" and "modinst"
     will always run as the root user, by rerun the commands with "sudo".
-""" % {"ovs": OVS_SRC, "v": sys.argv[0], "run": RUNDIR}
+""" % {"ovs": OVS_SRC, "v": sys.argv[0], "run": RUNDIR})
     sys.exit(0)
 commands.append(doc)
 
+
 def parse_subargs(option, opt_str, value, parser):
     subopts = []
 
@@ -383,16 +387,15 @@ def parse_subargs(option, opt_str, value, parser):
 
     setattr(parser.values, option.dest, subopts)
 
+
 def main():
     global options
     global parser
 
     description = "Open vSwitch developer configuration. Try `%prog doc`."
     cmd_names = [c.__name__ for c in commands]
-    parser = optparse.OptionParser(usage="usage: %prog"
-                                   + " [options] [%s] ..."
-                                   % "|".join(cmd_names),
-                                   description=description)
+    usage = "usage: %prog" + " [options] [%s] ..." % "|".join(cmd_names)
+    parser = optparse.OptionParser(usage=usage, description=description)
 
     group = optparse.OptionGroup(parser, "conf")
     group.add_option("--disable-Werror", dest="werror", action="store_false",
@@ -402,7 +405,7 @@ def main():
     group.add_option("--mandir", dest="mandir", metavar="MANDIR",
                      help="configure the man documentation install directory")
     group.add_option("--with-dpdk", dest="with_dpdk", metavar="DPDK_BUILD",
-                     help="built with dpdk libraries located at DPDK_BUILD");
+                     help="built with dpdk libraries located at DPDK_BUILD")
     parser.add_option_group(group)
 
     group = optparse.OptionGroup(parser, "Optimization Flags")
@@ -435,14 +438,13 @@ def main():
     group.add_option("--monitor", dest="monitor", action="store_true",
                      help="run daemons with --monitor option")
 
-
     parser.add_option_group(group)
 
     options, args = parser.parse_args()
 
     for arg in args:
         if arg not in cmd_names:
-            print "Unknown argument " + arg
+            print("Unknown argument " + arg)
             doc()
 
     if options.clang:
@@ -453,7 +455,7 @@ def main():
     try:
         os.chdir(OVS_SRC)
     except OSError:
-        print "Missing %s." % OVS_SRC
+        print("Missing %s." % OVS_SRC)
         doc()
 
     for arg in args:
-- 
2.8.2




More information about the dev mailing list