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

47 lines
826 B
Python

import pickle
import os
from ._internal import defaultarguments, gopen, doreahconfig
_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()
@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
# now check local configuration file
_config.update(doreahconfig("persistence"))