autotest: (base_job) delete TAPReport and all callers

This looks unused.

BUG=None
TEST=None

Change-Id: I7ceff7c4c546eba72ab6c24e66abe759077a758c
Reviewed-on: https://chromium-review.googlesource.com/509013
Commit-Ready: Aviv Keshet <akeshet@chromium.org>
Tested-by: Aviv Keshet <akeshet@chromium.org>
Reviewed-by: Keith Haddow <haddowk@chromium.org>
Reviewed-by: Richard Barnette <jrbarnette@google.com>
diff --git a/client/bin/autotest b/client/bin/autotest
index 7d36a05..21845dd 100755
--- a/client/bin/autotest
+++ b/client/bin/autotest
@@ -65,8 +65,7 @@
                        'the server. Use all to prebuild all of them.')
 
 parser.add_option('--tap', dest='tap_report', action='store_true',
-                  default=None, help='Output TAP (Test anything '
-                  'protocol) reports')
+                  default=None, help='Deprecated, do not use.')
 
 def usage():
     parser.print_help()
diff --git a/client/bin/job.py b/client/bin/job.py
index 4077a3e..c3d4aea 100644
--- a/client/bin/job.py
+++ b/client/bin/job.py
@@ -226,8 +226,7 @@
             # send the entry to stdout, if it's enabled
             logging.info(rendered_entry)
         self._logger = base_job.status_logger(
-            self, status_indenter(self), record_hook=client_job_record_hook,
-            tap_writer=self._tap)
+            self, status_indenter(self), record_hook=client_job_record_hook)
 
 
     def _post_record_init(self, control, options, drop_caches):
@@ -839,12 +838,7 @@
 
 
     def complete(self, status):
-        """Write pending TAP reports, clean up, and exit"""
-        # write out TAP reports
-        if self._tap.do_tap_report:
-            self._tap.write()
-            self._tap._write_tap_archive()
-
+        """Write pending reports, clean up, and exit"""
         # write out a job HTML report
         try:
             html_report.create_report(self.resultdir)
diff --git a/client/bin/job_unittest.py b/client/bin/job_unittest.py
index b3107df..7ca279b 100755
--- a/client/bin/job_unittest.py
+++ b/client/bin/job_unittest.py
@@ -93,7 +93,6 @@
             log = False
             args = ''
             output_dir = ''
-            tap_report = None
         self.god.stub_function_to_return(job.utils, 'drop_caches', None)
 
         self.job._job_state = base_job_unittest.stub_job_state
@@ -239,7 +238,6 @@
         options.user = 'my_user'
         options.args = ''
         options.output_dir = ''
-        options.tap_report = None
         self.job.__init__(self.control, options)
 
         # check
@@ -280,7 +278,6 @@
         options.user = 'my_user'
         options.args = ''
         options.output_dir = ''
-        options.tap_report = None
         error = Exception('fail')
 
         self.god.stub_function(self.job, '_post_record_init')
diff --git a/client/bin/setup_job_unittest.py b/client/bin/setup_job_unittest.py
index cd45725..1037a5f 100755
--- a/client/bin/setup_job_unittest.py
+++ b/client/bin/setup_job_unittest.py
@@ -84,7 +84,6 @@
             hostname = None
             user = None
             log = False
-            tap_report = None
             output_dir = False
 
         self.job.__init__(options)
@@ -176,7 +175,6 @@
         options.verbose = False
         options.hostname = 'localhost'
         options.user = 'my_user'
-        options.tap_report = None
         options.output_dir = False
         self.job.__init__(options)
 
diff --git a/client/common_lib/base_job.py b/client/common_lib/base_job.py
index 5ccfd2d..91dc8e4 100644
--- a/client/common_lib/base_job.py
+++ b/client/common_lib/base_job.py
@@ -1,9 +1,16 @@
 # pylint: disable=missing-docstring
 
-import os, copy, logging, errno, fcntl, time, re, weakref, traceback
-import tarfile
 import cPickle as pickle
+import copy
+import errno
+import fcntl
+import logging
+import os
+import re
 import tempfile
+import time
+import traceback
+import weakref
 from autotest_lib.client.common_lib import autotemp, error, log
 
 
@@ -597,8 +604,7 @@
     @property subdir_filename: The filename to write subdir-level logs to.
     """
     def __init__(self, job, indenter, global_filename='status',
-                 subdir_filename='status', record_hook=None,
-                 tap_writer=None):
+                 subdir_filename='status', record_hook=None):
         """Construct a logger instance.
 
         @param job: A reference to the job object this is logging for. Only a
@@ -613,18 +619,12 @@
         @param record_hook: An optional function to be called before an entry
             is logged. The function should expect a single parameter, a
             copy of the status_log_entry object.
-        @param tap_writer: An instance of the class TAPReport for addionally
-            writing TAP files
         """
         self._jobref = weakref.ref(job)
         self._indenter = indenter
         self.global_filename = global_filename
         self.subdir_filename = subdir_filename
         self._record_hook = record_hook
-        if tap_writer is None:
-            self._tap_writer = TAPReport(None)
-        else:
-            self._tap_writer = tap_writer
 
 
     def render_entry(self, log_entry):
@@ -677,10 +677,6 @@
             finally:
                 fileobj.close()
 
-        # write to TAPRecord instance
-        if log_entry.is_end() and self._tap_writer.do_tap_report:
-            self._tap_writer.record(log_entry, self._indenter.indent, log_files)
-
         # adjust the indentation if this was a START or END entry
         if log_entry.is_start():
             self._indenter.increment()
@@ -688,191 +684,6 @@
             self._indenter.decrement()
 
 
-class TAPReport(object):
-    """
-    Deal with TAP reporting for the Autotest client.
-    """
-
-    job_statuses = {
-        "TEST_NA": False,
-        "ABORT": False,
-        "ERROR": False,
-        "FAIL": False,
-        "WARN": False,
-        "GOOD": True,
-        "START": True,
-        "END GOOD": True,
-        "ALERT": False,
-        "RUNNING": False,
-        "NOSTATUS": False
-    }
-
-
-    def __init__(self, enable, resultdir=None, global_filename='status'):
-        """
-        @param enable: Set self.do_tap_report to trigger TAP reporting.
-        @param resultdir: Path where the TAP report files will be written.
-        @param global_filename: File name of the status files .tap extensions
-                will be appended.
-        """
-        self.do_tap_report = enable
-        if resultdir is not None:
-            self.resultdir = os.path.abspath(resultdir)
-        self._reports_container = {}
-        self._keyval_container = {} # {'path1': [entries],}
-        self.global_filename = global_filename
-
-
-    @classmethod
-    def tap_ok(self, success, counter, message):
-        """
-        return a TAP message string.
-
-        @param success: True for positive message string.
-        @param counter: number of TAP line in plan.
-        @param message: additional message to report in TAP line.
-        """
-        if success:
-            message = "ok %s - %s" % (counter, message)
-        else:
-            message = "not ok %s - %s" % (counter, message)
-        return message
-
-
-    def record(self, log_entry, indent, log_files):
-        """
-        Append a job-level status event to self._reports_container. All
-        events will be written to TAP log files at the end of the test run.
-        Otherwise, it's impossilble to determine the TAP plan.
-
-        @param log_entry: A string status code describing the type of status
-                entry being recorded. It must pass log.is_valid_status to be
-                considered valid.
-        @param indent: Level of the log_entry to determine the operation if
-                log_entry.operation is not given.
-        @param log_files: List of full path of files the TAP report will be
-                written to at the end of the test.
-        """
-        for log_file in log_files:
-            log_file_path = os.path.dirname(log_file)
-            key = log_file_path.split(self.resultdir, 1)[1].strip(os.sep)
-            if not key:
-                key = 'root'
-
-            if not self._reports_container.has_key(key):
-                self._reports_container[key] = []
-
-            if log_entry.operation:
-                operation = log_entry.operation
-            elif indent == 1:
-                operation = "job"
-            else:
-                operation = "unknown"
-            entry = self.tap_ok(
-                self.job_statuses.get(log_entry.status_code, False),
-                len(self._reports_container[key]) + 1, operation + "\n"
-            )
-            self._reports_container[key].append(entry)
-
-
-    def record_keyval(self, path, dictionary, type_tag=None):
-        """
-        Append a key-value pairs of dictionary to self._keyval_container in
-        TAP format. Once finished write out the keyval.tap file to the file
-        system.
-
-        If type_tag is None, then the key must be composed of alphanumeric
-        characters (or dashes + underscores). However, if type-tag is not
-        null then the keys must also have "{type_tag}" as a suffix. At
-        the moment the only valid values of type_tag are "attr" and "perf".
-
-        @param path: The full path of the keyval.tap file to be created
-        @param dictionary: The keys and values.
-        @param type_tag: The type of the values
-        """
-        self._keyval_container.setdefault(path, [0, []])
-        self._keyval_container[path][0] += 1
-
-        if type_tag is None:
-            key_regex = re.compile(r'^[-\.\w]+$')
-        else:
-            if type_tag not in ('attr', 'perf'):
-                raise ValueError('Invalid type tag: %s' % type_tag)
-            escaped_tag = re.escape(type_tag)
-            key_regex = re.compile(r'^[-\.\w]+\{%s\}$' % escaped_tag)
-        self._keyval_container[path][1].extend([
-            self.tap_ok(True, self._keyval_container[path][0], "results"),
-            "\n  ---\n",
-        ])
-        try:
-            for key in sorted(dictionary.keys()):
-                if not key_regex.search(key):
-                    raise ValueError('Invalid key: %s' % key)
-                self._keyval_container[path][1].append(
-                    '  %s: %s\n' % (key.replace('{', '_').rstrip('}'),
-                                    dictionary[key])
-                )
-        finally:
-            self._keyval_container[path][1].append("  ...\n")
-        self._write_keyval()
-
-
-    def _write_reports(self):
-        """
-        Write TAP reports to file.
-        """
-        for key in self._reports_container.keys():
-            if key == 'root':
-                sub_dir = ''
-            else:
-                sub_dir = key
-            tap_fh = open(os.sep.join(
-                [self.resultdir, sub_dir, self.global_filename]
-            ) + ".tap", 'w')
-            tap_fh.write('1..' + str(len(self._reports_container[key])) + '\n')
-            tap_fh.writelines(self._reports_container[key])
-            tap_fh.close()
-
-
-    def _write_keyval(self):
-        """
-        Write the self._keyval_container key values to a file.
-        """
-        for path in self._keyval_container.keys():
-            tap_fh = open(path + ".tap", 'w')
-            tap_fh.write('1..' + str(self._keyval_container[path][0]) + '\n')
-            tap_fh.writelines(self._keyval_container[path][1])
-            tap_fh.close()
-
-
-    def write(self):
-        """
-        Write the TAP reports to files.
-        """
-        self._write_reports()
-
-
-    def _write_tap_archive(self):
-        """
-        Write a tar archive containing all the TAP files and
-        a meta.yml containing the file names.
-        """
-        os.chdir(self.resultdir)
-        tap_files = []
-        for rel_path, d, files in os.walk('.'):
-            tap_files.extend(["/".join(
-                [rel_path, f]) for f in files if f.endswith('.tap')])
-        meta_yaml = open('meta.yml', 'w')
-        meta_yaml.write('file_order:\n')
-        tap_tar = tarfile.open(self.resultdir + '/tap.tar.gz', 'w:gz')
-        for f in tap_files:
-            meta_yaml.write("  - " + f.lstrip('./') + "\n")
-            tap_tar.add(f)
-        meta_yaml.close()
-        tap_tar.add('meta.yml')
-        tap_tar.close()
-
-
 class base_job(object):
     """An abstract base class for the various autotest job classes.
 
@@ -1016,11 +827,6 @@
         # initialize all the job state
         self._state = self._job_state()
 
-        # initialize tap reporting
-        if dargs.has_key('options'):
-            self._tap = self._tap_init(dargs['options'].tap_report)
-        else:
-            self._tap = self._tap_init(False)
 
     @classmethod
     def _find_base_directories(cls):
@@ -1185,11 +991,6 @@
                               subdir, e)
             raise error.TestError('%s directory creation failed' % subdir)
 
-    def _tap_init(self, enable):
-        """Initialize TAP reporting
-        """
-        return TAPReport(enable, resultdir=self.resultdir)
-
 
     def record(self, status_code, subdir, operation, status='',
                optional_fields=None):
diff --git a/client/common_lib/test.py b/client/common_lib/test.py
index 177e624..f0fea0e 100644
--- a/client/common_lib/test.py
+++ b/client/common_lib/test.py
@@ -77,8 +77,7 @@
 
 
     def write_test_keyval(self, attr_dict):
-        utils.write_keyval(self.outputdir, attr_dict,
-                           tap_report=self.job._tap)
+        utils.write_keyval(self.outputdir, attr_dict)
 
 
     @staticmethod
@@ -224,29 +223,25 @@
 
 
     def write_perf_keyval(self, perf_dict):
-        self.write_iteration_keyval({}, perf_dict,
-                                    tap_report=self.job._tap)
+        self.write_iteration_keyval({}, perf_dict)
 
 
     def write_attr_keyval(self, attr_dict):
-        self.write_iteration_keyval(attr_dict, {},
-                                    tap_report=self.job._tap)
+        self.write_iteration_keyval(attr_dict, {})
 
 
-    def write_iteration_keyval(self, attr_dict, perf_dict, tap_report=None):
+    def write_iteration_keyval(self, attr_dict, perf_dict):
         # append the dictionaries before they have the {perf} and {attr} added
         self._keyvals.append({'attr':attr_dict, 'perf':perf_dict})
         self._new_keyval = True
 
         if attr_dict:
             attr_dict = self._append_type_to_keys(attr_dict, "attr")
-            utils.write_keyval(self.resultsdir, attr_dict, type_tag="attr",
-                               tap_report=tap_report)
+            utils.write_keyval(self.resultsdir, attr_dict, type_tag="attr")
 
         if perf_dict:
             perf_dict = self._append_type_to_keys(perf_dict, "perf")
-            utils.write_keyval(self.resultsdir, perf_dict, type_tag="perf",
-                               tap_report=tap_report)
+            utils.write_keyval(self.resultsdir, perf_dict, type_tag="perf")
 
         keyval_path = os.path.join(self.resultsdir, "keyval")
         print >> open(keyval_path, "a"), ""
diff --git a/client/common_lib/test_unittest.py b/client/common_lib/test_unittest.py
index a269207..44f088f 100755
--- a/client/common_lib/test_unittest.py
+++ b/client/common_lib/test_unittest.py
@@ -169,7 +169,6 @@
         """
         # Stubbed out for the write_keyval call.
         self.test.outputdir = '/tmp'
-        self.test.job._tap = None
 
         num_to_fail = 2
         self.test.job.test_retry = 5
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index 2fe566e..81f8091f 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -517,7 +517,7 @@
     return keyval
 
 
-def write_keyval(path, dictionary, type_tag=None, tap_report=None):
+def write_keyval(path, dictionary, type_tag=None):
     """
     Write a key-value pair format file out to a file. This uses append
     mode to open the file, so existing text will not be overwritten or
@@ -551,10 +551,6 @@
     finally:
         keyval.close()
 
-    # same for tap
-    if tap_report is not None and tap_report.do_tap_report:
-        tap_report.record_keyval(path, dictionary, type_tag=type_tag)
-
 
 def is_url(path):
     """Return true if path looks like a URL"""