X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=juju%2Fclient%2Fclient.py;h=89b52487664040baabcf5ae6914e13886682660f;hb=4886fb1aecea27593aa4d5ec8829975c38701c71;hp=f4eef0efaf8a591c03a80887b1a7c6f199caa563;hpb=6637bf37c99d012ccd51823501dd7325ba3d6840;p=osm%2FN2VC.git diff --git a/juju/client/client.py b/juju/client/client.py index f4eef0e..89b5248 100644 --- a/juju/client/client.py +++ b/juju/client/client.py @@ -1,19 +1,34 @@ '''Replace auto-generated classes with our own, where necessary. - ''' -from . import _client -from . import overrides +from . import _client, _definitions, overrides for o in overrides.__all__: - setattr(_client, o, getattr(overrides, o)) + if not "Facade" in o: + # Override stuff in _definitions, which is all imported + # into _client. We Monkey patch both the original class and + # the ref in _client (import shenanigans are fun!) + setattr(_definitions, o, getattr(overrides, o)) + setattr(_client, o, getattr(overrides, o)) + # We shouldn't be overriding Facades! + else: + raise ValueError( + "Cannot override a versioned Facade class -- you must patch " + "it instead.") for o in overrides.__patches__: - c_type = getattr(_client, o) - o_type = getattr(overrides, o) - for a in dir(o_type): - if not a.startswith('_'): - setattr(c_type, a, getattr(o_type, a)) + # Patch a versioned Facade. + for client_version in _client.CLIENTS.values(): + try: + c_type = getattr(client_version, o) + except AttributeError: + # Not all the _client modules may have the + # facade. That's okay -- we just skip over them. + continue + o_type = getattr(overrides, o) + for a in dir(o_type): + if not a.startswith('_'): + setattr(c_type, a, getattr(o_type, a)) from ._client import * # noqa