diff options
author | Dominik Holland <dominik.holland@qt.io> | 2020-01-22 14:45:18 +0100 |
---|---|---|
committer | Dominik Holland <dominik.holland@qt.io> | 2020-01-22 17:04:05 +0100 |
commit | 533c842385c2275ba02e0343fb90edb3759490be (patch) | |
tree | 41e6b5788fcb6e33e15417475c4aa68b549d057e | |
parent | 7020082856f36e06eb3e970155ca6e2eeafe5c7c (diff) | |
download | qtivi-533c842385c2275ba02e0343fb90edb3759490be.tar.gz |
ivigenerator: Fix python code style
Change-Id: I2158700d533f5412e95108985ce300f37ac4fad3
Reviewed-by: Robert Griebl <robert.griebl@qt.io>
-rwxr-xr-x | src/tools/ivigenerator/generate.py | 37 | ||||
-rw-r--r-- | src/tools/ivigenerator/generator/builtin_config.py | 4 | ||||
-rw-r--r-- | src/tools/ivigenerator/generator/filters.py | 113 | ||||
-rw-r--r-- | src/tools/ivigenerator/generator/global_functions.py | 16 | ||||
-rw-r--r-- | src/tools/ivigenerator/generator/rule_generator.py | 30 |
5 files changed, 124 insertions, 76 deletions
diff --git a/src/tools/ivigenerator/generate.py b/src/tools/ivigenerator/generate.py index 6d6963d..dcad893 100755 --- a/src/tools/ivigenerator/generate.py +++ b/src/tools/ivigenerator/generate.py @@ -39,21 +39,14 @@ # # SPDX-License-Identifier: LGPL-3.0 -import re import os import fnmatch import click import logging.config -import yaml -import sys from path import Path -from qface.generator import FileSystem, Generator, RuleGenerator +from qface.generator import FileSystem, Generator from qface.watch import monitor -from qface.idl.domain import Module, Interface, Property, Parameter, Field, Struct - -from jinja2 import TemplateAssertionError -import inspect import generator.builtin_config as builtin_config from generator.global_functions import register_global_functions @@ -67,6 +60,7 @@ log = logging.getLogger(__file__) builtinTemplatesPath = Path(here / 'templates') builtinTemplates = [os.path.splitext(f)[0] for f in os.listdir(builtinTemplatesPath) if fnmatch.fnmatch(f, '*.yaml')] + def generate(tplconfig, moduleConfig, annotations, imports, src, dst): log.debug('run {0} {1}'.format(src, dst)) FileSystem.strict = True @@ -90,17 +84,17 @@ def generate(tplconfig, moduleConfig, annotations, imports, src, dst): exit(1) FileSystem.merge_annotations(system, Path(annotations_file)) - srcFile = os.path.basename(src[0]) srcBase = os.path.splitext(srcFile)[0] - ctx = {'qtASVersion': builtin_config.config["VERSION"], 'srcFile':srcFile, 'srcBase':srcBase} - generator = CustomRuleGenerator(search_path=[tplconfig, builtinTemplatesPath], destination=dst, context = ctx, modules=module_names) + ctx = {'qtASVersion': builtin_config.config["VERSION"], 'srcFile': srcFile, 'srcBase': srcBase} + generator = CustomRuleGenerator(search_path=[tplconfig, builtinTemplatesPath], destination=dst, + context=ctx, modules=module_names) generator.env.keep_trailing_newline = True register_global_functions(generator) register_filters(generator) - #Make sure the config tag is available for all our symbols + # Make sure the config tag is available for all our symbols for module in system.modules: module.add_tag('config') for val, key in moduleConfig.items(): @@ -125,7 +119,6 @@ def generate(tplconfig, moduleConfig, annotations, imports, src, dst): generator.process_rules(os.path.dirname(tplconfig) + '/{0}.yaml'.format(os.path.basename(tplconfig)), system) - def run(format, moduleConfig, annotations, imports, src, dst): templatePath = format if format in builtinTemplates: @@ -134,14 +127,22 @@ def run(format, moduleConfig, annotations, imports, src, dst): if os.path.exists(templatePath): generate(templatePath, moduleConfig, annotations, imports, src, dst) else: - print('Invalid Format: {0}. It either needs to be one of the builtin formats or an existing ' - 'template folder. The following builtin formats are available: {1}'.format(format, builtinTemplates)) + print('Invalid Format: {0}. It either needs to be one of the builtin formats or an ' + 'existing template folder. The following builtin formats are available: {1}' + .format(format, builtinTemplates)) exit(1) + @click.command() -@click.option('--reload/--no-reload', default=False, help='Specifies whether the generator should keep track of the changes in the IDL file and update output on the fly (--no-reload by default).') -@click.option('--format', '-f', multiple=False, help='The format the autogenerator should use for the generation. This can either be one of the builtin formats or a path to a template folder. Builtin formats are: \n' + '\n'.join(builtinTemplates)) -@click.option('--module', default=False, help='The name of the Qt module the autogenerator is generating. This is automatically used by the qmake integration and passed directly to the qface templates.') +@click.option('--reload/--no-reload', default=False, help= + 'Specifies whether the generator should keep track of the changes in the IDL file and update ' + 'output on the fly (--no-reload by default).') +@click.option('--format', '-f', multiple=False, help='The format the autogenerator should use for ' + 'the generation. This can either be one of the builtin formats or a path to a template folder. ' + 'Builtin formats are: \n' + '\n'.join(builtinTemplates)) +@click.option('--module', default=False, help='The name of the Qt module the autogenerator is ' + 'generating. This is automatically used by the qmake integration and passed directly to the ' + 'qface templates.') @click.option('--force', is_flag=True, default=False, help='Always write all output files') @click.option('--annotations', '-A', multiple=True, default=False, help= 'Merges the given annotation file with annotions already in the qface file and the ' diff --git a/src/tools/ivigenerator/generator/builtin_config.py b/src/tools/ivigenerator/generator/builtin_config.py index efa6c67..7e46094 100644 --- a/src/tools/ivigenerator/generator/builtin_config.py +++ b/src/tools/ivigenerator/generator/builtin_config.py @@ -41,14 +41,16 @@ import yaml import os +import sys config = {} + def parse(here): global config builtin_config_path = here / '.config' if 'IVIGENERATOR_CONFIG' in os.environ: builtin_config_path = os.environ['IVIGENERATOR_CONFIG'] config = yaml.load(open(builtin_config_path), Loader=yaml.SafeLoader) - if not 'VERSION' in config or not 'FEATURES' in config: + if 'VERSION' not in config or 'FEATURES' not in config: sys.exit("Invalid builtin config") diff --git a/src/tools/ivigenerator/generator/filters.py b/src/tools/ivigenerator/generator/filters.py index b4df14c..737143c 100644 --- a/src/tools/ivigenerator/generator/filters.py +++ b/src/tools/ivigenerator/generator/filters.py @@ -42,12 +42,13 @@ import json from qface.idl.domain import Module, Interface, Property, Parameter, Field, Struct -from qface.helper.generic import upper_first +from qface.helper.generic import lower_first, upper_first from qface.helper.qtcpp import Filters from .global_functions import jinja_error, jinja_warning from . import builtin_config + def tag_by_path(symbol, path, default_value=False): """ Find the tag given by its full path in the object hierarchy, @@ -85,12 +86,13 @@ def enum_value(value, module_name): sub_values = [enum_value_to_cppliteral(v, module_name) for v in sub_values] return "|".join(sub_values) + def default_type_value(symbol): """ Find the default value for the type. Models are initialized as nullptr """ prefix = Filters.classPrefix - t = symbol.type # type: qface.domain.TypeSymbol + t = symbol.type if t.is_primitive: if t.is_int: return 'int(0)' @@ -120,12 +122,13 @@ def default_type_value(symbol): return 'nullptr' jinja_error('default_type_value: Unknown parameter {0} of type {1}'.format(symbol, symbol.type)) + def test_type_value(symbol): """ Find a value different than the default value for the type. Models are initialized as nullptr """ prefix = Filters.classPrefix - t = symbol.type # type: qface.domain.TypeSymbol + t = symbol.type if t.is_primitive: if t.is_int: return '111' @@ -149,7 +152,7 @@ def test_type_value(symbol): return '{0}{1}Module::{2}'.format(prefix, upper_first(module_name), value) elif symbol.type.is_list: value = test_type_value(t.nested.type) - if not (t.nested.type.is_primitive ): + if not (t.nested.type.is_primitive): value = 'QVariant::fromValue({0})'.format(value) return 'QVariantList({{{0}}})'.format(value) elif symbol.type.is_struct: @@ -159,15 +162,19 @@ def test_type_value(symbol): return 'new QIviPagingModel()' jinja_error('test_type_value: Unknown parameter {0} of type {1}'.format(symbol, symbol.type)) + def default_value_helper(symbol, res): t = symbol.type if t.is_struct: if not (isinstance(res, dict) or isinstance(res, list)): jinja_error('default_value: value in annotation is supposed to be a dict or list') if len(res) != len(t.reference.fields): - jinja_error('default_value: argument count in annotation and number of struct fields does not match') - values_string = ', '.join(default_value_helper(list(t.reference.fields)[idx], property) for idx, property in enumerate(res)) - return '{0}({{{1}}})'.format(t.type, values_string) + jinja_error('default_value: argument count in annotation and number of struct fields ' + 'does not match') + values = [] + for idx, property in enumerate(res): + values.append(default_value_helper(list(t.reference.fields)[idx], property)) + return '{0}({{{1}}})'.format(t.type, ', '.join(values)) if t.is_model or t.is_list: if not isinstance(res, list): jinja_error('default_value: value in annotation is supposed to be a list') @@ -195,13 +202,14 @@ def default_value_helper(symbol, res): return '{0}'.format(res) + def default_value(symbol, zone='='): """ Find the default value used by the simulator backend """ res = default_type_value(symbol) if symbol.type.is_model: - res = '{}'; + res = '{}' if 'config_simulator' in symbol.tags and 'default' in symbol.tags['config_simulator']: res = symbol.tags['config_simulator']['default'] if isinstance(res, dict): @@ -213,6 +221,7 @@ def default_value(symbol, zone='='): return res + def parameter_type_default(symbol): """ Return the parameter declaration for properties, handle camel case module name @@ -239,7 +248,9 @@ def parameter_type_default(symbol): return 'QIviPagingModel *{0}=nullptr'.format(symbol) else: return 'const {0}{1} &{2}={0}{1}()'.format(prefix, symbol.type.reference.name, symbol) - jinja_error('parameter_type_default: Unknown parameter {0} of type {1}'.format(symbol, symbol.type)) + jinja_error('parameter_type_default: Unknown parameter {0} of type {1}'.format(symbol, + symbol.type)) + def parameter_type(symbol): """ @@ -276,7 +287,9 @@ def return_type(symbol): """ prefix = Filters.classPrefix if symbol.type.is_enum or symbol.type.is_flag: - return('{0}{1}Module::{2}'.format(prefix, upper_first(symbol.type.reference.module.module_name), flag_type(symbol))) + return('{0}{1}Module::{2}'.format(prefix, + upper_first(symbol.type.reference.module.module_name), + flag_type(symbol))) if symbol.type.is_void or symbol.type.is_primitive: if symbol.type.name == 'string': return 'QString' @@ -323,24 +336,27 @@ def domain_values(symbol): return symbol.tags['config_simulator']['domain'] return None + def getter_name(symbol): """ Returns the getter name of the property """ if type(symbol) is Property: if 'config' in symbol.tags and 'getter_name' in symbol.tags['config']: - return symbol.tags['config']['getter_name'] + return symbol.tags['config']['getter_name'] return symbol + def setter_name(symbol): """ Returns the setter name of the property """ if type(symbol) is Property: if 'config' in symbol.tags and 'setter_name' in symbol.tags['config']: - return symbol.tags['config']['setter_name'] + return symbol.tags['config']['setter_name'] return 'set' + symbol.name[0].upper() + symbol.name[1:] + def range_value(symbol, index, key): """ Returns value for property (if defined by @range index or key) @@ -379,6 +395,7 @@ def has_domains(properties): return True return False + def strip_QT(s): """ If the given string starts with QT, stip it away. @@ -388,25 +405,26 @@ def strip_QT(s): return s[2:] return s + def json_domain(properties): """ Returns property domains formated in json """ data = {} if len(properties): - data["iviVersion"] = builtin_config.config["VERSION"] + data["iviVersion"] = builtin_config.config["VERSION"] for property in properties: if 'config_simulator' in property.tags: for p in ['range', 'domain', 'minimum', 'maximum']: - if property.tags['config_simulator'] is not None and p in property.tags['config_simulator']: - if not property.name in data: + if (property.tags['config_simulator'] is not None + and p in property.tags['config_simulator']): + if property.name not in data: data[property.name] = {} data[property.name][p] = property.tags['config_simulator'][p] return json.dumps(data, separators=(',', ':')) -def simulationData(module): - found = False +def simulationData(module): data = {} for interface in module.interfaces: iData = {} @@ -415,25 +433,29 @@ def simulationData(module): for property in interface.properties: if 'config_simulator' in property.tags: for p in ['range', 'domain', 'minimum', 'maximum', 'default']: - if property.tags['config_simulator'] is not None and p in property.tags['config_simulator']: - if not property.name in iData: + if (property.tags['config_simulator'] is not None + and p in property.tags['config_simulator']): + if property.name not in iData: iData[property.name] = {} - iData[property.name][p] = symbolToJson(property.tags['config_simulator'][p], property.type) + iData[property.name][p] = symbolToJson(property.tags['config_simulator'][p], + property.type) data[interface.name] = iData return json.dumps(data, indent=' ') + def symbolToJson(data, symbol): if symbol.type.is_struct: t = symbol.type if not (isinstance(data, dict) or isinstance(data, list)): jinja_error('simulationData: value in annotation is supposed to be a dict or list') if len(data) != len(t.reference.fields): - jinja_error('simulationData: argument count in annotation and number of struct fields does not match') + jinja_error('simulationData: argument count in annotation and number of struct fields ' + 'does not match') newList = list(symbolToJson(property, list(t.reference.fields)[idx]) for idx, property in enumerate(data)) - return { "type": symbol.type.name, "value": newList } + return {"type": symbol.type.name, "value": newList} elif symbol.type.is_enum or symbol.type.is_flag: module_name = symbol.type.reference.module.module_name - return { "type": "enum", "value": enum_value(data, module_name) } + return {"type": "enum", "value": enum_value(data, module_name)} elif symbol.type.is_list or symbol.type.is_model: nested = symbol.type.nested if nested.is_complex: @@ -443,12 +465,13 @@ def symbolToJson(data, symbol): return newList return data + def qml_control_properties(symbol, backend_object): """ Returns properties of the QML control matching to this IDL type (e.g. min/max properties) """ - prop_str = lower_first_filter(symbol) + "Control" + prop_str = lower_first(symbol) + "Control" if isinstance(symbol, Property): top = range_high(symbol) bottom = range_low(symbol) @@ -465,7 +488,9 @@ def qml_control_properties(symbol, backend_object): values = domain_values(symbol) if values is None and (symbol.type.is_enum or symbol.type.is_flag): values_string = ' '.join('ListElement {{ key: "{0}"; value: {1}.{0} }}'.format(e, qml_type(symbol.interface)) for e in symbol.type.reference.members) - return 'id: {0}; textRole: "key"; {2} model: ListModel {{ {1} }}'.format(prop_str, values_string, binding) + return 'id: {0}; textRole: "key"; {2} model: ListModel {{ {1} }}'.format(prop_str, + values_string, + binding) if values is not None: values_string = ','.join('"'+str(e)+'"' for e in values) return 'id: {0}; model: [ {1} ]; '.format(prop_str, values_string) @@ -479,13 +504,15 @@ def qml_control_properties(symbol, backend_object): if isinstance(symbol, Parameter): return 'id: {1}Param{0}'.format(prop_str, symbol.operation) if isinstance(symbol, Field): - return 'id: {1}_{0}'.format(prop_str, lower_first_filter(symbol.struct)) + return 'id: {1}_{0}'.format(prop_str, lower_first(symbol.struct)) + def qml_control_signal_parameters(symbol): """ Returns the parameters for calling the signal using the values from the ui controls """ - return ', '.join('{0}Param{1}Control.{2}'.format(e.operation, lower_first_filter(e), qml_binding_property(e)) for e in symbol.parameters) + return ', '.join('{0}Param{1}Control.{2}'.format(e.operation, lower_first(e),qml_binding_property(e)) for e in symbol.parameters) + def qml_meta_control_name(symbol): """ @@ -505,6 +532,7 @@ def qml_meta_control_name(symbol): if values is not None: return "ComboBox" + def qml_type_control_name(symbol): """ Returns name of the QML control inferred based on the type of the symbol. @@ -540,13 +568,15 @@ def qml_control_name(symbol): def qml_control(symbol, backend_object): """ - Returns QML code for the control (or group of controls) to represent the editing UI for the symbol. + Returns QML code for the control (or group of controls) to represent the editing UI for the + symbol. """ if symbol.type.is_struct: return qml_struct_control(symbol) - return "{0} {{ {1} }}".format(qml_control_name(symbol), qml_control_properties(symbol, backend_object)) + return "{0} {{ {1} }}".format(qml_control_name(symbol), + qml_control_properties(symbol, backend_object)) def qml_binding_property(symbol): @@ -557,13 +587,15 @@ def qml_binding_property(symbol): control_name = qml_control_name(symbol) if control_name == "CheckBox": return "checked" - elif control_name == "Slider" or control_name == "SpinBox" or control_name == "FlagControl" or control_name == "EnumControl": + elif (control_name == "Slider" or control_name == "SpinBox" or control_name == "FlagControl" + or control_name == "EnumControl"): return "value" elif control_name == "TextField": return "text" elif control_name == "ComboBox": return "currentIndex" + def qml_struct_control(symbol): if symbol.type.is_struct and symbol.type.reference.fields: result = "Rectangle { ColumnLayout { " @@ -579,7 +611,8 @@ def qml_info_type(symbol): """ prefix = Filters.classPrefix if symbol.type.is_enum or symbol.type.is_flag: - return('{0}{1}Module::{2}'.format(prefix, upper_first(symbol.module.module_name), flag_type(symbol))) + return('{0}{1}Module::{2}'.format(prefix, upper_first(symbol.module.module_name), + flag_type(symbol))) elif symbol.type.is_void or symbol.type.is_primitive: if symbol.type.is_real: return 'double' @@ -593,12 +626,13 @@ def qml_info_type(symbol): else: jinja_error('qml_info_type: Unknown symbol {0} of type {1}'.format(symbol, symbol.type)) + def qml_type(symbol): """ :param interface: - :return: Returns the name of the interface for using in QML. This name is defined in the IDL under - the "config" tag as "qml_type". This annotation is optional, if not provided, the interface name is - used. + :return: Returns the name of the interface for using in QML. This name is defined in the IDL + under the "config" tag as "qml_type". This annotation is optional, if not provided, the + interface name is used. """ result = symbol.name if 'qml_type' in symbol.tags['config']: @@ -607,6 +641,7 @@ def qml_type(symbol): result = symbol.tags['config']['qml_name'] return result + def model_type(symbol): if symbol.type.is_model: nested = symbol.type.nested @@ -618,8 +653,6 @@ def struct_includes(symbol): includesSet = set() tpl = '#include \"{0}.h\"' - module = symbol.module - if isinstance(symbol, Struct): for val in symbol.fields: if val.type.is_struct: @@ -641,11 +674,12 @@ def struct_includes(symbol): return includesSet + def comment_text(comment): """ Returns the text of the passed comment without the leading/trailing comment tokens e.g. /**, * """ - comment_start = [ '/**', '/*!', '/*'] + comment_start = ['/**', '/*!', '/*'] processed = [] isComment = False @@ -656,11 +690,12 @@ def comment_text(comment): for token in comment_start: if (comment.startswith(token)): isComment = True - break; + break if isComment: comment = comment[3:-2] else: - jinja_error("comment_text: The provided comment needs to be start with one of these strings: {}".format(comment_start)) + jinja_error("comment_text: The provided comment needs to be start with one of these " + "strings: {}".format(comment_start)) for line in comment.splitlines(): line = line.lstrip(" *") diff --git a/src/tools/ivigenerator/generator/global_functions.py b/src/tools/ivigenerator/generator/global_functions.py index 1ef8b60..69c60e5 100644 --- a/src/tools/ivigenerator/generator/global_functions.py +++ b/src/tools/ivigenerator/generator/global_functions.py @@ -45,6 +45,7 @@ import click from jinja2 import TemplateAssertionError from jinja2 import contextfunction + def jinjaTrace(): """ Collects all jinja template files and the line numbers from the current calltrace @@ -54,17 +55,18 @@ def jinjaTrace(): while frame: template = frame.f_globals.get('__jinja_template__') if template is not None: - infos.append((inspect.getsourcefile(frame), template.get_corresponding_lineno(frame.f_lineno))) + infos.append((inspect.getsourcefile(frame), + template.get_corresponding_lineno(frame.f_lineno))) frame = frame.f_back - return infos + @contextfunction def jinja_error(context, msg): """ Throws an error for the current jinja template and the templates this is included from - This can be used inside a filter to indicate problems with the passed arguments or direclty inside - an template + This can be used inside a filter to indicate problems with the passed arguments or direclty + inside an template """ infos = jinjaTrace() if len(infos): @@ -76,11 +78,12 @@ def jinja_error(context, msg): raise TemplateAssertionError(message, infos[0][1], "", infos[0][0]) raise TemplateAssertionError(msg, -1, "", "unknown") + def jinja_warning(msg): """ Reports an warning in the current jinja template. - This can be used inside a filter to indicate problems with the passed arguments or direclty inside - an template + This can be used inside a filter to indicate problems with the passed arguments or direclty + inside an template """ file, lineno = jinjaTrace()[0] if file: @@ -89,6 +92,7 @@ def jinja_warning(msg): message = '<unknown-file>: warning: {0}'.format(msg) click.secho(message, fg='yellow', err=True) + def register_global_functions(generator): generator.env.globals["error"] = jinja_error generator.env.globals["warning"] = jinja_warning diff --git a/src/tools/ivigenerator/generator/rule_generator.py b/src/tools/ivigenerator/generator/rule_generator.py index fbeef28..ab14531 100644 --- a/src/tools/ivigenerator/generator/rule_generator.py +++ b/src/tools/ivigenerator/generator/rule_generator.py @@ -47,9 +47,12 @@ from qface.idl.domain import Module, Interface, Property, Parameter, Field, Stru log = logging.getLogger(__file__) + class CustomRuleGenerator(RuleGenerator): """Extended RuleGenerator to only generate the wanted modules instead of all""" - def __init__(self, search_path: str, destination:Path, modules:[], context:dict={}, features:set=set(), force=False): + + def __init__(self, search_path: str, destination: Path, modules: [], context: dict = {}, + features: set = set(), force=False): super().__init__(search_path, destination, context, features, force) self.module_names = modules @@ -61,7 +64,7 @@ class CustomRuleGenerator(RuleGenerator): super().process_rules(path, system) def _process_rules(self, rules: dict, system): - self._source = None # reset the template source + self._source = None # reset the template source if not self._shall_proceed(rules): return self.context.update(rules.get('context', {})) @@ -69,8 +72,8 @@ class CustomRuleGenerator(RuleGenerator): self.source = rules.get('source', None) self._process_rule(rules.get('system', None), {'system': system}) for module in system.modules: - #Only generate files for the modules detected from the first parse run - if not module.name in self.module_names: + # Only generate files for the modules detected from the first parse run + if module.name not in self.module_names: continue log.debug('generate code for module %s', module) @@ -88,7 +91,6 @@ class CustomRuleGenerator(RuleGenerator): for enum in module.enums: self._process_rule(rules.get('enum', None), {'enum': enum}) - def _process_legacy(self, gen_config, system): click.secho('Using the legacy Generation YAML Parser. Please consider porting to the new ' @@ -96,7 +98,7 @@ class CustomRuleGenerator(RuleGenerator): for module in system.modules: # Only generate files for the modules detected from the first parse run - if not module.name in self.module_names: + if module.name not in self.module_names: continue log.debug('generate code for module %s', module) @@ -110,8 +112,10 @@ class CustomRuleGenerator(RuleGenerator): dst = self.apply('{{dst}}', self.context) self.destination = dst module_rules = gen_config['generate_rules']['module_rules'] - force = True #moduleConfig['force'] - if module_rules is None: module_rules = [] + force = True # moduleConfig['force'] + if module_rules is None: + module_rules = [] + for rule in module_rules: preserve = rule['preserve'] if 'preserve' in rule else False self.write(rule['dest_file'], rule['template_file'], self.context, preserve, force) @@ -119,15 +123,17 @@ class CustomRuleGenerator(RuleGenerator): log.debug('generate backend code for interface %s', interface) self.context.update({'interface': interface}) interface_rules = gen_config['generate_rules']['interface_rules'] - if interface_rules is None: interface_rules = [] + if interface_rules is None: + interface_rules = [] for rule in interface_rules: preserve = rule['preserve'] if 'preserve' in rule else False - self.write(rule['dest_file'], rule['template_file'], self.context, preserve, force) - if 'struct_rules' in gen_config['generate_rules'] and isinstance(gen_config['generate_rules']['struct_rules'], list): + self.write(rule['dest_file'], rule['template_file'], self.context, preserve, + force) + if ('struct_rules' in gen_config['generate_rules'] + and isinstance(gen_config['generate_rules']['struct_rules'], list)): for struct in module.structs: log.debug('generate code for struct %s', struct) self.context.update({'struct': struct}) for rule in gen_config['generate_rules']['struct_rules']: preserve = rule['preserve'] if 'preserve' in rule else False self.write(rule['dest_file'], rule['template_file'], ctx, preserve, force) - |