2 Flat ASCII Database to implement VERY simple config files.
6 from m_lib.flad import flad, fladm
9 from .flad import checking_error
10 class error(checking_error):
15 class Flad_Conf(dict):
17 FLAD config is just FLAD Database with exactly ONE record.
18 Flad_Conf objects are just UserDicts.
20 def __init__(self, must_keys = None, other_keys = None):
23 self.must_keys = must_keys
24 self.other_keys = other_keys
29 db = fladm.Flad_WithMustKeys(check_record, self.must_keys, self.other_keys)
36 def load_file(self, f):
41 raise error("incorrect number of records in config file `%s'; expected 1, got %d" % (str(f), len(db)))
46 def load_from_file(self, f):
51 raise error("incorrect number of records in config file `%s'; expected 1, got %d" % (str(f), len(db)))
56 def store_to_file(self, f):
62 def check_record(data, record): # Only allow append 1 record
66 def load_file(f, must_keys = None, other_keys = None):
68 Create a database object and load it from file
71 db = Flad_Conf(must_keys, other_keys)
77 def load_from_file(f, must_keys = None, other_keys = None):
79 Create a database object and load it from file
82 db = Flad_Conf(must_keys, other_keys)