def GetOutput(self, policy_json, definitions, writer_type): '''Generates an output of a writer. Args: policy_json: Raw policy JSON string. definitions: Definitions to create writer configurations. writer_type: Writer type (e.g. 'admx'), see template_formatter.py. Returns: The string of the template created by the writer. ''' # Evaluate policy_json. For convenience, fix indentation in statements like # policy_json = ''' # { # ... # }''') start_idx = 1 if policy_json[0] == '\n' else 0 policy_data = eval(textwrap.dedent(policy_json[start_idx:])) config = writer_configuration.GetConfigurationForBuild(definitions) policy_generator = \ policy_template_generator.PolicyTemplateGenerator(config, policy_data) writer = template_formatter.GetWriter(writer_type, config) return policy_generator.GetTemplateText(writer)
def _GetWriterConfiguration(grit_defines): '''Returns the writer configuration based on grit defines. Args: grit_defines: Array of grit defines, see grit_rule.gni. ''' # Build a dictionary from grit defines, which can be plain DEFs or KEY=VALUEs. grit_defines_dict = {} for define in grit_defines: parts = define.split('=', 1) grit_defines_dict[parts[0]] = parts[1] if len(parts) > 1 else 1 return writer_configuration.GetConfigurationForBuild(grit_defines_dict)