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