From 232c7711055ae3df83abe0d96fd653d075365bfc Mon Sep 17 00:00:00 2001 From: Grahame Bowland Date: Wed, 28 Mar 2012 17:25:54 +0800 Subject: [PATCH] python scripts run with Python 2.4 (for RHEL5) --- src/etc/get-snapshot.py | 2 +- src/etc/snapshot.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/etc/get-snapshot.py b/src/etc/get-snapshot.py index 643cd0fcdd62..964c06ffcae7 100755 --- a/src/etc/get-snapshot.py +++ b/src/etc/get-snapshot.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import os, tarfile, hashlib, re, shutil, sys +import os, tarfile, re, shutil, sys from snapshot import * def unpack_snapshot(triple, dl_path): diff --git a/src/etc/snapshot.py b/src/etc/snapshot.py index e29f2863e9ce..191e31138d15 100644 --- a/src/etc/snapshot.py +++ b/src/etc/snapshot.py @@ -1,4 +1,11 @@ -import re, os, sys, glob, hashlib, tarfile, shutil, subprocess, tempfile +import re, os, sys, glob, tarfile, shutil, subprocess, tempfile + +try: + import hashlib + sha_func = hashlib.sha1 +except ImportError: + import sha + sha_func = sha.new def scrub(b): if sys.version_info >= (3,) and type(b) == bytes: @@ -119,9 +126,8 @@ def local_rev_committer_date(): def get_url_to_file(u,f): # no security issue, just to stop partial download leaving a stale file tmpf = f + '.tmp' - try: - subprocess.check_call(["curl", "-o", tmpf, u]) - except subprocess.CalledProcessError: + returncode = subprocess.call(["curl", "-o", tmpf, u]) + if returncode != 0: os.unlink(tmpf) raise os.rename(tmpf, f) @@ -133,7 +139,7 @@ def snap_filename_hash_part(snap): return match.group(1) def hash_file(x): - h = hashlib.sha1() + h = sha_func() h.update(open(x, "rb").read()) return scrub(h.hexdigest())