diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2016-10-06 02:06:56 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2016-10-11 01:55:33 -0700 |
commit | f0edfa6edf49d7e869f68a949017c5f7d8160d1d (patch) | |
tree | e71672ba45512db98e226146b51af6ac088be4d3 /lib | |
parent | 222f551c37fc5411ddce5dccb87dc477b0a02ae4 (diff) | |
download | spack-f0edfa6edf49d7e869f68a949017c5f7d8160d1d.tar.gz spack-f0edfa6edf49d7e869f68a949017c5f7d8160d1d.tar.bz2 spack-f0edfa6edf49d7e869f68a949017c5f7d8160d1d.tar.xz spack-f0edfa6edf49d7e869f68a949017c5f7d8160d1d.zip |
Roll my my own bit_length function for Python 2.6 compatibility.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/package.py | 4 | ||||
-rw-r--r-- | lib/spack/spack/stage.py | 4 | ||||
-rw-r--r-- | lib/spack/spack/util/crypto.py | 7 |
3 files changed, 11 insertions, 4 deletions
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) |