Bug 1595982 - make mozharness::base::log.py and errors.py python3 compatible r=aki
authorEdwin Takahashi <egao@mozilla.com>
Mon, 18 Nov 2019 18:20:16 +0000
changeset 502519 59d5dcf22862ff998d5f08fcf42309bdb0fc066d
parent 502518 4f123ce2cc07772d932aae792a39a38f3ce765fa
child 502520 6a9a26055f9c47058638838305867c87e86eddec
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaki
bugs1595982
milestone72.0a1
Bug 1595982 - make mozharness::base::log.py and errors.py python3 compatible r=aki Changes: Reorder imports and general code style fixes. Change reference to `basestring` to `six.string_types`. Explicitly cast potential view object. Depends on D52791 Differential Revision: https://phabricator.services.mozilla.com/D53119
testing/mozharness/mozharness/base/errors.py
testing/mozharness/mozharness/base/log.py
--- a/testing/mozharness/mozharness/base/errors.py
+++ b/testing/mozharness/mozharness/base/errors.py
@@ -16,17 +16,17 @@ TODO: Context lines (requires work on th
 
 TODO: We could also create classes that generate these, but with the
 appropriate level (please don't die on any errors; please die on any
 warning; etc.) or platform or language or whatever.
 """
 
 import re
 
-from mozharness.base.log import DEBUG, WARNING, ERROR, CRITICAL, FATAL
+from mozharness.base.log import CRITICAL, DEBUG, ERROR, FATAL, WARNING
 
 
 # Exceptions
 class VCSException(Exception):
     pass
 
 
 # ErrorLists {{{1
@@ -106,17 +106,18 @@ GitErrorList = BaseErrorList + [
     {'substr': r'''does not appear to be a git repository''', 'level': ERROR},
     {'substr': r'''error: src refspec''', 'level': ERROR},
     {'substr': r'''invalid author/committer line -''', 'level': ERROR},
     {'substr': r'''remote: fatal: Error in object''', 'level': ERROR},
     {'substr': r'''fatal: sha1 file '<stdout>' write error: Broken pipe''', 'level': ERROR},
     {'substr': r'''error: failed to push some refs to ''', 'level': ERROR},
     {'substr': r'''remote: error: denying non-fast-forward ''', 'level': ERROR},
     {'substr': r'''! [remote rejected] ''', 'level': ERROR},
-    {'regex': re.compile(r'''remote:.*No such file or directory'''), 'level': ERROR},
+    {'regex': re.compile(
+        r'''remote:.*No such file or directory'''), 'level': ERROR},
 ]
 
 PythonErrorList = BaseErrorList + [
     {'regex': re.compile(r'''Warning:.*Error: '''), 'level': WARNING},
     {'substr': r'''Traceback (most recent call last)''', 'level': ERROR},
     {'substr': r'''SyntaxError: ''', 'level': ERROR},
     {'substr': r'''TypeError: ''', 'level': ERROR},
     {'substr': r'''NameError: ''', 'level': ERROR},
@@ -141,17 +142,18 @@ RustErrorList = [
 
 # We may need to have various MakefileErrorLists for differing amounts of
 # warning-ignoring-ness.
 MakefileErrorList = BaseErrorList + PythonErrorList + RustErrorList + [
     {'substr': r'''No rule to make target ''', 'level': ERROR},
     {'regex': re.compile(r'''akefile.*was not found\.'''), 'level': ERROR},
     {'regex': re.compile(r'''Stop\.$'''), 'level': ERROR},
     {'regex': re.compile(r''':\d+: error:'''), 'level': ERROR},
-    {'regex': re.compile(r'''make\[\d+\]: \*\*\* \[.*\] Error \d+'''), 'level': ERROR},
+    {'regex': re.compile(
+        r'''make\[\d+\]: \*\*\* \[.*\] Error \d+'''), 'level': ERROR},
     {'regex': re.compile(r''':\d+: warning:'''), 'level': WARNING},
     {'regex': re.compile(r'''make(?:\[\d+\])?: \*\*\*/'''), 'level': ERROR},
     {'substr': r'''Warning: ''', 'level': WARNING},
 ]
 
 TarErrorList = BaseErrorList + [
     {'substr': r'''(stdin) is not a bzip2 file.''', 'level': ERROR},
     {'regex': re.compile(r'''Child returned status [1-9]'''), 'level': ERROR},
--- a/testing/mozharness/mozharness/base/log.py
+++ b/testing/mozharness/mozharness/base/log.py
@@ -21,22 +21,24 @@ Attributes:
 
 TODO:
 - network logging support.
 - log rotation config
 """
 
 from __future__ import print_function
 
-from datetime import datetime
 import logging
 import os
 import sys
 import time
 import traceback
+from datetime import datetime
+
+from six import string_types
 
 # Define our own FATAL_LEVEL
 FATAL_LEVEL = logging.CRITICAL + 10
 logging.addLevelName(FATAL_LEVEL, 'FATAL')
 
 # mozharness log levels.
 DEBUG, INFO, WARNING, ERROR, CRITICAL, FATAL, IGNORE = (
     'debug', 'info', 'warning', 'error', 'critical', 'fatal', 'ignore')
@@ -345,17 +347,17 @@ class OutputParser(LogMixin):
         them of any trailing whitespaces and parse them using `parse_single_line`
 
         strings consisting only of whitespaces are ignored.
 
         Args:
             output (str | list): string or list of string to parse
         """
 
-        if isinstance(output, basestring):
+        if isinstance(output, string_types):
             output = [output]
         for line in output:
             if not line or line.isspace():
                 continue
             line = line.decode("utf-8", 'replace').rstrip()
             self.parse_single_line(line)
 
 
@@ -626,17 +628,18 @@ class SimpleFileLogger(BaseLogger):
                             log_dir=log_dir, **kwargs)
         self.new_logger()
         self.init_message()
 
     def new_logger(self):
         """ calls the BaseLogger.new_logger method and adds a file handler to it."""
 
         BaseLogger.new_logger(self)
-        self.log_path = os.path.join(self.abs_log_dir, '%s.log' % self.log_name)
+        self.log_path = os.path.join(
+            self.abs_log_dir, '%s.log' % self.log_name)
         self.log_files['default'] = self.log_path
         self.add_file_handler(self.log_path)
 
 
 # MultiFileLogger {{{1
 class MultiFileLogger(BaseLogger):
     """Subclass of the BaseLogger class. Create a log per log level in log_dir.
     Possibly also output to the terminal and a raw log (no prepending of level or date)
@@ -671,17 +674,17 @@ class MultiFileLogger(BaseLogger):
 
     def new_logger(self):
         """ calls the BaseLogger.new_logger method and adds a file handler per
         logging level in the `LEVELS` class attribute.
         """
 
         BaseLogger.new_logger(self)
         min_logger_level = self.get_logger_level(self.log_level)
-        for level in self.LEVELS.keys():
+        for level in list(self.LEVELS.keys()):
             if self.get_logger_level(level) >= min_logger_level:
                 self.log_files[level] = '%s_%s.log' % (self.log_name,
                                                        level)
                 self.add_file_handler(os.path.join(self.abs_log_dir,
                                                    self.log_files[level]),
                                       log_level=level)