def _print_resource(r): if opts.validate: try: r.validate_data() except error_class as e: _handle(e) return if opts.format: txt = expand_abbreviations(opts.format, fields) lines = txt.split("\\n") for line in lines: try: line_ = r.format(line) except error_class as e: _handle(e) break if opts.no_newlines: line_ = line_.replace('\n', "\\n") print line_ else: print r.qualified_name
def _format_search_result(self, resource_search_result): formatted_lines = [] # just ignore formatting if family if resource_search_result.resource_type == "family": family_name = resource_search_result.resource return [(family_name, info)] if resource_search_result.validation_error: line1 = (resource_search_result.resource.qualified_name, error) line2 = (resource_search_result.validation_error, critical) formatted_lines.extend([line1, line2]) elif self.output_format: txt = expand_abbreviations(self.output_format, self.fields) lines = txt.split("\\n") for line in lines: try: line_ = resource_search_result.resource.format(line) except ResourceContentError as e: # formatting may read attrib that causes validation fail line1 = (resource_search_result.resource.qualified_name, error) line2 = (str(e), critical) formatted_lines.extend([line1, line2]) break if self.suppress_newlines: line_ = line_.replace('\n', "\\n") formatted_lines.append((line_, info)) else: line = (resource_search_result.resource.qualified_name, info) formatted_lines.append(line) return formatted_lines