From aa659234bb19fe885854f1b6d6e0597f3a79d168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Sat, 12 Aug 2017 19:19:24 +0200 Subject: [PATCH] Cleanup HAR_DIR if a scrap failed --- lookyloo/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lookyloo/__init__.py b/lookyloo/__init__.py index 1f9bab7a..0d3a366b 100644 --- a/lookyloo/__init__.py +++ b/lookyloo/__init__.py @@ -57,9 +57,17 @@ def scrap(): return render_template('scrap.html') +def get_report_dirs(): + # Cleanup HAR_DIR of failed runs. + for report_dir in os.listdir(HAR_DIR): + if not os.listdir(os.path.join(HAR_DIR, report_dir)): + os.rmdir(os.path.join(HAR_DIR, report_dir)) + return sorted(os.listdir(HAR_DIR)) + + @app.route('/tree/', methods=['GET']) def tree(tree_id): - report_dir = sorted(os.listdir(HAR_DIR))[tree_id] + report_dir = get_report_dirs()[tree_id] tree = load_tree(report_dir) nodes, faces, base64 = tree.redraw() return render_template('tree.html', nodes=nodes, faces=faces, base64_img=base64) @@ -71,7 +79,7 @@ def index(): titles = [] if not os.path.exists(HAR_DIR): os.makedirs(HAR_DIR) - for report_dir in sorted(os.listdir(HAR_DIR)): + for report_dir in get_report_dirs(): har_files = sorted(glob(os.path.join(HAR_DIR, report_dir, '*.har'))) if not har_files: continue