From d0c12fe18714b7a8c797ade7864f6f7a4ec902ef Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sat, 25 Feb 2006 13:06:00 +0000 Subject: [PATCH] Added keywords. Made write_template() to test if the template was changed. git-svn-id: file:///home/phd/archive/SVN/phdru.name/scripts@3 7bb0bf08-9e0d-0410-b083-99cee3bf18b8 --- reindex_blog.py | 62 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/reindex_blog.py b/reindex_blog.py index be27835..43c4f8b 100755 --- a/reindex_blog.py +++ b/reindex_blog.py @@ -1,6 +1,12 @@ #! /usr/local/bin/python -O # -*- coding: koi8-r -*- +__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 glob import glob @@ -77,10 +83,21 @@ months_names_ru0 = ['', " ] -def write_template(show_year, show_month, year, month, titles, cut=None, show_years=False): - index_tmpl = open(os.path.join(year, month, "index.tmpl"), 'w') +def write_template(year, month, titles): + index_name = os.path.join(year, month, "index.tmpl") + try: + index_tmpl = open(index_name, 'r') + old_text = index_tmpl.read() + index_tmpl.close() + except IOError: + old_text = None + + new_text = [] + show_year = not year + show_month = not month + if show_year: - index_tmpl.write("""\ + new_text.append("""\ #extends phd_pp_ru #implements respond #attr $Title = "Oleg BroytMann's blog" @@ -93,7 +110,7 @@ def write_template(show_year, show_month, year, month, titles, cut=None, show_ye elif show_month: - index_tmpl.write("""\ + new_text.append("""\ #extends phd_pp_ru #implements respond #attr $Title = "Oleg BroytMann's blog: %(year)s" @@ -107,7 +124,7 @@ def write_template(show_year, show_month, year, month, titles, cut=None, show_ye else: month = int(month) - index_tmpl.write("""\ + new_text.append("""\ #extends phd_pp_ru #implements respond #attr $Title = "Oleg BroytMann's blog: %(month_abbr_en)s %(year)s" @@ -124,8 +141,6 @@ def write_template(show_year, show_month, year, month, titles, cut=None, show_ye save_titles = titles[:] titles.reverse() - if cut: - titles = titles[:cut] save_day = None for key, tmpl, title, lead in titles: @@ -141,27 +156,27 @@ def write_template(show_year, show_month, year, month, titles, cut=None, show_ye if day[0] == '0': day = day[1:] if save_day <> day: if show_year: - index_tmpl.write('\n

%s %s %s

' % (day, months_names_ru[int(month)], year)) + new_text.append('\n

%s %s %s

' % (day, months_names_ru[int(month)], year)) else: - index_tmpl.write('\n

%s %s

' % (day, months_names_ru[int(month)])) + new_text.append('\n

%s %s

' % (day, months_names_ru[int(month)])) save_day = day if lead: lead = lead + ' ' else: lead = '' - index_tmpl.write(''' + new_text.append('''

%s%s.

''' % (lead, href, title)) - if show_years: + if show_year: years = {} for key, tmpl, title, lead in save_titles: year, month, day = key years[year] = True first_year = True - index_tmpl.write(''' + new_text.append('''

@@ -170,17 +185,23 @@ def write_template(show_year, show_month, year, month, titles, cut=None, show_ye if first_year: first_year = False else: - index_tmpl.write(' - ') - index_tmpl.write('%s' % (year, year)) - index_tmpl.write(''' + new_text.append(' - ') + new_text.append('%s' % (year, year)) + new_text.append('''

''') - index_tmpl.write("""\ + new_text.append("""\ #end def $phd_pp_ru.respond(self) """) - index_tmpl.close() + + new_text = ''.join(new_text) + if old_text <> new_text: + print "Writing", index_name + index_tmpl = open(index_name, 'w') + index_tmpl.write(new_test) + index_tmpl.close() def translate(tmpl): @@ -193,6 +214,7 @@ all_titles = [] for key in sorted(blog.keys()): title, tmpl, lead = blog[key] all_titles.append((key, translate(tmpl), title, lead)) +all_titles = all_titles[-20:] for year in sorted(years.keys()): year_titles = [] @@ -207,6 +229,6 @@ for year in sorted(years.keys()): tmpl = translate(tmpl) year_titles.append((key, tmpl, title, lead)) month_titles.append((key, tmpl, title, lead)) - write_template(False, False, year, month, month_titles) - write_template(False, True, year, '', year_titles) -write_template(True, True, '', '', all_titles, 5, True) + write_template(year, month, month_titles) + write_template(year, '', year_titles) +write_template('', '', all_titles) -- 2.39.5