hashlib is only available in python 2.5 or higher, but the 'sha' module
produces a DeprecationWarning in python 2.6 or higher. We want to support
python 2.4 and above without any stupid warnings, so let's try using
hashlib. If it fails, switch to the old sha module.
-import sys, os, glob, subprocess, time, sha
+import sys, os, glob, subprocess, time
from bup import options, git
from bup.helpers import *
from bup import options, git
from bup.helpers import *
wantsum = f.read(20)
assert(len(wantsum) == 20)
f.seek(0)
wantsum = f.read(20)
assert(len(wantsum) == 20)
f.seek(0)
for b in chunkyreader(f, os.fstat(f.fileno()).st_size - 20):
sum.update(b)
if sum.digest() != wantsum:
for b in chunkyreader(f, os.fstat(f.fileno()).st_size - 20):
sum.update(b)
if sum.digest() != wantsum:
-import sys, math, struct, glob, sha
+import sys, math, struct, glob
from bup import options, git
from bup.helpers import *
from bup import options, git
from bup.helpers import *
def do_midx(outdir, outfilename, infilenames):
if not outfilename:
assert(outdir)
def do_midx(outdir, outfilename, infilenames):
if not outfilename:
assert(outdir)
- sum = sha.sha('\0'.join(infilenames)).hexdigest()
+ sum = Sha1('\0'.join(infilenames)).hexdigest()
outfilename = '%s/midx-%s.midx' % (outdir, sum)
inp = []
outfilename = '%s/midx-%s.midx' % (outdir, sum)
inp = []
-import os, errno, zlib, time, sha, subprocess, struct, stat, re, tempfile
+import os, errno, zlib, time, subprocess, struct, stat, re, tempfile
import heapq
from bup.helpers import *
import heapq
from bup.helpers import *
def calc_hash(type, content):
header = '%s %d\0' % (type, len(content))
def calc_hash(type, content):
header = '%s %d\0' % (type, len(content))
sum.update(content)
return sum.digest()
sum.update(content)
return sum.digest()
# calculate the pack sha1sum
f.seek(0)
# calculate the pack sha1sum
f.seek(0)
while 1:
b = f.read(65536)
sum.update(b)
while 1:
b = f.read(65536)
sum.update(b)
else:
return oldhook(exctype, value, traceback)
sys.excepthook = newhook
else:
return oldhook(exctype, value, traceback)
sys.excepthook = newhook
+
+
+# hashlib is only available in python 2.5 or higher, but the 'sha' module
+# produces a DeprecationWarning in python 2.6 or higher. We want to support
+# python 2.4 and above without any stupid warnings, so let's try using hashlib
+# first, and downgrade if it fails.
+try:
+ import hashlib
+except ImportError:
+ import sha
+ Sha1 = sha.sha
+else:
+ Sha1 = hashlib.sha1