From f0edfa6edf49d7e869f68a949017c5f7d8160d1d Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 6 Oct 2016 02:06:56 -0700 Subject: Roll my my own bit_length function for Python 2.6 compatibility. --- lib/spack/spack/package.py | 4 ++-- lib/spack/spack/stage.py | 4 ++-- lib/spack/spack/util/crypto.py | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 42e18b2a1e..768605294f 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -40,7 +40,6 @@ import textwrap import time import string import contextlib -from urlparse import urlparse from StringIO import StringIO import llnl.util.lock @@ -63,6 +62,7 @@ import spack.url import spack.util.web from spack.stage import Stage, ResourceStage, StageComposite +from spack.util.crypto import bit_length from spack.util.environment import dump_environment from spack.util.executable import ProcessError, which from spack.version import * @@ -719,7 +719,7 @@ class Package(object): if prefix not in Package.prefix_locks: Package.prefix_locks[prefix] = llnl.util.lock.Lock( spack.installed_db.prefix_lock_path, - self.spec.dag_hash_bit_prefix(sys.maxsize.bit_length()), 1) + self.spec.dag_hash_bit_prefix(bit_length(sys.maxsize)), 1) self._prefix_lock = Package.prefix_locks[prefix] diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 230defc67e..c0dfbba987 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -41,7 +41,7 @@ import spack.config import spack.fetch_strategy as fs import spack.error from spack.version import * -from spack.util.crypto import prefix_bits +from spack.util.crypto import prefix_bits, bit_length STAGE_PREFIX = 'spack-stage-' @@ -161,7 +161,7 @@ class Stage(object): if lock: if self.name not in Stage.stage_locks: sha1 = hashlib.sha1(self.name).digest() - lock_id = prefix_bits(sha1, sys.maxsize.bit_length()) + lock_id = prefix_bits(sha1, bit_length(sys.maxsize)) stage_lock_path = join_path(spack.stage_path, '.lock') Stage.stage_locks[self.name] = llnl.util.lock.Lock( diff --git a/lib/spack/spack/util/crypto.py b/lib/spack/spack/util/crypto.py index 6e17b74774..d074716022 100644 --- a/lib/spack/spack/util/crypto.py +++ b/lib/spack/spack/util/crypto.py @@ -114,3 +114,10 @@ def prefix_bits(byte_array, bits): result >>= (n - bits) return result + + +def bit_length(num): + """Number of bits required to represent an integer in binary.""" + s = bin(num) + s = s.lstrip('-0b') + return len(s) -- cgit v1.2.3-60-g2f50