Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions ladybug/commandutil.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# coding=utf-8
"""Utility functions for running the functions of CLI commands outside of the CLI."""
import sys
import os


Expand Down Expand Up @@ -49,11 +50,20 @@ def process_content_to_output(content_str, output_file=None):
dir_name = os.path.dirname(os.path.abspath(output_file))
if not os.path.isdir(dir_name):
os.makedirs(dir_name)
with open(output_file, 'w') as of:
of.write(content_str)
if (sys.version_info < (3, 0)): # we need to manually encode it as UTF-8
with open(output_file, 'w') as of:
of.write(content_str.encode('utf-8'))
else:
with open(output_file, 'w', encoding='utf-8') as of:
of.write(content_str)
else:
if 'stdout' not in str(output_file):
dir_name = os.path.dirname(os.path.abspath(output_file.name))
if not os.path.isdir(dir_name):
os.makedirs(dir_name)
output_file.write(content_str)
if (sys.version_info < (3, 0)): # we need to manually encode it as UTF-8
with open(output_file, 'w') as of:
of.write(content_str.encode('utf-8'))
else:
with open(output_file, 'w', encoding='utf-8') as of:
of.write(content_str)