Closed nir0s closed 8 years ago
I can see 3 ways of getting the backend class:
storage = {"tinydb": TinyDBStorage}
) inspect
method, but also eg. having the backends inherit from a base class and look for its children)myplugin.module.MyBackend
; maybe specialcase so that it can just be TinyDBStorage
, not ghost.TinyDBStorage
) (then use something like eg. https://github.com/cloudify-cosmo/cloudify-manager/blob/master/rest-service/manager_rest/utils.py#L85-L111 )So I think the middle one is much more magical than the first one (which is trivial), but it isn't much more powerful... you need to of course remember to maintain the dict, but in this case the backends only live inside ghost anyway, and there probably won't be very many of them. The third one is much more powerful of course, but not sure if it's very useful at this point.
Anyway, please note that backends might need more arguments than just a stash path (eg. the proposed consul backend, or really anything that you use over a network with optional tls), so I think there should be a way of passing additional parameters.
Sounds reasonable. I guess we should start from the dict and see where it takes us. The reason for my suggestion was that assuming everything is exposed under ghost.py for now, it should be relatively easy. Of course, at some point, offering additional backends will complicate the package after which we need a more robust method. 3 sounds good for that.
Now allowing to using SQLAlchemy as well while the default still uses TinyDB. I've implemented this using the first method @tehasdf suggested and we'll see how this goes when we add more backends.
Currently, only the TinyDB storage backend is supported in the CLI.
To solve this, we can get all storage class objects and their names. The names could be used by click via
type=click.Choice(storage_names)
after which if the name the user provides aligns with any of the available implementations,globals()[class.__name__](stash_path)
, it will be chosen.clsmembers = inspect.getmembers(sys.modules[__name__], inspect.isclass)
can return the desires class objects.