From patchwork Fri Jan 29 05:36:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 75655 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o0T5aTH6025307 for ; Fri, 29 Jan 2010 05:36:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751172Ab0A2Fg2 (ORCPT ); Fri, 29 Jan 2010 00:36:28 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751144Ab0A2Fg2 (ORCPT ); Fri, 29 Jan 2010 00:36:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:30342 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751143Ab0A2Fg1 (ORCPT ); Fri, 29 Jan 2010 00:36:27 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0T5aQdN026284 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 29 Jan 2010 00:36:26 -0500 Received: from localhost.localdomain (vpn-11-140.rdu.redhat.com [10.11.11.140]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0T5aOKi010390; Fri, 29 Jan 2010 00:36:25 -0500 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH] Fixing sha/md5 deprecation messages from autotest Date: Fri, 29 Jan 2010 03:36:22 -0200 Message-Id: <1264743382-11198-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 29 Jan 2010 05:36:30 +0000 (UTC) diff --git a/tko/models.py b/tko/models.py index bc70074..2dc6724 100644 --- a/tko/models.py +++ b/tko/models.py @@ -1,4 +1,8 @@ -import os, md5 +import os +try: + import hashlib +except ImportError: + import md5 from autotest_lib.client.common_lib import utils from autotest_lib.tko import utils as tko_utils @@ -63,7 +67,11 @@ class kernel(object): @staticmethod def compute_hash(base, hashes): key_string = ','.join([base] + hashes) - return md5.new(key_string).hexdigest() + try: + hash = hashlib.md5(key_string).hexdigest() + except NameError: + hash = md5.new(key_string).hexdigest() + return hash class test(object): diff --git a/tko/parsers/version_1_unittest.py b/tko/parsers/version_1_unittest.py index 5110fe8..a6e87e4 100755 --- a/tko/parsers/version_1_unittest.py +++ b/tko/parsers/version_1_unittest.py @@ -1,6 +1,10 @@ #!/usr/bin/python -import unittest, datetime, time, md5 +import unittest, datetime, time +try: + import hashlib +except ImportError: + import md5 import common from autotest_lib.tko.parsers import version_1 @@ -163,7 +167,10 @@ class test_status_line(unittest.TestCase): "patch0": "first_patch 0 0", "patch1": "another_patch 0 0"}) kern = line.get_kernel() - kernel_hash = md5.new("2.6.24-rc40,0,0").hexdigest() + try: + kernel_hash = hashlib.md5("2.6.24-rc40,0,0").hexdigest() + except NameError: + kernel_hash = md5.new("2.6.24-rc40,0,0").hexdigest() self.assertEquals(kern.base, "2.6.24-rc40") self.assertEquals(kern.patches[0].spec, "first_patch") self.assertEquals(kern.patches[1].spec, "another_patch") @@ -178,7 +185,10 @@ class test_status_line(unittest.TestCase): "patch0": "first_patch 0 0", "patch2": "another_patch 0 0"}) kern = line.get_kernel() - kernel_hash = md5.new("2.6.24-rc40,0").hexdigest() + try: + kernel_hash = hashlib.md5("2.6.24-rc40,0").hexdigest() + except: + kernel_hash = md5.new("2.6.24-rc40,0").hexdigest() self.assertEquals(kern.base, "2.6.24-rc40") self.assertEquals(kern.patches[0].spec, "first_patch") self.assertEquals(len(kern.patches), 1) diff --git a/utils/build_externals.py b/utils/build_externals.py index d58975e..8993249 100755 --- a/utils/build_externals.py +++ b/utils/build_externals.py @@ -12,7 +12,11 @@ Usage? Just run it. utils/build_externals.py """ -import compileall, logging, os, sha, shutil, sys, tempfile, time, urllib2 +import compileall, logging, os, shutil, sys, tempfile, time, urllib2 +try: + import hashlib +except ImportError: + import sha import subprocess, re import common from autotest_lib.client.common_lib import logging_config, logging_manager @@ -152,7 +156,10 @@ def _checksum_file(full_path): """@returns The hex checksum of a file given its pathname.""" inputfile = open(full_path, 'rb') try: - hex_sum = sha.sha(inputfile.read()).hexdigest() + try: + hex_sum = hashlib.sha1(inputfile.read()).hexdigest() + except NameError: + hex_sum = sha.sha(inputfile.read()).hexdigest() finally: inputfile.close() return hex_sum