|
1 | | -#!/usr/bin/env python |
| 1 | +#!/usr/bin/env python3 |
2 | 2 | # |
3 | 3 | # Copyright 2014 Hewlett-Packard Development Company, L.P. |
4 | 4 | # |
|
23 | 23 | import datetime |
24 | 24 | from distutils import spawn |
25 | 25 | import fnmatch |
| 26 | +import io |
26 | 27 | import os |
27 | | -import os.path |
28 | 28 | import shutil |
29 | 29 | import subprocess |
30 | 30 | import sys |
@@ -109,9 +109,10 @@ def _bridge_list(): |
109 | 109 | # This method gets max version searching 'OpenFlow versions 0x1:0x'. |
110 | 110 | # And return a version value converted to an integer type. |
111 | 111 | def _get_ofp_version(): |
112 | | - process = subprocess.Popen(['ovs-ofctl', '--version'], stdout=subprocess.PIPE) |
| 112 | + process = subprocess.Popen(['ovs-ofctl', '--version'], |
| 113 | + stdout=subprocess.PIPE) |
113 | 114 | stdout, _ = process.communicate() |
114 | | - find_str = 'OpenFlow versions 0x1:0x' |
| 115 | + find_str = b'OpenFlow versions 0x1:0x' |
115 | 116 | offset = stdout.find(find_str) |
116 | 117 | return int(stdout[offset + len(find_str):-1]) - 1 |
117 | 118 |
|
@@ -206,7 +207,7 @@ def process_list(): |
206 | 207 |
|
207 | 208 | def compute_consoles(): |
208 | 209 | _header("Compute consoles") |
209 | | - for root, dirnames, filenames in os.walk('/opt/stack'): |
| 210 | + for root, _, filenames in os.walk('/opt/stack'): |
210 | 211 | for filename in fnmatch.filter(filenames, 'console.log'): |
211 | 212 | fullpath = os.path.join(root, filename) |
212 | 213 | _dump_cmd("sudo cat %s" % fullpath) |
@@ -234,12 +235,22 @@ def var_core(): |
234 | 235 | # tools out there that can do that sort of thing though. |
235 | 236 | _dump_cmd("ls -ltrah /var/core") |
236 | 237 |
|
| 238 | + |
| 239 | +def disable_stdio_buffering(): |
| 240 | + # re-open STDOUT as binary, then wrap it in a |
| 241 | + # TextIOWrapper, and write through everything. |
| 242 | + binary_stdout = io.open(sys.stdout.fileno(), 'wb', 0) |
| 243 | + sys.stdout = io.TextIOWrapper(binary_stdout, write_through=True) |
| 244 | + |
| 245 | + |
237 | 246 | def main(): |
238 | 247 | opts = get_options() |
239 | 248 | fname = filename(opts.dir, opts.name) |
240 | 249 | print("World dumping... see %s for details" % fname) |
241 | | - sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) |
242 | | - with open(fname, 'w') as f: |
| 250 | + |
| 251 | + disable_stdio_buffering() |
| 252 | + |
| 253 | + with io.open(fname, 'w') as f: |
243 | 254 | os.dup2(f.fileno(), sys.stdout.fileno()) |
244 | 255 | disk_space() |
245 | 256 | process_list() |
|
0 commit comments