From fde7b6e4d87740a43c833299a27cb03bc62cc120 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 13 Dec 2021 02:16:30 +0300 Subject: [PATCH] Fix(remove_old_html): Check if the blog is empty --- remove_old_html.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/remove_old_html.py b/remove_old_html.py index 904ff9e..bbddded 100755 --- a/remove_old_html.py +++ b/remove_old_html.py @@ -1,7 +1,7 @@ #! /usr/bin/env python __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2020 PhiloSoft Design" +__copyright__ = "Copyright (C) 2020, 2021 PhiloSoft Design" import os from blog_db import blog_root, load_blog @@ -62,19 +62,20 @@ for key in sorted(blog): if current_mtime is not None and (next_mtime < current_mtime): os.remove(next_html) -current_tmpl = fullpath(key, blog_post) -try: - current_mtime = os.path.getmtime(current_tmpl) -except OSError: - pass -else: - current_mtime = None +if blog: + current_tmpl = fullpath(key, blog_post) + try: + current_mtime = os.path.getmtime(current_tmpl) + except OSError: + pass + else: + current_mtime = None -prev_html = html(fullpath(current_key, current_blog_post)) -try: - prev_mtime = os.path.getmtime(prev_html) -except OSError: - pass -else: - if current_mtime is not None and (prev_mtime < current_mtime): - os.remove(prev_html) + prev_html = html(fullpath(current_key, current_blog_post)) + try: + prev_mtime = os.path.getmtime(prev_html) + except OSError: + pass + else: + if current_mtime is not None and (prev_mtime < current_mtime): + os.remove(prev_html) -- 2.39.2