From 30c30ad32bd724dd3026cd8c19d2abe033e85dfa Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 12 Mar 2006 14:43:25 +0000 Subject: [PATCH] Generate news templates from text source files. git-svn-id: file:///home/phd/archive/SVN/phdru.name/scripts@24 7bb0bf08-9e0d-0410-b083-99cee3bf18b8 --- Makefile | 8 ++++++- make-news.py | 33 +++++++++++++++++++++++++++++ news.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ news.tmpl-en | 8 +++++++ news.tmpl-ru | 9 ++++++++ reindex_blog.py | 15 +------------ 6 files changed, 114 insertions(+), 15 deletions(-) create mode 100755 make-news.py create mode 100644 news.py create mode 100644 news.tmpl-en create mode 100644 news.tmpl-ru diff --git a/Makefile b/Makefile index 0d4e3e0..26c8cf4 100644 --- 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 index 0000000..9556322 --- /dev/null +++ b/make-news.py @@ -0,0 +1,33 @@ +#! /usr/local/bin/python -O + +__version__ = "$Revision$"[11:-2] +__revision__ = "$Id$"[5:-2] +__date__ = "$Date$"[7:-2] +__author__ = "Oleg BroytMann " +__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(""" +

+

+

+#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 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 " +__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 index 0000000..bd1b90f --- /dev/null +++ b/news.tmpl-en @@ -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 +

Most recently changed files

diff --git a/news.tmpl-ru b/news.tmpl-ru new file mode 100644 index 0000000..e98f72e --- /dev/null +++ b/news.tmpl-ru @@ -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 +

ðÏÓÌÅÄÎÉÅ ÉÚÍÅΣÎÎÙÅ ÆÁÊÌÙ

diff --git a/reindex_blog.py b/reindex_blog.py index 45faac2..cd6906c 100755 --- a/reindex_blog.py +++ b/reindex_blog.py @@ -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): -- 2.39.5