def save_web_report_link_to_file(logger, export_dir, web_report_data):
"""
Write Web Report links to 'web-report-links.csv' on disk at specified location
Any existing file with the same name will be appended to
:param logger: the logger
:param export_dir: path to directory for exports
:param web_report_data: Data to write to CSV: Template ID, Template name, Audit ID, Audit name, Web Report link
"""
if not os.path.exists(export_dir):
logger.info("Creating directory at {0} for Web Report links.".format(export_dir))
os.makedirs(export_dir)
file_path = os.path.join(export_dir, 'web-report-links.csv')
if os.path.isfile(file_path):
logger.info('Appending Web Report link to ' + file_path)
try:
with open(file_path, 'ab') as web_report_link_csv:
wr = csv.writer(web_report_link_csv, dialect='excel', quoting=csv.QUOTE_ALL)
wr.writerow(web_report_data)
web_report_link_csv.close()
except Exception as ex:
log_critical_error(logger, ex, 'Exception while writing' + file_path + ' to file')
else:
logger.info('Creating ' + file_path)
logger.info('Appending web report to ' + file_path)
try:
with open(file_path, 'wb') as web_report_link_csv:
wr = csv.writer(web_report_link_csv, dialect='excel', quoting=csv.QUOTE_ALL)
wr.writerow(['Template ID', 'Template Name', 'Audit ID', 'Audit Name', 'Web Report Link'])
wr.writerow(web_report_data)
web_report_link_csv.close()
except Exception as ex:
log_critical_error(logger, ex, 'Exception while writing' + file_path + ' to file')
exporter.py 文件源码
python
阅读 39
收藏 0
点赞 0
评论 0
评论列表
文章目录