Skip to content

Commit

Permalink
ovs-dev.py: PEP-8ify.
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Stringer <[email protected]>
  • Loading branch information
joestringer committed May 18, 2016
1 parent 1d349d0 commit c6b581b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion utilities/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
60 changes: 31 additions & 29 deletions utilities/ovs-dev.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,7 +18,7 @@
import shutil
import subprocess
import sys
import tempfile
import time

ENV = os.environ
HOME = ENV["HOME"]
Expand All @@ -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)
Expand All @@ -60,6 +62,7 @@ def sudo():
_sh(" ".join(["sudo"] + sys.argv), check=True)
sys.exit(0)


def conf():
tag()

Expand Down Expand Up @@ -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
Expand All @@ -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()]))
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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 = []

Expand All @@ -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",
Expand All @@ -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")
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit c6b581b

Please sign in to comment.