X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=modules%2Flibjuju%2Fjuju%2Fclient%2Ffacade.py;fp=modules%2Flibjuju%2Fjuju%2Fclient%2Ffacade.py;h=c015c5f03c8931898246e323ab0795807bc7c1b1;hp=c959e01649964a9a5eb955e2fc0829ebabfcc90f;hb=1a15d1c84fc826fa7996c1c9d221a324edd33432;hpb=fd577a36aaf408c845f3bb8b3f28ecbbf3332107 diff --git a/modules/libjuju/juju/client/facade.py b/modules/libjuju/juju/client/facade.py index c959e01..c015c5f 100644 --- a/modules/libjuju/juju/client/facade.py +++ b/modules/libjuju/juju/client/facade.py @@ -44,19 +44,19 @@ HEADER = """\ # Classes and helper functions that we'll write to _client.py LOOKUP_FACADE = ''' def lookup_facade(name, version): - """ - Given a facade name and version, attempt to pull that facade out - of the correct client.py file. + """ + Given a facade name and version, attempt to pull that facade out + of the correct client.py file. - """ - try: - facade = getattr(CLIENTS[str(version)], name) - except KeyError: - raise ImportError("No facades found for version {}".format(version)) - except AttributeError: - raise ImportError( - "No facade with name '{}' in version {}".format(name, version)) - return facade + """ + try: + facade = getattr(CLIENTS[str(version)], name) + except KeyError: + raise ImportError("No facades found for version {}".format(version)) + except AttributeError: + raise ImportError( + "No facade with name '{}' in version {}".format(name, version)) + return facade ''' @@ -127,6 +127,7 @@ class TypeRegistry(dict): return self[refname] + _types = TypeRegistry() _registry = KindRegistry() CLASSES = {} @@ -257,7 +258,7 @@ def buildTypes(schema, capture): for kind in sorted((k for k in _types if not isinstance(k, str)), key=lambda x: str(x)): name = _types[kind] - if name in capture and not name in NAUGHTY_CLASSES: + if name in capture and name not in NAUGHTY_CLASSES: continue args = Args(kind) # Write Factory class for _client.py @@ -277,9 +278,7 @@ class {}(Type): pprint.pformat(args.SchemaToPyMapping(), width=999), ", " if args else "", args.as_kwargs(), - textwrap.indent(args.get_doc(), INDENT * 2)) - ] - assignments = args._get_arg_str(False, False) + textwrap.indent(args.get_doc(), INDENT * 2))] if not args: source.append("{}pass".format(INDENT * 2)) @@ -289,7 +288,9 @@ class {}(Type): arg_type = arg[1] arg_type_name = strcast(arg_type) if arg_type in basic_types: - source.append("{}self.{} = {}".format(INDENT * 2, arg_name, arg_name)) + source.append("{}self.{} = {}".format(INDENT * 2, + arg_name, + arg_name)) elif issubclass(arg_type, typing.Sequence): value_type = ( arg_type_name.__parameters__[0] @@ -297,10 +298,16 @@ class {}(Type): else None ) if type(value_type) is typing.TypeVar: - source.append("{}self.{} = [{}.from_json(o) for o in {} or []]".format( - INDENT * 2, arg_name, strcast(value_type), arg_name)) + source.append( + "{}self.{} = [{}.from_json(o) " + "for o in {} or []]".format(INDENT * 2, + arg_name, + strcast(value_type), + arg_name)) else: - source.append("{}self.{} = {}".format(INDENT * 2, arg_name, arg_name)) + source.append("{}self.{} = {}".format(INDENT * 2, + arg_name, + arg_name)) elif issubclass(arg_type, typing.Mapping): value_type = ( arg_type_name.__parameters__[1] @@ -308,15 +315,28 @@ class {}(Type): else None ) if type(value_type) is typing.TypeVar: - source.append("{}self.{} = {{k: {}.from_json(v) for k, v in ({} or dict()).items()}}".format( - INDENT * 2, arg_name, strcast(value_type), arg_name)) + source.append( + "{}self.{} = {{k: {}.from_json(v) " + "for k, v in ({} or dict()).items()}}".format( + INDENT * 2, + arg_name, + strcast(value_type), + arg_name)) else: - source.append("{}self.{} = {}".format(INDENT * 2, arg_name, arg_name)) + source.append("{}self.{} = {}".format(INDENT * 2, + arg_name, + arg_name)) elif type(arg_type) is typing.TypeVar: - source.append("{}self.{} = {}.from_json({}) if {} else None".format( - INDENT * 2, arg_name, arg_type_name, arg_name, arg_name)) + source.append("{}self.{} = {}.from_json({}) " + "if {} else None".format(INDENT * 2, + arg_name, + arg_type_name, + arg_name, + arg_name)) else: - source.append("{}self.{} = {}".format(INDENT * 2, arg_name, arg_name)) + source.append("{}self.{} = {}".format(INDENT * 2, + arg_name, + arg_name)) source = "\n".join(source) capture.clear(name) @@ -435,7 +455,10 @@ def makeFunc(cls, name, params, result, async=True): ''' # map input types to rpc msg _params = dict() - msg = dict(type='{cls.name}', request='{name}', version={cls.version}, params=_params) + msg = dict(type='{cls.name}', + request='{name}', + version={cls.version}, + params=_params) {assignments} reply = {await}self.rpc(msg) return reply @@ -539,7 +562,7 @@ class Type: return d def to_json(self): - return json.dumps(self.serialize()) + return json.dumps(self.serialize(), cls=TypeEncoder, sort_keys=True) class Schema(dict): @@ -576,7 +599,7 @@ class Schema(dict): if not defs: return for d, data in defs.items(): - if d in _registry and not d in NAUGHTY_CLASSES: + if d in _registry and d not in NAUGHTY_CLASSES: continue node = self.deref(data, d) kind = node.get("type") @@ -762,6 +785,7 @@ def generate_facades(options): return captures + def setup(): parser = argparse.ArgumentParser() parser.add_argument("-s", "--schema", default="juju/client/schemas*") @@ -769,6 +793,7 @@ def setup(): options = parser.parse_args() return options + def main(): options = setup() @@ -780,5 +805,6 @@ def main(): write_definitions(captures, options, last_version) write_client(captures, options) + if __name__ == '__main__': main()