cic-cli/cic/base.py

55 lines
996 B
Python
Raw Normal View History

2021-10-09 19:56:29 +02:00
# standard imports
import os
2021-10-10 21:30:18 +02:00
import hashlib
2021-10-09 19:56:29 +02:00
mod_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = os.path.join(mod_dir, '..')
data_dir = os.path.join(mod_dir, 'data')
schema_dir = os.path.join(mod_dir, 'schema')
class Data:
__default_version = 0
def __init__(self):
self.dirty = False
self.inited = False
self.__version = self.__default_version
2021-10-10 21:30:18 +02:00
self.__hasher = self.__basehasher
def __basehasher(self, v):
h = hashlib.sha256()
h.update(v)
return h.digest()
def hash(self, v):
return self.__hasher(v)
2021-10-09 19:56:29 +02:00
def load(self):
if self.dirty:
raise RuntimeError('Object contains uncommitted changes')
def start(self):
if self.inited:
raise RuntimeError('Object already initialized')
2021-10-10 14:49:22 +02:00
def verify(self):
return True
2021-10-09 19:56:29 +02:00
def version(self):
return self.__version
2021-10-09 20:37:54 +02:00
def set_version(self, version):
self.__version = version