Futurize `mtstat` as much as possible
Downloading files now works on Python 2.7 again, though other things
still seem broken with various errors (though I'm not sure if they were
there before). I gave up on Python 3 compatibility, as the encoding
situation is just too confusing. (Reports are downloaded using the
`stubby` command, then extracted from its text proto output with
regexes, and then have to be turned back into binary again to be treated
as ZIP files. https://stackoverflow.com/a/24519338/1175455 is just a
taste of the problem.)
TEST=Run `python2.7 mtstat.py -d 10`, and check it succeeds. Some
invalid reports are to be expected.
BUG=none
Change-Id: Ia0eec0598f0ee8ab1ce203c370cc9748af4ab65d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/mttools/+/2044826
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/mtstat/queryengine.py b/mtstat/queryengine.py
index ab96b52..0d5ae2a 100755
--- a/mtstat/queryengine.py
+++ b/mtstat/queryengine.py
@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+from __future__ import absolute_import
+from __future__ import division
from __future__ import print_function
from mtlib.log import FeedbackDownloader, FeedbackLog, Log
@@ -218,8 +220,6 @@
downloader = FeedbackDownloader()
dt = datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)
- end_time = (((dt.days * 24 * 60 * 60 + dt.seconds) * 1000) +
- (dt.microseconds / 10))
num_to_download = int(num_to_download)
num_downloaded = 0
invalid_ids = self.GetInvalidIDs()
@@ -229,7 +229,7 @@
# Download list of feedback report id's
num_this_iteration = min((num_to_download - num_downloaded) * 5, 500)
page_token, report_ids = downloader.DownloadIDs(
- num_this_iteration, end_time, page_token)
+ num_this_iteration, page_token=page_token)
# Download and check each report
parameters = [(r_id, downloader, invalid_ids) for r_id in report_ids]
@@ -259,7 +259,7 @@
""" Wrapper for subprocesses to run ExecuteSingle """
try:
return QueryEngine().ExecuteSingle(args[0], args[1])
- except Exception, e:
+ except Exception as e:
traceback.print_exc()
raise e
@@ -267,6 +267,6 @@
""" Wrapper for subprocesses to run DownloadFile """
try:
return QueryEngine().DownloadFile(args[0], args[1], args[2])
- except Exception, e:
+ except Exception as e:
traceback.print_exc()
raise e