Commit e5354e76 authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/t/{tcpu,tzodb}.py: Move hashing utilities & hashRegistry to -> zodbtools

Moved here:

	nexedi/zodbtools@e973d519
parent fe751a15
...@@ -25,37 +25,11 @@ from __future__ import print_function ...@@ -25,37 +25,11 @@ from __future__ import print_function
import sys import sys
import hashlib import hashlib
import zlib import zlib
from zlib import crc32, adler32
from os.path import dirname from os.path import dirname
from zodbtools.util import Adler32Hasher, CRC32Hasher
from golang import testing from golang import testing
# adler32 in hashlib interface
class Adler32Hasher:
name = "adler32"
def __init__(self):
self.h = adler32('')
def update(self, data):
self.h = adler32(data, self.h)
def hexdigest(self):
return '%08x' % (self.h & 0xffffffff)
# crc32 in hashlib interface
class CRC32Hasher:
name = "crc32"
def __init__(self):
self.h = crc32('')
def update(self, data):
self.h = crc32(data, self.h)
def hexdigest(self):
return '%08x' % (self.h & 0xffffffff)
# fmtsize formats size in human readable form # fmtsize formats size in human readable form
_unitv = "BKMGT" # (2^10)^i represents by corresponding char suffix _unitv = "BKMGT" # (2^10)^i represents by corresponding char suffix
def fmtsize(size): def fmtsize(size):
......
...@@ -22,37 +22,15 @@ ...@@ -22,37 +22,15 @@
from __future__ import print_function from __future__ import print_function
import zodbtools.util from zodbtools.util import storageFromURL, hashRegistry
from ZODB.POSException import POSKeyError from ZODB.POSException import POSKeyError
from ZODB.utils import p64, u64 from ZODB.utils import p64, u64
import hashlib
from tcpu import Adler32Hasher, CRC32Hasher
import sys import sys
import logging import logging
from time import time from time import time
from getopt import getopt, GetoptError from getopt import getopt, GetoptError
# hasher that discards data
class NullHasher:
name = "null"
def update(self, data):
pass
def hexdigest(self):
return "00"
# {} name -> hasher
hashRegistry = {
"null": NullHasher,
"adler32": Adler32Hasher,
"crc32": CRC32Hasher,
"sha1": hashlib.sha1,
"sha256": hashlib.sha256,
"sha512": hashlib.sha512,
}
def usage(w): def usage(w):
print(\ print(\
"""Usage: tzodb zhash [options] url """Usage: tzodb zhash [options] url
...@@ -115,7 +93,7 @@ def zhash(): ...@@ -115,7 +93,7 @@ def zhash():
l = logging.getLogger() l = logging.getLogger()
l.addHandler(logging.StreamHandler()) l.addHandler(logging.StreamHandler())
stor = zodbtools.util.storageFromURL(url, read_only=True) stor = storageFromURL(url, read_only=True)
last_tid = stor.lastTransaction() last_tid = stor.lastTransaction()
before = p64(u64(last_tid) + 1) before = p64(u64(last_tid) + 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment