def write_output(data, fmt): '''Write data to stdout''' if fmt == 'json': out = json.dumps(data, indent=2) else: out = yaml.dump(data, default_flow_style=False, Dumper=Dumper) sys.stdout.write(out + '\n')
def load_using_schema(self, schema, fileinfo): '''Helps loading validated data from file''' self.reader.load_reader_by_extension(fileinfo.extension) try: raw_data = self.reader.read(fileinfo.path) except Exception as e: raise CorruptFileException('{}: {}'.format(fileinfo.path, e)) try: data = schema.load(raw_data) except ValidationError as e: raise InvalidFormatException( '{}: while reading this file below errors were found:\n{}'.format( fileinfo.path, yaml.dump(e.messages, default_flow_style=False, Dumper=Dumper))) return data
def load_using_schema(self, schema, fileinfo): '''Helps loading validated data from file''' self.reader.load_reader_by_extension(fileinfo.extension) try: raw_data = self.reader.read(fileinfo.path) except Exception as e: raise CorruptFileException('{}: {}'.format(fileinfo.path, e)) try: data = schema.load(raw_data) except ValidationError as e: raise InvalidFormatException( '{}: while reading this file below errors were found:\n{}'. format( fileinfo.path, yaml.dump(e.messages, default_flow_style=False, Dumper=Dumper))) return data
def _write_yaml(data, filepath): '''Write yaml files''' with open(filepath, 'w', encoding='utf-8') as f: yaml.dump(data, f, default_flow_style=False, Dumper=Dumper)