[ovs-dev] [python 3/7] stream.py: Make usage() function return a string.

Ethan Jackson ethan at nicira.com
Mon Sep 26 23:49:23 UTC 2011


This will marginally simplify a future patch.
---
 python/ovs/stream.py  |   19 ++++++++++++-------
 tests/test-jsonrpc.py |    2 +-
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/python/ovs/stream.py b/python/ovs/stream.py
index 5180642..9d8da21 100644
--- a/python/ovs/stream.py
+++ b/python/ovs/stream.py
@@ -303,13 +303,18 @@ class PassiveStream(object):
 
 
 def usage(name, active, passive):
-    print
+    string = ""
     if active:
-        print("Active %s connection methods:" % name)
-        print("  unix:FILE               "
-               "Unix domain socket named FILE")
+        string += "\nActive %s connection methods:" % name
+        string += ("\n  unix:FILE               "
+                   "Unix domain socket named FILE")
 
     if passive:
-        print("Passive %s connection methods:" % name)
-        print("  punix:FILE              "
-              "listen on Unix domain socket FILE")
+        if active:
+            string += "\n"
+
+        string += "\nPassive %s connection methods:" % name
+        string += ("\n  punix:FILE              "
+                   "listen on Unix domain socket FILE")
+
+    return string
diff --git a/tests/test-jsonrpc.py b/tests/test-jsonrpc.py
index 9da3bd2..2eca393 100644
--- a/tests/test-jsonrpc.py
+++ b/tests/test-jsonrpc.py
@@ -212,7 +212,7 @@ usage: %s [OPTIONS] COMMAND [ARG...]
   request REMOTE METHOD PARAMS   send request, print reply
   notify REMOTE METHOD PARAMS  send notification and exit
 """ % (ovs.util.PROGRAM_NAME, ovs.util.PROGRAM_NAME))
-    ovs.stream.usage("JSON-RPC", True, True)
+    sys.stdout.write(ovs.stream.usage("JSON-RPC", True, True))
     ovs.daemon.usage()
     sys.stdout.write("""
 Other options:
-- 
1.7.6.1




More information about the dev mailing list