fix format-yaml to work with python 3
Change-Id: I48717815536a4e31fbac799f7fc7743ff8bc3c4d Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
52bcc89e8f
commit
25ea1d8ecd
@ -23,10 +23,10 @@ def main():
|
||||
args = parser.parse_args()
|
||||
for filename in args.file:
|
||||
print("Reformatting %s" % filename)
|
||||
with open(filename, 'rb') as fh:
|
||||
with open(filename, 'r', encoding='utf-8') as fh:
|
||||
contents = yamlutils.loads(fh.read())
|
||||
contents = yamlutils.dumps(contents)
|
||||
with open(filename, 'wb') as fh:
|
||||
with open(filename, 'w', encoding='utf-8') as fh:
|
||||
fh.write(contents)
|
||||
if not contents.endswith("\n"):
|
||||
fh.write("\n")
|
||||
|
@ -90,11 +90,13 @@ for str_type in [six.binary_type, six.text_type]:
|
||||
|
||||
def dumps(obj):
|
||||
"""Dump a python object -> blob and apply our pretty styling."""
|
||||
buff = six.BytesIO()
|
||||
buff = six.StringIO()
|
||||
yaml.dump_all([obj], buff,
|
||||
explicit_start=True, indent=2,
|
||||
explicit_start=True,
|
||||
indent=2,
|
||||
default_flow_style=False,
|
||||
line_break="\n", Dumper=PrettySafeDumper,
|
||||
line_break="\n",
|
||||
Dumper=PrettySafeDumper,
|
||||
allow_unicode=True)
|
||||
return buff.getvalue()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user