]
-def write_template(year, month, day, titles):
- index_name = os.path.join(year, month, day, "index.tmpl")
+def write_template(level, year, month, day, titles):
+ path = []
+ if level >= 1:
+ path.append(year)
+ if level >= 2:
+ path.append(month)
+ if level == 3:
+ path.append(day)
+ path.append("index.tmpl")
+ index_name = os.path.join(*path)
try:
index_tmpl = open(index_name, 'r')
old_text = index_tmpl.read()
except IOError:
old_text = None
- new_text = []
- show_year = not year
- show_month = not month
- show_day = not day
-
- new_text.append("""\
+ new_text = ["""\
## THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
#extends phd_pp_ru
#implements respond
-""")
+"""]
- if show_year:
+ if level == 0:
new_text.append("""\
#attr $Title = "Oleg BroytMann's blog"
#attr $Description = "BroytMann Russian Blog Index Document"
<H1>Журнал</H1>
""" % {"cyear": year or 2005})
- elif show_month:
-
+ elif level == 1:
new_text.append("""\
#attr $Title = "Oleg BroytMann's blog: %(year)s"
#attr $Description = "BroytMann Russian Blog %(year)s Index Document"
<H1>Журнал: %(year)s</H1>
""" % {"year": year, "cyear": year or 2005})
- elif show_day:
-
- month = int(month)
+ elif level == 2:
+ imonth = int(month)
new_text.append("""\
#attr $Title = "Oleg BroytMann's blog: %(month_abbr_en)s %(year)s"
#attr $Description = "BroytMann Russian Blog %(month_name_en)s %(year)s Index Document"
<H1>Журнал: %(month_name_ru0)s %(year)s</H1>
""" % {
"year": year, "cyear": year or 2005,
- "month_abbr_en": months_abbrs_en[month], "month_name_en": months_names_en[month],
- "month_name_ru0": months_names_ru0[month],
+ "month_abbr_en": months_abbrs_en[imonth], "month_name_en": months_names_en[imonth],
+ "month_name_ru0": months_names_ru0[imonth],
})
- else:
-
- day = int(day)
- month = int(month)
+ elif level == 3:
+ iday = int(day)
+ imonth = int(month)
new_text.append("""\
#attr $Title = "Oleg BroytMann's blog: %(day)d %(month_abbr_en)s %(year)s"
<H1>Журнал: %(day)d %(month_name_ru0)s %(year)s</H1>
""" % {
"year": year, "cyear": year or 2005,
- "month_abbr_en": months_abbrs_en[month], "month_name_en": months_names_en[month],
- "month_name_ru0": months_names_ru0[month],
- "day": day
+ "month_abbr_en": months_abbrs_en[imonth], "month_name_en": months_names_en[imonth],
+ "month_name_ru0": months_names_ru0[imonth],
+ "day": iday
})
save_titles = titles[:]
titles.reverse()
save_day = None
- for key, tmpl, title, lead in titles:
- year, month, day = key
+ for year, month, day, filename, title, lead in titles:
href = []
- if show_year:
+ if level == 0:
href.append(year)
- if show_month:
+ if level <= 1:
href.append(month)
- if show_day:
+ if level <= 2:
href.append(day)
- href.append(tmpl)
+ href.append(filename)
href = '/'.join(href)
if day[0] == '0': day = day[1:]
if save_day <> day:
- if show_year:
+ if level == 0:
new_text.append('\n<h2>%s %s %s</h2>' % (day, months_names_ru[int(month)], year))
else:
new_text.append('\n<h2>%s %s</h2>' % (day, months_names_ru[int(month)]))
</p>
''' % (lead, href, title))
- if show_year:
+ if level == 0:
years = {}
- for key, tmpl, title, lead in save_titles:
- year, month, day = key
+ for year, month, day, filename, title, lead in save_titles:
years[year] = True
first_year = True
new_text.append('''
day_titles = []
key = year, month, day
if key in blog:
- for tmpl, title, lead in blog[key]:
- if tmpl.endswith(".tmpl"): tmpl = tmpl[:-len("tmpl")] + "html"
- all_titles.append((key, tmpl, title, lead))
- year_titles.append((key, tmpl, title, lead))
- month_titles.append((key, tmpl, title, lead))
- day_titles.append((key, tmpl, title, lead))
- write_template(year, month, day, day_titles)
- write_template(year, month, '', month_titles)
- write_template(year, '', '', year_titles)
-write_template('', '', '', all_titles[-20:])
+ for filename, title, lead in blog[key]:
+ if filename.endswith(".tmpl"):
+ filename = filename[:-len("tmpl")] + "html"
+ value = (year, month, day, filename, title, lead)
+ all_titles.append(value)
+ year_titles.append(value)
+ month_titles.append(value)
+ day_titles.append(value)
+ write_template(3, year, month, day, day_titles)
+ write_template(2, year, month, day, month_titles)
+ write_template(1, year, month, day, year_titles)
+write_template(0, year, month, day, all_titles[-20:])