#! /usr/local/bin/python -O
# -*- coding: koi8-r -*-
+__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 glob import glob
]
-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"
elif show_month:
- index_tmpl.write("""\
+ new_text.append("""\
#extends phd_pp_ru
#implements respond
#attr $Title = "Oleg BroytMann's blog: %(year)s"
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"
save_titles = titles[:]
titles.reverse()
- if cut:
- titles = titles[:cut]
save_day = None
for key, tmpl, title, lead in titles:
if day[0] == '0': day = day[1:]
if save_day <> day:
if show_year:
- index_tmpl.write('\n<h2>%s %s %s</h2>' % (day, months_names_ru[int(month)], year))
+ new_text.append('\n<h2>%s %s %s</h2>' % (day, months_names_ru[int(month)], year))
else:
- index_tmpl.write('\n<h2>%s %s</h2>' % (day, months_names_ru[int(month)]))
+ new_text.append('\n<h2>%s %s</h2>' % (day, months_names_ru[int(month)]))
save_day = day
if lead:
lead = lead + ' '
else:
lead = ''
- index_tmpl.write('''
+ new_text.append('''
<p class="head">
%s<a href="%s">%s</a>.
</p>
''' % (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('''
<hr>
<p class="years">
if first_year:
first_year = False
else:
- index_tmpl.write(' - ')
- index_tmpl.write('<a href="%s/">%s</a>' % (year, year))
- index_tmpl.write('''
+ new_text.append(' - ')
+ new_text.append('<a href="%s/">%s</a>' % (year, year))
+ new_text.append('''
</p>
''')
- 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):
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 = []
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)