2f3e49d98d44e7b1d76a00898841c26096a99678
[osm/N2VC.git] / modules / libjuju / juju / client / client.py
1 '''Replace auto-generated classes with our own, where necessary.
2 '''
3
4 from . import _client, _definitions, overrides
5
6
7 for o in overrides.__all__:
8 if "Facade" not in o:
9 # Override stuff in _definitions, which is all imported
10 # into _client. We Monkey patch both the original class and
11 # the ref in _client (import shenanigans are fun!)
12 setattr(_definitions, o, getattr(overrides, o))
13 setattr(_client, o, getattr(overrides, o))
14 # We shouldn't be overriding Facades!
15 else:
16 raise ValueError(
17 "Cannot override a versioned Facade class -- you must patch "
18 "it instead.")
19
20 for o in overrides.__patches__:
21 # Patch a versioned Facade.
22 for client_version in _client.CLIENTS.values():
23 try:
24 c_type = getattr(client_version, o)
25 except AttributeError:
26 # Not all the _client<version> modules may have the
27 # facade. That's okay -- we just skip over them.
28 continue
29 o_type = getattr(overrides, o)
30 for a in dir(o_type):
31 if not a.startswith('_'):
32 setattr(c_type, a, getattr(o_type, a))
33
34 from ._client import * # noqa