diff --git a/src/energenie/Registry.py b/src/energenie/Registry.py index 6430a30..212afe7 100644 --- a/src/energenie/Registry.py +++ b/src/energenie/Registry.py @@ -71,6 +71,7 @@ self.filename = filename self.store = {} + @unimplemented def load(self, factory): """Load the whole file into an in-memory cache""" # The 'factory' is a place to go to turn device type names into actual class instances @@ -93,12 +94,14 @@ # process command,key,values, if it command is not empty # close file + @unimplemented def process(self, command, key, values): """Process the temporary object""" pass #TODO # getattr method associated with the command name, error if no method # pass the key,values to that method to let it be processed + @unimplemented def ADD(self, key, values): """Add a new item to the kvs""" # The ADD command process the next type= parameter as the class name in context @@ -111,6 +114,7 @@ # write k=v # close file + @unimplemented def IGN(self, key, values=None): """Ignore the whole record""" # The IGN command is the same length as ADD, allowing a seek/write to change any @@ -118,6 +122,7 @@ # so that the record is deleted. pass # There is nothing to do with this command + @unimplemented def DEL(self, key, values=None): """Delete the key from the store""" # The DEL command deletes the rec from the store. @@ -126,23 +131,29 @@ pass #TODO # find key in object store, delete it - def __getattr__(self, key): + @untested + def __getitem__(self, key): return self.store[key] - def __setattr__(self, key, value): + @untested + def __setitem__(self, key, value): self.store[key] = value self.append(key, value) + @untested def __delitem__(self, key): del self.store[key] self.remove(key) + @untested def keys(self): return self.store.keys() + @untested def size(self): return len(self.store) + @unimplemented def append(self, key, values): """Append a new record to the persistent file""" pass #TODO @@ -152,6 +163,7 @@ # write k=v # close file + @unimplemented def remove(self, key): """Remove reference to this key in the file, and remove from in memory store""" pass #TODO @@ -163,6 +175,7 @@ # keep going in case of duplicates # close file + @unimplemented def rewrite(self): """Rewrite the whole in memory cache over the top of the external file""" # useful if you have updated the in memory copy only and want to completely regenerate @@ -186,10 +199,9 @@ DEFAULT_FILENAME = "registry.kvs" - def __init__(self): - pass # nothing to do - # There is intentionally no self.store until load_from is called. - # This ensures you can't use the registry until you create a file. + def __init__(self, filename=None): + if filename != None: + self.store = KVS(filename) @untested def load_from(self, filename=None): @@ -206,10 +218,10 @@ #TODO: need to know what file it was previously loaded from #TODO: What about existing receive routes?? - @unimplemented + @untested def rewrite(self): """Rewrite the persisted version from the in memory version""" - pass #TODO: self.store.rewrite() + self.store.rewrite() def load_into(self, context): """auto-create variables in the provided context, for all persisted registry entries""" @@ -257,7 +269,8 @@ return dl -registry = DeviceRegistry("registry.txt") +registry = DeviceRegistry() +#TODO: registry.reload?? # This will create all class instance variables in the module that imports the registry. diff --git a/src/energenie/Registry_test.py b/src/energenie/Registry_test.py index a666402..c2332ce 100644 --- a/src/energenie/Registry_test.py +++ b/src/energenie/Registry_test.py @@ -16,19 +16,36 @@ radio.DEBUG=True class TestRegistry(unittest.TestCase): - pass - # add some devices to the registry - # persist it to a file - # see what the file looks like + @test_1 + def test_create(self): + registry = DeviceRegistry("registry.kvs") - # load from a persisted registry - # list the registry in memory - # see that each item is instantiated and has a route + # add some devices to the registry, it should auto update the file + registry.add(Devices.MIHO005(device_id=0x68b), "tv") + registry.add(Devices.ENER002(device_id=(0xC8C8C, 1)), "fan") - # load from a persisted registry - # load_into some context - # make sure all the loaded context variables point to the right thing + # see what the file looks like + with open(registry.DEFAULT_FILENAME) as f: + print(f.readlines()) + + @test_0 + def test_load(self): + pass #TODO + # load from a persisted registry + # list the registry in memory + # see that each item is instantiated and has a route + + @test_0 + def test_load_into(self): + pass #TODO + # load from a persisted registry + # load_into some context + # make sure all the loaded context variables point to the right thing + + + + #TODO: This is not realy a registry tester, it's a device class/router tester?? @@ -179,7 +196,7 @@ registry.list() fsk_router.list() - @test_1 + @test_0 def test_discovery_askjoin(self): def no(a,b): return False def yes(a,b): return True