1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00
maloja/doreah/persistence.py

47 lines
826 B
Python
Raw Normal View History

2019-03-29 21:44:42 +03:00
import pickle
import os
2019-03-31 13:18:49 +03:00
from ._internal import defaultarguments, gopen, doreahconfig
2019-03-29 21:44:42 +03:00
_config = {}
# set configuration
# folder folder to store log files
def config(folder="storage"):
global _config
_config["folder"] = folder
# initial config on import, set everything to default
config()
2019-03-31 13:18:49 +03:00
2019-03-29 21:44:42 +03:00
@defaultarguments(_config,folder="folder")
def save(data,name,folder):
filename = os.path.join(folder,name + ".gilly")
fl = gopen(filename,"wb")
stream = pickle.dumps(data)
fl.write(stream)
fl.close()
@defaultarguments(_config,folder="folder")
def load(name,folder):
filename = os.path.join(folder,name + ".gilly")
try:
fl = gopen(filename,"rb")
ob = pickle.loads(fl.read())
except: ob = None
finally:
fl.close()
return ob
2019-03-31 13:18:49 +03:00
# now check local configuration file
_config.update(doreahconfig("persistence"))