Rename transactions to hook, since that's what they are.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
brian m. carlson 2014-12-15 02:46:48 +00:00
parent 08ded8196b
commit 1f031fad16
No known key found for this signature in database
GPG key ID: BF535D811F52F68B
2 changed files with 15 additions and 15 deletions

View file

@ -61,7 +61,7 @@ class Record:
return self._version
class TransactionStore:
class Hook:
def prepare_open(self, filename, mode):
pass
@ -87,7 +87,7 @@ class TransactionStore:
pass
class StackingTransactionStore(TransactionStore):
class StackingHook(Hook):
def __init__(self, stores):
self._stores = stores
@ -124,7 +124,7 @@ class StackingTransactionStore(TransactionStore):
store.commit_store(rec)
class GitTransactionStore(TransactionStore):
class GitHook(Hook):
class DirectoryChanger:
@ -198,7 +198,7 @@ class GitTransactionStore(TransactionStore):
self._call_git("commit", "-m", message)
class HashTransactionStore(TransactionStore):
class HashHook(Hook):
def __init__(self, hashname="sha256", options=None):
self._filename = None
self._mode = None
@ -230,7 +230,7 @@ class HashTransactionStore(TransactionStore):
return choice1
if choice2 is not None:
return choice2
return "sha512" if HashTransactionStore._bitness() == 64 else "sha256"
return "sha512" if HashHook._bitness() == 64 else "sha256"
def prepare_open(self, filename, mode):
self._filename = filename
@ -578,11 +578,11 @@ class FileStorage:
@staticmethod
def _get_transaction_types():
return {
"git": GitTransactionStore,
"sha256": lambda *a, **k: HashTransactionStore("sha256", *a, **k),
"sha384": lambda *a, **k: HashTransactionStore("sha384", *a, **k),
"sha512": lambda *a, **k: HashTransactionStore("sha512", *a, **k),
"hash": lambda *a, **k: HashTransactionStore(None, *a, **k),
"git": GitHook,
"sha256": lambda *a, **k: HashHook("sha256", *a, **k),
"sha384": lambda *a, **k: HashHook("sha384", *a, **k),
"sha512": lambda *a, **k: HashHook("sha512", *a, **k),
"hash": lambda *a, **k: HashHook(None, *a, **k),
}
@staticmethod
@ -593,13 +593,13 @@ class FileStorage:
def _make_transaction_store(items, options):
txntypes = FileStorage._get_transaction_types()
if items is None or items == "":
return TransactionStore()
return Hook()
elif isinstance(items, str):
return txntypes[items](options)
else:
stores = [FileStorage._make_transaction_store(i, options)
for i in items]
return StackingTransactionStore(stores)
return StackingHook(stores)
def store(self, records):
"""Store the records."""

View file

@ -1,6 +1,6 @@
#!/usr/bin/python3
from newfol.filemanip import Record, FileStorage, HashTransactionStore
from newfol.filemanip import Record, FileStorage, HashHook
import hashlib
import newfol.exception
import tempfile
@ -140,7 +140,7 @@ class SHA256TransactionTest(unittest.TestCase):
v = self.generate_len_and_hash(hashlib.sha256, k)
with open(temp, "w") as wfp:
wfp.write(k)
self.assertEqual(HashTransactionStore._hash_file("sha256", temp),
self.assertEqual(HashHook._hash_file("sha256", temp),
"sha256:" + v)
tempdir.cleanup()
@ -210,7 +210,7 @@ class SHA256TransactionTest(unittest.TestCase):
x.fs.store([Record(["", ""])])
with open(x.tempfile + ".checksum", "r") as fp:
data = fp.read()
bitness = HashTransactionStore._bitness()
bitness = HashHook._bitness()
self.assertIn(bitness, [32, 64])
self.assertTrue(data.startswith("sha512" if bitness == 64 else
"sha256"))