From 7ffe8fbafc663f749660d9356521bbab3c2b5784 Mon Sep 17 00:00:00 2001 From: Carlos Valiente Date: Tue, 5 May 2009 15:43:04 +0100 Subject: [PATCH] Avoid DeprecationWarning on Python >= 2.6 Python 2.6 complains about module 'sha' being deprecated. It makes execution of Ganeti commands a bit annoying, and when you run 'ganeti-watcher' in cron jobs, you get a mail message after every execution. Tests pass under under Python 2.6 and Python 2.4. Signed-off-by: Iustin Pop Reviewed-by: Iustin Pop --- lib/utils.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/utils.py b/lib/utils.py index 370ba62..786cb0e 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -29,7 +29,6 @@ the command line scripts. import sys import os -import sha import time import subprocess import re @@ -47,6 +46,12 @@ import signal from cStringIO import StringIO +try: + from hashlib import sha1 +except ImportError: + import sha + sha1 = sha.new + from ganeti import errors from ganeti import constants @@ -337,7 +342,7 @@ def _FingerprintFile(filename): f = open(filename) - fp = sha.sha() + fp = sha1() while True: data = f.read(4096) if not data: @@ -1186,7 +1191,7 @@ def GenerateSecret(): @return: a sha1 hexdigest of a block of 64 random bytes """ - return sha.new(os.urandom(64)).hexdigest() + return sha1(os.urandom(64)).hexdigest() def EnsureDirs(dirs): -- 1.7.10.4