From c6b581b9c320fa06ceb32d2318cbfe8e9d9ce067 Mon Sep 17 00:00:00 2001 From: Joe Stringer Date: Sat, 14 May 2016 14:18:27 -0700 Subject: [PATCH] ovs-dev.py: PEP-8ify. Signed-off-by: Joe Stringer --- utilities/automake.mk | 2 +- utilities/ovs-dev.py | 60 ++++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/utilities/automake.mk b/utilities/automake.mk index 155de0e2322..1cc66b60c4d 100644 --- a/utilities/automake.mk +++ b/utilities/automake.mk @@ -148,6 +148,6 @@ utilities_nlmon_LDADD = lib/libopenvswitch.la endif FLAKE8_PYFILES += utilities/ovs-pcap.in \ - utilities/checkpatch.py + utilities/checkpatch.py utilities/ovs-dev.py include utilities/bugtool/automake.mk diff --git a/utilities/ovs-dev.py b/utilities/ovs-dev.py index 524f574ff09..6d8dda66a94 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. @@ -18,7 +18,7 @@ import shutil import subprocess import sys -import tempfile +import time ENV = os.environ HOME = ENV["HOME"] @@ -34,13 +34,15 @@ 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,19 +290,19 @@ def 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() try: _sh("rmmod", "openvswitch") - except subprocess.CalledProcessError, e: + except subprocess.CalledProcessError: pass # Module isn't loaded try: _sh("rm -f /lib/modules/%s/extra/openvswitch.ko" % uname()) _sh("rm -f /lib/modules/%s/extra/vport-*.ko" % uname()) - except subprocess.CalledProcessError, e: + except subprocess.CalledProcessError: pass # Module isn't installed conf() @@ -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 @@ def doc(): 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: