本文整理匯總了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