本文整理汇总了Python中tools.log.Log.beautify_json方法的典型用法代码示例。如果您正苦于以下问题:Python Log.beautify_json方法的具体用法?Python Log.beautify_json怎么用?Python Log.beautify_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tools.log.Log
的用法示例。
在下文中一共展示了Log.beautify_json方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_html_report
# 需要导入模块: from tools.log import Log [as 别名]
# 或者: from tools.log.Log import beautify_json [as 别名]
def generate_html_report(self, report_in_js=True):
self.generate_report_path()
reportjs = self.report_path + '/' + 'report.js'
reporttemplate = self.html_path + '/' + 'report.html'
reporthtml = self.report_path + '/' + self.dict_all["project"]["name"] + '.html'
if report_in_js:
shutil.copy(reporttemplate, reporthtml)
with open(reportjs, 'w') as f:
try:
d = Log.beautify_json(self.dict_all).encode('utf8').decode('utf8')
f.writelines(["report = ", "\n", d, ";", "\n"])
except UnicodeDecodeError as e:
print(e)
else:
reporthtml = self.report_path + '/' + self.dict_all["project"]["name"] + '_report.html'
with open(reporttemplate, 'r') as src, open(reporthtml, 'w') as dst:
for line in src:
if "<script" in line and "src" in line and "report.js" in line:
d = Log.beautify_json(self.dict_all)
dst.writelines(["<script type='text/javascript' charset='utf-8'>", "\n"])
dst.writelines(["var report = ", "\n"])
dst.writelines([d.encode("utf8").decode("utf8"), ";", "\n"])
dst.writelines(["</script>", "\n"])
else:
dst.write(line)
pass
示例2: write_to_file
# 需要导入模块: from tools.log import Log [as 别名]
# 或者: from tools.log.Log import beautify_json [as 别名]
def write_to_file(thepath, thefile, content, append=False):
if not content:
content = {}
data = Log.beautify_json(content) if type(content) is not str else content
if not os.path.exists(thepath):
os.makedirs(thepath)
try:
filepath = "%s/%s" % (thepath, thefile)
file_open_mode = "a" if append else "w"
with codecs.open(filepath, file_open_mode, "utf-8-sig") as f:
f.write(unicode(data, "utf-8"))
f.write("\r\n")
except UnicodeDecodeError as e:
print "UnicodeDecodeError: %s" % e
except IOError as e:
print "IOError: %s" % e
pass