]> git.phdru.name Git - phdru.name/phdru.name.git/commitdiff
Generate news templates from text source files.
authorOleg Broytman <phd@phdru.name>
Sun, 12 Mar 2006 14:43:25 +0000 (14:43 +0000)
committerOleg Broytman <phd@phdru.name>
Sun, 12 Mar 2006 14:43:25 +0000 (14:43 +0000)
git-svn-id: file:///home/phd/archive/SVN/phdru.name/scripts@24 7bb0bf08-9e0d-0410-b083-99cee3bf18b8

Makefile
make-news.py [new file with mode: 0755]
news.py [new file with mode: 0644]
news.tmpl-en [new file with mode: 0644]
news.tmpl-ru [new file with mode: 0644]
reindex_blog.py

index 0d4e3e07cc7fe09763c18ac4b415a6eea8354aec..26c8cf4488f2d9284ff51190ba1d453717c1fd56 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -11,8 +11,14 @@ blog:
 phd_pp_ru.py: phd_pp_ru.tmpl
        @(umask 022; cheetah compile --nobackup $<)
 
+../htdocs/phd.pp.ru/news.tmpl: news_en
+       @(umask 022; PYTHONPATH=.; export PYTHONPATH; ./make-news.py en '' ../htdocs/phd.pp.ru/news.tmpl)
+
+../htdocs/phd.pp.ru/Russian/news.tmpl: news_ru
+       @(umask 022; PYTHONPATH=.; export PYTHONPATH; ./make-news.py ru Russian ../htdocs/phd.pp.ru/Russian/news.tmpl)
+
 templates = $(shell find ../htdocs/phd.pp.ru -type f -name \*.tmpl -print)
 htmls = $(patsubst %.tmpl,%.html,$(templates))
 
 .PHONY: html
-html: phd_pp.py phd_pp_ru.py $(htmls)
+html: phd_pp.py phd_pp_ru.py ../htdocs/phd.pp.ru/news.tmpl ../htdocs/phd.pp.ru/Russian/news.tmpl $(htmls)
diff --git a/make-news.py b/make-news.py
new file mode 100755 (executable)
index 0000000..9556322
--- /dev/null
@@ -0,0 +1,33 @@
+#! /usr/local/bin/python -O
+
+__version__ = "$Revision$"[11:-2]
+__revision__ = "$Id$"[5:-2]
+__date__ = "$Date$"[7:-2]
+__author__ = "Oleg BroytMann <phd@phd.pp.ru>"
+__copyright__ = "Copyright (C) 2006 PhiloSoft Design"
+
+
+import sys, os
+from news import get_news, write_if_changed
+
+header, news_items = get_news(sys.argv[1])
+root_dir = sys.argv[2]
+
+new_text = [header]
+
+new_text.append("""
+<p class="head">
+   <ul>
+""")
+
+for item in news_items:
+   new_text.append('      <li><a href="%s">%s - %s</a></li>\n' % (item.rel_link, item.date, item.title))
+
+new_text.append("""\
+   </ul>
+</p>
+#end def
+$phd_pp_ru.respond(self)
+""")
+
+write_if_changed(sys.argv[3], ''.join(new_text))
diff --git a/news.py b/news.py
new file mode 100644 (file)
index 0000000..7d0977c
--- /dev/null
+++ b/news.py
@@ -0,0 +1,56 @@
+"""News"""
+
+__version__ = "$Revision$"[11:-2]
+__revision__ = "$Id$"[5:-2]
+__date__ = "$Date$"[7:-2]
+__author__ = "Oleg BroytMann <phd@phd.pp.ru>"
+__copyright__ = "Copyright (C) 2006 PhiloSoft Design"
+__docformat__ = "epytext en"
+
+__all__ = ["get_news", "write_if_changed"]
+
+
+class NewsItem(object):
+   def __init__(self, date, title, rel_link):
+      self.date = date
+      self.title = title
+      self.rel_link = rel_link
+
+def get_news(lang):
+   """Get news
+
+   @param lang: langauge
+   @type lang: a string 'en' or 'ru'
+   @return: a tuple of (lnaguge-dependent header, a list of new items)
+
+   """
+   news_tmpl_file = open("news.tmpl-%s" % lang, 'r')
+   header = news_tmpl_file.read()
+   news_tmpl_file.close()
+
+   news_items_file = open("news_%s" % lang, 'r')
+   news_text = news_items_file.read()
+   news_items_file.close()
+
+   news_items = []
+   for line in news_text.split('\n'):
+      if not line: continue
+      date, rel_link, title = line.split(None, 2)
+      news_items.append(NewsItem(date, title, rel_link))
+
+   return header, news_items
+
+
+def write_if_changed(filename, new_text):
+   try:
+      infile = open(filename, 'r')
+      old_text = infile.read()
+      infile.close()
+   except IOError:
+      old_text = None
+
+   if old_text <> new_text:
+      print "Writing", filename
+      outfile = open(filename, 'w')
+      outfile.write(new_text)
+      outfile.close()
diff --git a/news.tmpl-en b/news.tmpl-en
new file mode 100644 (file)
index 0000000..bd1b90f
--- /dev/null
@@ -0,0 +1,8 @@
+#extends phd_pp_ru
+#implements respond
+#attr $Title = "Oleg BroytMann's Personal Page - News"
+#attr $Description = "BroytMann News Page Index Document"
+#attr $Copyright = 2004
+##
+#def body_html
+<H1>Most recently changed files</H1>
diff --git a/news.tmpl-ru b/news.tmpl-ru
new file mode 100644 (file)
index 0000000..e98f72e
--- /dev/null
@@ -0,0 +1,9 @@
+#extends phd_pp_ru
+#implements respond
+#attr $Title = "Oleg BroytMann's Personal Page - News"
+#attr $Description = "BroytMann News Page Index Document"
+#attr $Copyright = 2004
+#attr $Prev = "index.html"
+##
+#def body_html
+<H1>Последние изменённые файлы</H1>
index 45faac2fdb7908e9b383d6f1c454ca02f500b9ee..cd6906c0424691cc51512378e14a4b4691bfd5ea 100755 (executable)
@@ -100,20 +100,7 @@ months_names_ru0 = ['', "
    "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь"
 ]
 
-
-def write_if_changed(filename, new_text):
-   try:
-      infile = open(filename, 'r')
-      old_text = infile.read()
-      infile.close()
-   except IOError:
-      old_text = None
-
-   if old_text <> new_text:
-      print "Writing", filename
-      outfile = open(filename, 'w')
-      outfile.write(new_text)
-      outfile.close()
+from news import write_if_changed
 
 
 def write_template(level, year, month, day, titles, tags=None):