]> git.phdru.name Git - phdru.name/phdru.name.git/commitdiff
Split blog loading/saving from reindex_blog.py to blog_db.py
authorOleg Broytman <phd@phdru.name>
Mon, 10 Apr 2017 03:16:17 +0000 (06:16 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 10 Apr 2017 03:38:34 +0000 (06:38 +0300)
Also remove parameters - it is always Russian blog.

blog_db.py [new file with mode: 0755]
reindex_blog.py
reindex_blog_ru

diff --git a/blog_db.py b/blog_db.py
new file mode 100755 (executable)
index 0000000..5850e76
--- /dev/null
@@ -0,0 +1,30 @@
+#! /usr/bin/env python
+
+import sys, os
+
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 2017 PhiloSoft Design"
+
+blog_data_root = os.path.dirname(__file__)
+blog_root = os.path.join(blog_data_root, '../htdocs/phdru.name/Russian/blog')
+blog_filename = os.path.join(blog_data_root, "ru/blog_dict.pickle")
+
+try:
+    import cPickle as pickle
+except ImportError:
+    import pickle
+
+def load_blog():
+    try:
+        blog_file = open(blog_filename, "rb")
+    except IOError:
+        blog = {}
+    else:
+        blog = pickle.load(blog_file)
+        blog_file.close()
+    return blog
+
+def save_blog(blog):
+    blog_file = open(blog_filename, "wb")
+    pickle.dump(blog, blog_file, pickle.HIGHEST_PROTOCOL)
+    blog_file.close()
index ac22002b324adc704dd42119dd5f4f4383dc2880..c2e16ce32c35029bb31d05f382f46e4d65e55617 100755 (executable)
@@ -5,30 +5,12 @@ __author__ = "Oleg Broytman <phd@phdru.name>"
 __copyright__ = "Copyright (C) 2006-2017 PhiloSoft Design"
 
 import sys, os
-from Cheetah.compat import string_type
-
-blog_data_root = sys.argv[1]
-blog_root = sys.argv[2]
-blog_filename = os.path.join(blog_data_root, "blog_dict.pickle")
-
-try:
-   import cPickle as pickle
-except ImportError:
-   import pickle
-
 from Cheetah.Template import Template
+from Cheetah.compat import string_type
+from blog_db import blog_root, load_blog, save_blog
 
 
-# Load old blog
-
-try:
-   blog_file = open(blog_filename, "rb")
-except IOError:
-   old_blog = {}
-else:
-   old_blog = pickle.load(blog_file)
-   blog_file.close()
-
+old_blog = load_blog()
 
 # blog is a dictionary mapping
 # (year, month, day) => [list of (file, title, lead, tags)]
@@ -87,10 +69,8 @@ for dirpath, dirs, files in os.walk(blog_root):
          bodies[key] = body
 
 # Need to save the blog?
-if blog <> old_blog:
-   blog_file = open(blog_filename, "wb")
-   pickle.dump(blog, blog_file, pickle.HIGHEST_PROTOCOL)
-   blog_file.close()
+if blog != old_blog:
+    save_blog(blog)
 
 # Localized month names
 
index e51558db0a1c261c36018eecad4e3b1e63849263..a02f1906874a4ccfca474fea9bbe584947341aae 100755 (executable)
@@ -6,4 +6,4 @@ LC_TIME=ru_RU.KOI8-R
 export LC_TIME
 
 cd ../htdocs/phdru.name &&
-exec ../../phdru.name/reindex_blog.py ../../phdru.name/ru Russian/blog
+exec ../../phdru.name/reindex_blog.py