[autotest] Use |json| instead of |simplejson|.

simplejson was moved into the library as of python 2.4. We're now at
python 2.6/2.7, and having to keep installing simplejson everywhere has
slowly turned into a hassle.  Since we can just trivially drop/rename
it, let's do so.

The rpc_interface parts of this change have been vetted, the rest is
done just as a s/simplejson/json/ across the code, which afaik should be
a safe thing to do.

BUG=None
TEST=unit, run_suite
DEPLOY=apache

Change-Id: Iab35f71157e7e5cd3be5291c776b07eb3283be8e
Reviewed-on: https://gerrit.chromium.org/gerrit/46424
Tested-by: Aviv Keshet <akeshet@chromium.org>
Reviewed-by: Alex Miller <milleral@chromium.org>
Commit-Queue: Aviv Keshet <akeshet@chromium.org>
diff --git a/client/common_lib/perf_expectations/expectation_checker.py b/client/common_lib/perf_expectations/expectation_checker.py
index 267cf35..5fe31ee 100644
--- a/client/common_lib/perf_expectations/expectation_checker.py
+++ b/client/common_lib/perf_expectations/expectation_checker.py
@@ -67,9 +67,9 @@
                           self._expectation_file_path, e.errno, e.strerror)
             raise e
         # Must import here to make it work with autotest.
-        import simplejson
+        import json
         try:
-            self._expectations = simplejson.load(expectation_file)
+            self._expectations = json.load(expectation_file)
         except ValueError, e:
             logging.error('ValueError parsing expectations %s(%s): %s',
                           self._expectation_file_path, e.errno, e.strerror)
diff --git a/frontend/afe/json_rpc/proxy.py b/frontend/afe/json_rpc/proxy.py
index 718bac3..cbb60e9 100644
--- a/frontend/afe/json_rpc/proxy.py
+++ b/frontend/afe/json_rpc/proxy.py
@@ -73,9 +73,9 @@
         return ServiceProxy(self.__serviceURL, name, self.__headers)
 
     def __call__(self, *args, **kwargs):
-        # pull in simplejson imports lazily so that the library isn't required
+        # pull in json imports lazily so that the library isn't required
         # unless you actually need to do encoding and decoding
-        from simplejson import decoder, encoder
+        from json import decoder, encoder
 
         postdata = encoder.JSONEncoder().encode({"method": self.__serviceName,
                                                 'params': args + (kwargs,),
diff --git a/frontend/afe/json_rpc/serviceHandler.py b/frontend/afe/json_rpc/serviceHandler.py
index 4d85fc0..50ea45f 100644
--- a/frontend/afe/json_rpc/serviceHandler.py
+++ b/frontend/afe/json_rpc/serviceHandler.py
@@ -21,7 +21,7 @@
 
 import traceback
 
-from simplejson import decoder, encoder
+from json import decoder, encoder
 
 def customConvertJson(value):
     """\
diff --git a/frontend/perf-dashboard/extract_perf.py b/frontend/perf-dashboard/extract_perf.py
index b5afb88..a289fdf 100644
--- a/frontend/perf-dashboard/extract_perf.py
+++ b/frontend/perf-dashboard/extract_perf.py
@@ -21,7 +21,7 @@
 import optparse
 import os
 import re
-import simplejson
+import json
 import sys
 import time
 
@@ -118,7 +118,7 @@
     result_out.append(perf_items)
     file_name = os.path.join(test_dir, result_dict['platform'] + '.txt')
     with open(file_name, 'a') as fp:
-        fp.write(simplejson.dumps(result_out) + '\n')
+        fp.write(json.dumps(result_out) + '\n')
 
     with open(os.path.join(output_dir, _COMPLETED_ID_FILE_NAME), 'a') as fp:
         fp.write(job_id + '\n')
@@ -246,7 +246,7 @@
     """
     charts = {}
     with open(_CHART_CONFIG_FILE, 'r') as fp:
-        charts = simplejson.loads(fp.read())
+        charts = json.loads(fp.read())
 
     # Compute the oldest date for the perf values that we want to consider.
     oldest_db_lookup_date = (
diff --git a/frontend/perf-dashboard/generate_perf_graphs.py b/frontend/perf-dashboard/generate_perf_graphs.py
index 44c09ae..d299a8c 100644
--- a/frontend/perf-dashboard/generate_perf_graphs.py
+++ b/frontend/perf-dashboard/generate_perf_graphs.py
@@ -28,7 +28,7 @@
 import os
 import re
 import shutil
-import simplejson
+import json
 import sys
 import urllib
 import urllib2
@@ -315,7 +315,7 @@
         }
         if units:
             new_dash_entry['units'] = units
-        json_string = simplejson.dumps([new_dash_entry], indent=2)
+        json_string = json.dumps([new_dash_entry], indent=2)
         params = urllib.urlencode({'data': json_string})
         fp = None
         try:
@@ -411,7 +411,7 @@
               'important': False,
             }]
             with open(os.path.join(output_path, 'graphs.dat'), 'w') as f:
-                f.write(simplejson.dumps(graphs, indent=2))
+                f.write(json.dumps(graphs, indent=2))
 
             # Add symlinks to the plotting code.
             for slink, target in _SYMLINK_LIST:
@@ -468,7 +468,7 @@
                 # Output data point to be displayed on the current (deprecated)
                 # dashboard.
                 with open(summary_file, 'a') as f:
-                    f.write(simplejson.dumps(entry) + '\n')
+                    f.write(json.dumps(entry) + '\n')
 
 
 def process_perf_data_files(file_names, test_name, master_name, completed_ids,
@@ -505,7 +505,7 @@
     for file_name in file_names:
         with open(file_name, 'r') as fp:
             for line in fp.readlines():
-                info = simplejson.loads(line.strip())
+                info = json.loads(line.strip())
                 job_id = info[0]
                 job_name = info[1]
                 platform = info[2]
@@ -559,7 +559,7 @@
     @param output_data_dir: A directory in which to output data files.
 
     """
-    charts = simplejson.loads(open(_CHART_CONFIG_FILE, 'r').read())
+    charts = json.loads(open(_CHART_CONFIG_FILE, 'r').read())
 
     # Identify all the job IDs already processed in the graphs, so that we don't
     # add that data again.
@@ -577,7 +577,7 @@
     rev_num_file = os.path.join(output_data_dir, _REV_NUM_FILE_NAME)
     if os.path.exists(rev_num_file):
         with open(rev_num_file, 'r') as fp:
-            summary_id_to_rev_num = simplejson.loads(fp.read())
+            summary_id_to_rev_num = json.loads(fp.read())
 
     # TODO (dennisjeffrey): If we have to add another "test_name_to_X"
     # dictionary to the list below, we should simplify this code to create a
@@ -635,7 +635,7 @@
     # Store the latest revision numbers for each test/platform/release
     # combination, to be used on the next invocation of this script.
     with open(rev_num_file, 'w') as fp:
-        fp.write(simplejson.dumps(summary_id_to_rev_num, indent=2))
+        fp.write(json.dumps(summary_id_to_rev_num, indent=2))
 
     logging.info('Added info for %d new jobs to the graphs!', newly_added_count)
 
diff --git a/frontend/shared/json_html_formatter.py b/frontend/shared/json_html_formatter.py
index b4b7364..6ef0736 100644
--- a/frontend/shared/json_html_formatter.py
+++ b/frontend/shared/json_html_formatter.py
@@ -29,7 +29,7 @@
 """
 
 import re
-import simplejson
+import json
 
 _HTML_DOCUMENT_TEMPLATE = """
 <!DOCTYPE html>
@@ -134,7 +134,7 @@
         if request.GET.get('alt', None) != 'json-html':
             return response
 
-        json_value = simplejson.loads(response.content)
+        json_value = json.loads(response.content)
         html = JsonHtmlFormatter().json_to_html(json_value)
         response.content = html
         response['Content-type'] = 'text/html'
diff --git a/frontend/shared/resource_lib.py b/frontend/shared/resource_lib.py
index 86cc583..254e92f 100644
--- a/frontend/shared/resource_lib.py
+++ b/frontend/shared/resource_lib.py
@@ -3,7 +3,7 @@
 import django.core.exceptions
 from django.core import urlresolvers
 from django.utils import datastructures
-import simplejson
+import json
 from autotest_lib.frontend.shared import exceptions, query_lib
 from autotest_lib.frontend.afe import model_logic
 
@@ -203,7 +203,7 @@
         query_parameters = self._query_parameters_response()
         if query_parameters:
             content['query_parameters'] = query_parameters
-        encoded_content = simplejson.dumps(content)
+        encoded_content = json.dumps(content)
         return http.HttpResponse(encoded_content,
                                  content_type=_JSON_CONTENT_TYPE)
 
@@ -214,7 +214,7 @@
         raw_data = self._request.raw_post_data
         if content_type == _JSON_CONTENT_TYPE:
             try:
-                raw_dict = simplejson.loads(raw_data)
+                raw_dict = json.loads(raw_data)
             except ValueError, exc:
                 raise exceptions.BadRequest('Error decoding request body: '
                                             '%s\n%r' % (exc, raw_data))
@@ -228,7 +228,7 @@
                 value = values[-1] # take last value if multiple were given
                 try:
                     # attempt to parse numbers, booleans and nulls
-                    raw_dict[key] = simplejson.loads(value)
+                    raw_dict[key] = json.loads(value)
                 except ValueError:
                     # otherwise, leave it as a string
                     raw_dict[key] = value
diff --git a/frontend/shared/resource_test_utils.py b/frontend/shared/resource_test_utils.py
index 8cb742f..f52cd3b 100644
--- a/frontend/shared/resource_test_utils.py
+++ b/frontend/shared/resource_test_utils.py
@@ -1,5 +1,5 @@
 import operator, unittest
-import simplejson
+import json
 from django.test import client
 from autotest_lib.frontend.afe import frontend_test_utils, models as afe_models
 
@@ -53,7 +53,7 @@
         if 'data' in kwargs:
             kwargs.setdefault('content_type', 'application/json')
             if kwargs['content_type'] == 'application/json':
-                kwargs['data'] = simplejson.dumps(kwargs['data'])
+                kwargs['data'] = json.dumps(kwargs['data'])
 
         if uri.startswith('http://'):
             full_uri = uri
@@ -72,7 +72,7 @@
             return response.content
 
         try:
-            return simplejson.loads(response.content)
+            return json.loads(response.content)
         except ValueError:
             self.fail('Invalid reponse body: %s' % response.content)
 
diff --git a/frontend/tko/graphing_utils.py b/frontend/tko/graphing_utils.py
index 44a5e11..17a6ceb 100644
--- a/frontend/tko/graphing_utils.py
+++ b/frontend/tko/graphing_utils.py
@@ -22,7 +22,7 @@
 import StringIO, colorsys, PIL.Image, PIL.ImageChops
 from autotest_lib.frontend.afe import readonly_connection
 from autotest_lib.frontend.afe.model_logic import ValidationError
-from simplejson import encoder
+from json import encoder
 from autotest_lib.client.common_lib import global_config
 from autotest_lib.frontend.tko import models, tko_rpc_utils
 
diff --git a/server/site_autotest.py b/server/site_autotest.py
index 6872eb6..83d5b50 100755
--- a/server/site_autotest.py
+++ b/server/site_autotest.py
@@ -4,6 +4,7 @@
 
 import logging
 import os
+import urllib2
 from autotest_lib.client.common_lib import error, global_config
 from autotest_lib.client.common_lib.cros import dev_server
 from autotest_lib.server import installable_object, autoserv_parser
@@ -43,7 +44,7 @@
                 if hosts and JOB_REPO_URL in hosts[0].attributes:
                     return hosts[0].attributes[JOB_REPO_URL]
                 logging.warning("No %s for %s", JOB_REPO_URL, self.host)
-        except ImportError:
+        except (ImportError, urllib2.URLError):
             logging.warning('Not attempting to look for %s', JOB_REPO_URL)
             pass
         return None
diff --git a/site_utils/admin/scripts/cp_autotest_cli_to_hbs.sh b/site_utils/admin/scripts/cp_autotest_cli_to_hbs.sh
deleted file mode 100755
index 0f69812..0000000
--- a/site_utils/admin/scripts/cp_autotest_cli_to_hbs.sh
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-#
-# Author: truty@google.com (Mike Truty)
-#
-# This script copies needed files to allow Autotest CLI access from nfs.
-
-declare -r BASE_DIR="/usr/local/autotest"
-
-declare -r TARGET_DIR="/home/build/static/projects-rw/chromeos/autotest"
-
-function checktarget() {
-  [[ -d "${TARGET_DIR}" ]] || mkdir -p "${TARGET_DIR}"
-}
-
-function copyfiles() {
-  local norecurse_copy_dirs="\
-    . \
-    client \
-    site-packages/simplejson"
-  echo "Copying directories..."
-  for d in ${norecurse_copy_dirs}; do
-    echo Copying "$d"...
-    [[ -d ${TARGET_DIR}/$d ]] || mkdir -p ${TARGET_DIR}/$d
-    cp -f ${BASE_DIR}/$d/* ${TARGET_DIR}/$d
-    # Ignore errors - warnings abound.
-  done
-
-  local recurse_copy_dirs="\
-    cli \
-    client/common_lib \
-    database \
-    frontend"
-  for d in ${recurse_copy_dirs}; do
-    echo Copying "$d"...
-    [[ -d ${TARGET_DIR}/$d ]] || mkdir -p ${TARGET_DIR}/$d
-    cp -rf ${BASE_DIR}/$d/* ${TARGET_DIR}/$d
-    if [[ "$?" -ne 0 ]]; then
-      echo Unable to copy ${BASE_DIR}/$d to ${TARGET_DIR}/$d
-      exit 1
-    fi
-  done
-  echo "Done."
-}
-
-function main() {
-  checktarget
-  copyfiles
-  echo "The previous Autotest directory has a btuils folder"
-  echo "that needs to be copied here. These utilities are"
-  echo "used to archive (btcp) results files and serve"
-  echo "them (btfsserver). Please create ${TARGET_DIR}/btuils"
-  echo "and copy the contents of the previous btuils folder there."
-}
-
-main
diff --git a/site_utils/experimental/croschart/update_crosreport_cache.py b/site_utils/experimental/croschart/update_crosreport_cache.py
index 0b959f2..2b35f73 100755
--- a/site_utils/experimental/croschart/update_crosreport_cache.py
+++ b/site_utils/experimental/croschart/update_crosreport_cache.py
@@ -10,7 +10,7 @@
 import os
 import optparse
 import pprint
-import simplejson
+import json
 import sys
 
 
@@ -49,7 +49,7 @@
 def ReadInputFile(input_file):
   """Read the input file into a string list."""
   f = open(input_file, 'r')
-  chart_list = simplejson.load(f)
+  chart_list = json.load(f)
   f.close()
   return chart_list
 
diff --git a/site_utils/validate_json_files.sh b/site_utils/validate_json_files.sh
index c161a56..a044bb6 100755
--- a/site_utils/validate_json_files.sh
+++ b/site_utils/validate_json_files.sh
@@ -5,9 +5,9 @@
 # found in the LICENSE file.
 
 set -e
-echo "This assumes you have python-simplejson installed"
+echo "This assumes you have python 2.4 or later installed"
 for json in *.json; do
    echo "Validating $json"
-   python -c "import simplejson; simplejson.load(open('$json'))" || \
+   python -c "import json; json.load(open('$json'))" || \
       printf "\n\n$json is broken!!!!\n\n"
 done
diff --git a/utils/external_packages.py b/utils/external_packages.py
index 71647c3..a6e4347 100644
--- a/utils/external_packages.py
+++ b/utils/external_packages.py
@@ -707,19 +707,6 @@
                         ExternalPackage._build_and_install_current_dir_setup_py)
 
 
-class SimplejsonPackage(ExternalPackage):
-    """simplejson package"""
-    version = '2.0.9'
-    local_filename = 'simplejson-%s.tar.gz' % version
-    urls = ('http://pypi.python.org/packages/source/s/simplejson/' +
-            local_filename,)
-    hex_sum = 'b5b26059adbe677b06c299bed30557fcb0c7df8c'
-
-    _build_and_install = ExternalPackage._build_and_install_from_package
-    _build_and_install_current_dir = (
-                        ExternalPackage._build_and_install_current_dir_setup_py)
-
-
 class Httplib2Package(ExternalPackage):
     """httplib2 package"""
     version = '0.6.0'