]> git.phdru.name Git - phdru.name/phdru.name.git/commitdiff
Fix(remove_old_html): Check if the blog is empty
authorOleg Broytman <phd@phdru.name>
Sun, 12 Dec 2021 23:16:30 +0000 (02:16 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 12 Dec 2021 23:16:30 +0000 (02:16 +0300)
remove_old_html.py

index 904ff9eb8a6d934e3c63bcb4a1bfbf51eba2cad7..bbddded89f3580c960ef45aa26fe8477e34be21e 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__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)