Make mtedit Python 3 compatible
Due to the way relative imports work in Python 3, mtedit/main.py has to
be moved outside of the mtedit package, as when run using its hashbang
line it is package `__main__`, and therefore cannot use relative
imports.
The other manual changes are:
* to properly distinguish between strings and binary data in
mtlib/util.py, mtlib/log.py, and mtedit/server.py;
* to switch between methods for getting headers in mtedit/server.py; and
* updating some `import` statements (as well as removing unused ones).
The rest of the changes were done using `futurize`:
$ futurize --stage1 --all-imports --write --nobackups mtedit/**/*.py
Two features remain broken:
* retrieving logs over SSH fails to retrieve
/var/log/xorg/cmt_input_events.dat, but that was broken already; and
* editing logs by adding the `-o` switch and clicking the shrink button
in the Web UI fails to import `MTReplay`, presumably because I haven't
updated that module yet.
TEST=run `mtedit` with the path of a downloaded ZIP file, choose a log
to view, and check that you can view the data properly in the
browser.
BUG=none
Cq-Depend: chromium:2024460
Change-Id: Ie59c191d3bc2827d3e94e45a9a8a38e3d524a1a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/mttools/+/2025612
Tested-by: Harry Cutts <hcutts@chromium.org>
Reviewed-by: Sean O'Brien <seobrien@chromium.org>
Commit-Queue: Harry Cutts <hcutts@chromium.org>
diff --git a/mtlib/util.py b/mtlib/util.py
index 052a3f4..6ca628c 100644
--- a/mtlib/util.py
+++ b/mtlib/util.py
@@ -16,6 +16,7 @@
import re
import shlex
import shutil
+from six import string_types
import subprocess
import sys
import time
@@ -211,7 +212,7 @@
This method behaves the same as Execute, but throws an ExecuteException
if the command fails.
"""
- if isinstance(command, basestring):
+ if isinstance(command, string_types):
command = shlex.split(command)
(code, out) = __Execute(command, cwd, verbose, interactive)
if code != 0:
@@ -219,7 +220,7 @@
return out
def __Execute(command, cwd=None, verbose=False, interactive=False):
- if isinstance(command, basestring):
+ if isinstance(command, string_types):
command = shlex.split(command)
if cwd:
@@ -251,7 +252,8 @@
out = None
if not interactive:
- out = process.stdout.read().replace("\r", "").strip()
+ out = process.stdout.read().decode('utf-8', 'strict')
+ out = out.replace("\r", "").strip()
return (process.returncode, out)