From 6aa7ab00b5dc30b6221d0d55fecc1b0b957cdd79 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sat, 25 Feb 2006 12:58:59 +0000 Subject: [PATCH] Scripts to (re)build phd.pp.ru site. git-svn-id: file:///home/phd/archive/SVN/phdru.name/scripts@1 7bb0bf08-9e0d-0410-b083-99cee3bf18b8 --- dotfiles2html/dotfile2html.vim | 15 ++ dotfiles2html/dotfiles2html.py | 65 +++++++++ dotfiles2html/fvwm2rc.head | 8 + dotfiles2html/gvimrc.head | 10 ++ dotfiles2html/init.py.head | 18 +++ dotfiles2html/init_old.py.head | 17 +++ dotfiles2html/mailcap.head | 7 + dotfiles2html/mime.types.head | 8 + dotfiles2html/muttrc.head | 8 + dotfiles2html/procmailrc.head | 8 + dotfiles2html/vimrc.head | 10 ++ make+update | 2 + make-all | 4 + make-changed | 4 + make-changed.py | 22 +++ make-files | 11 ++ make-index | 2 + make-new | 4 + phd_pp.py | 86 +++++++++++ phd_pp_ru.py | 260 +++++++++++++++++++++++++++++++++ phd_pp_ru.tmpl | 81 ++++++++++ reindex_blog.py | 212 +++++++++++++++++++++++++++ reindex_blog_ru | 7 + update-ALL | 3 + update-all | 2 + 25 files changed, 874 insertions(+) create mode 100644 dotfiles2html/dotfile2html.vim create mode 100755 dotfiles2html/dotfiles2html.py create mode 100644 dotfiles2html/fvwm2rc.head create mode 100644 dotfiles2html/gvimrc.head create mode 100644 dotfiles2html/init.py.head create mode 100644 dotfiles2html/init_old.py.head create mode 100644 dotfiles2html/mailcap.head create mode 100644 dotfiles2html/mime.types.head create mode 100644 dotfiles2html/muttrc.head create mode 100644 dotfiles2html/procmailrc.head create mode 100644 dotfiles2html/vimrc.head create mode 100755 make+update create mode 100755 make-all create mode 100755 make-changed create mode 100755 make-changed.py create mode 100755 make-files create mode 100755 make-index create mode 100755 make-new create mode 100644 phd_pp.py create mode 100644 phd_pp_ru.py create mode 100644 phd_pp_ru.tmpl create mode 100755 reindex_blog.py create mode 100755 reindex_blog_ru create mode 100755 update-ALL create mode 100755 update-all diff --git a/dotfiles2html/dotfile2html.vim b/dotfiles2html/dotfile2html.vim new file mode 100644 index 0000000..20795ed --- /dev/null +++ b/dotfiles2html/dotfile2html.vim @@ -0,0 +1,15 @@ +" Convert the file to HTML +highlight Constant gui=NONE guifg=NONE guibg=NONE +highlight Special gui=NONE guibg=NONE +highlight Normal gui=NONE guifg=NONE guibg=NONE +highlight Error gui=NONE guifg=NONE guibg=NONE +runtime syntax/2html.vim + +normal 1G +1,/^$/d + +normal Gk +normal 2dd + +write +quitall diff --git a/dotfiles2html/dotfiles2html.py b/dotfiles2html/dotfiles2html.py new file mode 100755 index 0000000..f13e4dc --- /dev/null +++ b/dotfiles2html/dotfiles2html.py @@ -0,0 +1,65 @@ +#! /usr/local/bin/python -O + +import os, shutil +os.umask(0022) # octal; -rw-r--r-- + +from m_lib.m_path import get_homedir +home_dir = get_homedir() + + +def add_headers(fname, prev, next): + head_fname = os.path.join(home_dir, fname + ".head") + head_file = open(head_fname, 'r') + head = head_file.read() + head_file.close() + + html_fname = fname + ".html" + html_file = open(html_fname, 'r') + html = html_file.read() + html_file.close() + + html_file = open(html_fname, 'w') + html_file.write("#extends phd_pp_ru\n") + html_file.write("#implements respond\n") + html_file.write("#attr $Title = \".%s\"\n" % fname) + html_file.write("#attr $Copyright = 2003\n") + if prev: + html_file.write("#attr $Prev = \"%s.html\"\n" % prev) + if next: + html_file.write("#attr $Next = \"%s.html\"\n" % next) + html_file.write("\n") + html_file.write("#def body_html\n") + html_file.write("#raw\n") + html_file.write(head) + html_file.write("\n") + html_file.write(html) + html_file.write("#end raw\n") + html_file.write("#end def\n") + html_file.write("$phd_pp_ru.respond(self)\n") + html_file.close() + + +file_types = (("fvwm2rc", "fvwm"), + ("mailcap", "conf"), ("mime.types", "conf"), + ("muttrc", "muttrc"), ("procmailrc", "procmail"), + ("vimrc", "vim"), ("gvimrc", "vim"), + ("init.py", "python"), ("init_old.py", "python")) +ft_len = len(file_types) + +for i, (fname, ftype) in enumerate(file_types): + if os.path.exists('.' + fname) and not os.path.exists(fname): + shutil.copy2('.' + fname, fname) + if os.path.exists(fname): + os.system("""exec gvim -f -c "set syntax=%s" -c ":source %s/dotfile2html.vim" "%s" + """ % (ftype, home_dir, fname)) + if i == 0: + prev = None + else: + prev = file_types[i-1][0] + if i >= ft_len - 1: + next = None + else: + next = file_types[i+1][0] + add_headers(fname, prev, next) + os.rename(fname + ".html", fname + ".tmpl") + os.chmod(fname, 0644) diff --git a/dotfiles2html/fvwm2rc.head b/dotfiles2html/fvwm2rc.head new file mode 100644 index 0000000..6229d05 --- /dev/null +++ b/dotfiles2html/fvwm2rc.head @@ -0,0 +1,8 @@ +
+#
+# User configuration file for Fvwm2
+#
+# Text version here
+#
+# Generated by gvim :runtime syntax/2html.vim
+#
diff --git a/dotfiles2html/gvimrc.head b/dotfiles2html/gvimrc.head
new file mode 100644
index 0000000..e89c7bf
--- /dev/null
+++ b/dotfiles2html/gvimrc.head
@@ -0,0 +1,10 @@
+
+"
+" User configuration file for Vi IMproved (GUI version)
+"
+" It is sourced after .vimrc
+"
+" Text version here
+"
+" Generated by gvim :runtime syntax/2html.vim
+"
diff --git a/dotfiles2html/init.py.head b/dotfiles2html/init.py.head
new file mode 100644
index 0000000..7379fa7
--- /dev/null
+++ b/dotfiles2html/init.py.head
@@ -0,0 +1,18 @@
+
+# This is startup file for interactive python.
+# It is not automatically loaded by python interpreter.
+# To instruct the interpreter to load it insert the following commands
+# into your .profile (use whatever syntax and initialization file
+# is appropriate for your shell):
+#
+# PYTHONSTARTUP=$HOME/init.py # or where you have really put it
+# export PYTHONSTARTUP
+#
+# Due to nested_scopes and pydoc.help(*args, **kwds) this file only works with
+# Python 2.1 or higher. For Python 1.5.2 and 2.0 use init_old.py.
+#
+# Text version here
+#
+# Generated by gvim :runtime syntax/2html.vim
+#
+
diff --git a/dotfiles2html/init_old.py.head b/dotfiles2html/init_old.py.head
new file mode 100644
index 0000000..6096e17
--- /dev/null
+++ b/dotfiles2html/init_old.py.head
@@ -0,0 +1,17 @@
+
+# This is startup file for interactive python.
+# It is not automatically loaded by python interpreter.
+# To instruct the interpreter to load it insert the following commands
+# into your .profile (use whatever syntax and initialization file
+# is appropriate for your shell):
+#
+# PYTHONSTARTUP=$HOME/init_old.py # or where you have really put it
+# export PYTHONSTARTUP
+#
+# This is special version for Python 1.5.2 and Python 2.0.
+#
+# Text version here
+#
+# Generated by gvim :runtime syntax/2html.vim
+#
+
diff --git a/dotfiles2html/mailcap.head b/dotfiles2html/mailcap.head
new file mode 100644
index 0000000..640fab1
--- /dev/null
+++ b/dotfiles2html/mailcap.head
@@ -0,0 +1,7 @@
+
+# MIME types -> viewers map.
+#
+# Text version here
+#
+# Generated by gvim :runtime syntax/2html.vim
+#
diff --git a/dotfiles2html/mime.types.head b/dotfiles2html/mime.types.head
new file mode 100644
index 0000000..585ea25
--- /dev/null
+++ b/dotfiles2html/mime.types.head
@@ -0,0 +1,8 @@
+
+# File extension -> MIME type map.
+# MIME type                                        Extension
+#
+# Text version here
+#
+# Generated by gvim :runtime syntax/2html.vim
+#
diff --git a/dotfiles2html/muttrc.head b/dotfiles2html/muttrc.head
new file mode 100644
index 0000000..e81b8c8
--- /dev/null
+++ b/dotfiles2html/muttrc.head
@@ -0,0 +1,8 @@
+
+#
+# User configuration file for Mutt
+#
+# Text version here
+#
+# Generated by gvim :runtime syntax/2html.vim
+#
diff --git a/dotfiles2html/procmailrc.head b/dotfiles2html/procmailrc.head
new file mode 100644
index 0000000..e1b96b6
--- /dev/null
+++ b/dotfiles2html/procmailrc.head
@@ -0,0 +1,8 @@
+
+#
+# User configuration file for Procmail
+#
+# Text version here
+#
+# Generated by gvim :runtime syntax/2html.vim
+#
diff --git a/dotfiles2html/vimrc.head b/dotfiles2html/vimrc.head
new file mode 100644
index 0000000..4114047
--- /dev/null
+++ b/dotfiles2html/vimrc.head
@@ -0,0 +1,10 @@
+
+"
+" User configuration file for Vi IMproved
+"
+" Text version here
+"
+" Generated by gvim :runtime syntax/2html.vim
+"
+" A number of scripts mentioned in the file are available here.
+"
diff --git a/make+update b/make+update
new file mode 100755
index 0000000..52021ed
--- /dev/null
+++ b/make+update
@@ -0,0 +1,2 @@
+#! /bin/sh
+./make-changed && exec ./update-all
diff --git a/make-all b/make-all
new file mode 100755
index 0000000..7bc7b88
--- /dev/null
+++ b/make-all
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+find ../htdocs/phd.pp.ru -type f -name \*.tmpl -print0 | \
+   xargs -r0 ./make-files
diff --git a/make-changed b/make-changed
new file mode 100755
index 0000000..a6c1b13
--- /dev/null
+++ b/make-changed
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+find ../htdocs/phd.pp.ru -type f -name \*.tmpl -print | \
+   ./make-changed.py | xargs -r ./make-files
diff --git a/make-changed.py b/make-changed.py
new file mode 100755
index 0000000..86a251b
--- /dev/null
+++ b/make-changed.py
@@ -0,0 +1,22 @@
+#! /usr/local/bin/python -O
+
+import sys, os
+
+main_tmpl_mtime = os.path.getmtime("phd_pp_ru.tmpl")
+main_prog_mtime = os.path.getmtime("phd_pp.py")
+
+for line in sys.stdin:
+   line = line.strip()
+   src_mtime = os.path.getmtime(line)
+
+   dest = line.replace(".tmpl", ".html")
+   try:
+      dest_mtime = os.path.getmtime(dest)
+   except OSError:
+      make = True
+   else:
+      make = (src_mtime > dest_mtime) or \
+         (main_tmpl_mtime > dest_mtime) or (main_prog_mtime > dest_mtime)
+
+   if make:
+      print line
diff --git a/make-files b/make-files
new file mode 100755
index 0000000..43b9c01
--- /dev/null
+++ b/make-files
@@ -0,0 +1,11 @@
+#! /bin/sh
+
+umask 022
+PYTHONPATH=.
+export PYTHONPATH
+
+if [ phd_pp_ru.tmpl -nt phd_pp_ru.py ]; then
+   cheetah compile --nobackup phd_pp_ru.tmpl
+fi
+
+exec cheetah fill --nobackup "$@"
diff --git a/make-index b/make-index
new file mode 100755
index 0000000..be9b6ab
--- /dev/null
+++ b/make-index
@@ -0,0 +1,2 @@
+#! /bin/sh
+exec ./make-files ./files/index.tmpl
diff --git a/make-new b/make-new
new file mode 100755
index 0000000..f3c359b
--- /dev/null
+++ b/make-new
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+find ../htdocs/phd.pp.ru -type f -name \*.tmpl -mtime -1 -print0 | \
+   xargs -r0 ./make-files
diff --git a/phd_pp.py b/phd_pp.py
new file mode 100644
index 0000000..08b6bf6
--- /dev/null
+++ b/phd_pp.py
@@ -0,0 +1,86 @@
+import os, re, time
+from Cheetah.Template import Template
+
+
+# Copied from ZWiki
+
+urlchars         = r'[A-Za-z0-9/:@_%~#=&\.\-\?\+\$,]+'
+urlendchar       = r'[A-Za-z0-9/]'
+url              = r'["=]?((about|gopher|http|https|ftp|mailto|file):%s)' % \
+                   (urlchars+urlendchar)
+
+def _url2href(match):
+   url = match.group(0)
+   return '%s' % (url, url)
+
+
+full_dirs = len(os.getcwd().split('/')) + 1
+
+class phd_pp(Template):
+   def __init__(self, *args, **kw):
+      Template.__init__(self, *args, **kw)
+      directories = self._fileDirName.split('/')[full_dirs:] # remove directories up to "./files"
+      dirs_to_root = len(directories)
+      if dirs_to_root:
+         root = "../"*dirs_to_root
+      else:
+         root = ''
+      self.root = root
+      path = '/'.join(directories) + '/' + \
+         self._fileBaseName.replace(".tmpl", ".html")
+      if path[0] <> '/': path = '/' + path
+      self.path = path
+
+   def copyright(self, start_year):
+      this_year = time.localtime()[0]
+      if start_year >= this_year:
+         return this_year
+      if start_year == this_year - 1:
+         return "%s, %s" % (start_year, this_year)
+      return "%s-%s" % (start_year, this_year)
+
+   def body(self):
+      if hasattr(self, "body_html"):
+         return self.body_html()
+      if hasattr(self, "body_text"):
+         return self.text2html()
+      if hasattr(self, "body_rst"):
+         return self.rst2html()
+
+   def text2html(self):
+      body = re.sub(url, _url2href, self.body_text())
+
+      paragraphs = body.split("\n\n")
+
+      new_paras = []
+      for p in paragraphs:
+         parts = p.split("\n   ")
+         parts[0] = parts[0].strip()
+         new_paras.append('\n

\n

\n'.join(parts)) + + if self.Title: + title = "

%s

\n\n" % self.Title + else: + title = '' + + body = '\n

\n\n

\n'.join(new_paras) + return "%s

%s

" % (title, body) + + def rst2html(self): + from docutils.core import publish_parts + from locale import getpreferredencoding + encoding = getpreferredencoding() + + parts = publish_parts(self.body_rst(), writer_name="html") + + title = parts["title"].encode(encoding) or self.Title + if title: + title = "

%s

" % title + + subtitle = parts["subtitle"].encode(encoding) + if subtitle: + subtitle = "

%s

" % subtitle + + body = parts["body"].encode(encoding) + parts = [part for part in (title, subtitle, body) if part] + return "\n\n".join(parts) diff --git a/phd_pp_ru.py b/phd_pp_ru.py new file mode 100644 index 0000000..d569873 --- /dev/null +++ b/phd_pp_ru.py @@ -0,0 +1,260 @@ +#!/usr/bin/env python +# -*- coding: koi8-r -*- + +""" +Autogenerated by CHEETAH: The Python-Powered Template Engine + CHEETAH VERSION: 1.0 + Generation time: Mon Jan 2 23:48:51 2006 + Source file: phd_pp_ru.tmpl + Source file last modified: Mon Jan 2 23:48:44 2006 +""" + +__CHEETAH_genTime__ = 'Mon Jan 2 23:48:51 2006' +__CHEETAH_src__ = 'phd_pp_ru.tmpl' +__CHEETAH_version__ = '1.0' + +################################################## +## DEPENDENCIES + +import sys +import os +import os.path +from os.path import getmtime, exists +import time +import types +import __builtin__ +from Cheetah.Template import Template +from Cheetah.DummyTransaction import DummyTransaction +from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList +from Cheetah.CacheRegion import CacheRegion +import Cheetah.Filters as Filters +import Cheetah.ErrorCatchers as ErrorCatchers +from phd_pp import phd_pp +import time + +################################################## +## MODULE CONSTANTS + +try: + True, False +except NameError: + True, False = (1==1), (1==0) +VFFSL=valueFromFrameOrSearchList +VFSL=valueFromSearchList +VFN=valueForName +currentTime=time.time + +################################################## +## CLASSES + +class phd_pp_ru(phd_pp): + """ + + Autogenerated by CHEETAH: The Python-Powered Template Engine + """ + + ################################################## + ## GENERATED METHODS + + + def __init__(self, *args, **KWs): + """ + + """ + + phd_pp.__init__(self, *args, **KWs) + + def respond(self, + trans=None, + VFFSL=valueFromFrameOrSearchList, + VFN=valueForName): + + + """ + This is the main method generated by Cheetah + """ + + if not trans: trans = self.transaction # is None unless self.awake() was called + if not trans: + trans = DummyTransaction() + dummyTrans = True + else: dummyTrans = False + write = trans.response().write + SL = self._searchList + globalSetVars = self._globalSetVars + filter = self._currentFilter + + ######################################## + ## START - generated method body + + write(''' + + + + +\n\n') + __v = VFFSL(SL,"Title",True) + if __v is not None: write(filter(__v, rawExpr='$Title')) # from line 23, col 8. + write('\n') + if VFFSL(SL,"refresh",True): + write('\n') + if VFFSL(SL,"Description",True): + write('\n') + if VFFSL(SL,"Keywords",True): + write('\n') + if VFFSL(SL,"Copyright",True): + full_copyright = VFFSL(SL,"copyright",False)(VFFSL(SL,"Copyright",True)) + write('\n\n\n') + write('\n\n') + if VFFSL(SL,"root",True): + write('\n\n') + if VFFSL(SL,"Prev",True): + write('\n') + if VFFSL(SL,"Next",True): + write('\n') + write('\n') + if VFFSL(SL,"styles",True): + for media, style in VFFSL(SL,"styles",True): + write('\n') + write(''' + + +''') + __v = VFFSL(SL,"body",True) + if __v is not None: write(filter(__v, rawExpr='$body')) # from line 64, col 1. + write('\n') + if VFN(VFFSL(SL,"path",True),"endswith",False)("index.html"): + path = VFFSL(SL,"path",True)[:-len("index.html")] + write('
\n') + if VFN(VFFSL(SL,"path",True),"startswith",False)("/Russian/"): + write('

\xfc\xd4\xc1 \xd3\xd4\xd2\xc1\xce\xc9\xc3\xc1 http://phd.pp.ru') + __v = VFFSL(SL,"path",True) + if __v is not None: write(filter(__v, rawExpr='$path')) # from line 70, col 101. + write('\n\xc2\xd9\xcc\xc1 \xd3\xc7\xc5\xce\xc5\xd2\xc9\xd2\xcf\xd7\xc1\xce\xc1 ') + __v = VFFSL(SL,"last_modified_ru",True) + if __v is not None: write(filter(__v, rawExpr='$last_modified_ru')) # from line 71, col 20. + write(' \xc9\xda \xdb\xc1\xc2\xcc\xcf\xce\xc1 CheetahTemplate ') + __v = VFFSL(SL,"_fileBaseName",True) + if __v is not None: write(filter(__v, rawExpr='$_fileBaseName')) # from line 71, col 90. + write(';\n\xf7\xd9 \xcd\xcf\xd6\xc5\xd4\xc5 \xd5\xda\xce\xc1\xd4\xd8 \xcf \xd4\xc5\xc8\xce\xc9\xde\xc5\xd3\xcb\xc9\xc8 \xc1\xd3\xd0\xc5\xcb\xd4\xc1\xc8 \xdc\xd4\xcf\xc7\xcf \xd3\xc1\xca\xd4\xc1.\n

\n') + else: + write('

This is the page http://phd.pp.ru') + __v = VFFSL(SL,"path",True) + if __v is not None: write(filter(__v, rawExpr='$path')) # from line 75, col 105. + write('.\nIt was generated on ') + __v = VFFSL(SL,"last_modified_en",True) + if __v is not None: write(filter(__v, rawExpr='$last_modified_en')) # from line 76, col 21. + write(' from CheetahTemplate ') + __v = VFFSL(SL,"_fileBaseName",True) + if __v is not None: write(filter(__v, rawExpr='$_fileBaseName')) # from line 76, col 85. + write(';\nread more about technical aspects of the site.\n

\n') + write('\n') + + ######################################## + ## END - generated method body + + return dummyTrans and trans.response().getvalue() or "" + + ################################################## + ## GENERATED ATTRIBUTES + + + Title = '' + + Description = None + + Keywords = None + + Copyright = None + + Prev = None + + Next = None + + refresh = None + + last_modified_en = time.strftime("%a, %d %b %Y %T GMT", time.gmtime()) + + last_modified_ru = time.strftime("%d.%m.%Y × %T", time.localtime()) + + styles = None + + __str__ = respond + + _mainCheetahMethod_for_phd_pp_ru= 'respond' + + +# CHEETAH was developed by Tavis Rudd, Mike Orr, Ian Bicking and Chuck Esterbrook; +# with code, advice and input from many other volunteers. +# For more information visit http://www.CheetahTemplate.org + +################################################## +## if run from command line: +if __name__ == '__main__': + phd_pp_ru().runAsMainProgram() + diff --git a/phd_pp_ru.tmpl b/phd_pp_ru.tmpl new file mode 100644 index 0000000..a488704 --- /dev/null +++ b/phd_pp_ru.tmpl @@ -0,0 +1,81 @@ +#encoding koi8-r +#extends phd_pp +#implements respond +#attr $Title = '' +#attr $Description = None +#attr $Keywords = None +#attr $Copyright = None +#attr $Prev = None +#attr $Next = None +#attr $refresh = None +#import time +#attr $last_modified_en = time.strftime("%a, %d %b %Y %T GMT", time.gmtime()) +#attr $last_modified_ru = time.strftime("%d.%m.%Y × %T", time.localtime()) +#attr $styles = None + + + + + + + +$Title +#if $refresh: + +#end if +#if $Description + +#end if +#if $Keywords + +#end if +#if $Copyright +#set $full_copyright = $copyright($Copyright) + + + +#end if + + +#if $root + + +#end if +#if $Prev + +#end if +#if $Next + +#end if + +#if $styles +#for $media, $style in $styles + +#end for +#end if + + + +$body +#if $path.endswith("index.html") +#set $path = $path[:-len("index.html")] +#end if +
+#if $path.startswith("/Russian/") +

üÔÁ ÓÔÒÁÎÉÃÁ http://phd.pp.ru$path +ÂÙÌÁ ÓÇÅÎÅÒÉÒÏ×ÁÎÁ $last_modified_ru ÉÚ ÛÁÂÌÏÎÁ CheetahTemplate $_fileBaseName; +÷Ù ÍÏÖÅÔÅ ÕÚÎÁÔØ Ï ÔÅÈÎÉÞÅÓËÉÈ ÁÓÐÅËÔÁÈ ÜÔÏÇÏ ÓÁÊÔÁ. +

+#else +

This is the page http://phd.pp.ru$path. +It was generated on $last_modified_en from CheetahTemplate $_fileBaseName; +read more about technical aspects of the site. +

+#end if + +#slurp diff --git a/reindex_blog.py b/reindex_blog.py new file mode 100755 index 0000000..be27835 --- /dev/null +++ b/reindex_blog.py @@ -0,0 +1,212 @@ +#! /usr/local/bin/python -O +# -*- coding: koi8-r -*- + +import sys, os +from glob import glob + +try: + import cPickle as pickle +except ImportError: + import pickle + +from Cheetah.Template import Template + +blog_filename = sys.argv[1] +try: + blog_file = open(blog_filename, "rb") +except IOError: + blog = {} +else: + blog = pickle.load(blog_file) + blog_file.close() + +years = {} +months = sys.argv[2:] +isdir = os.path.isdir + +if not months: + for year in os.listdir(os.curdir): + if isdir(year): + years[year] = {} + for month in os.listdir(year): + m = os.path.join(year, month) + if isdir(m): + months.append(m) + +days = [] +for month in months: + year, m = month.split(os.sep) + if month not in years: + years[year] = {} + years[year][m] = days_of_month = [] + for day in os.listdir(month): + d = os.path.join(month, day) + if isdir(d): + days.append(d) + days_of_month.append(d) + +for day in days: + for tmpl in glob(os.path.join(day, "*.tmpl")): + template = Template(file=tmpl) + title_parts = template.Title.split() + title = ' '.join(title_parts[6:]) + lead = getattr(template, "Lead", None) + + if title: + day_parts = day.split(os.sep) + blog[tuple(day_parts)] = (title, os.path.basename(tmpl), lead) + +blog_file = open(blog_filename, "wb") +pickle.dump(blog, blog_file, pickle.HIGHEST_PROTOCOL) +blog_file.close() + + +import locale +locale.setlocale(locale.LC_ALL, '') +from calendar import _localized_day, _localized_month + +locale.setlocale(locale.LC_TIME, 'C') +months_names_en = list(_localized_month('%B')) +months_abbrs_en = list(_localized_month('%b')) + +locale.setlocale(locale.LC_TIME, '') +months_names_ru = [month.lower() for month in _localized_month('%B')] + +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') + if show_year: + index_tmpl.write("""\ +#extends phd_pp_ru +#implements respond +#attr $Title = "Oleg BroytMann's blog" +#attr $Description = "BroytMann Russian Blog Index Document" +#attr $Copyright = %(cyear)s +## +#def body_html +

öÕÒÎÁÌ

+""" % {"cyear": year or 2005}) + + elif show_month: + + index_tmpl.write("""\ +#extends phd_pp_ru +#implements respond +#attr $Title = "Oleg BroytMann's blog: %(year)s" +#attr $Description = "BroytMann Russian Blog %(year)s Index Document" +#attr $Copyright = %(cyear)s +## +#def body_html +

öÕÒÎÁÌ: %(year)s

+""" % {"year": year, "cyear": year or 2005}) + + else: + + month = int(month) + index_tmpl.write("""\ +#extends phd_pp_ru +#implements respond +#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" +#attr $Copyright = %(cyear)s +## +#def body_html +

öÕÒÎÁÌ: %(month_name_ru0)s %(year)s

+""" % { + "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], + }) + + save_titles = titles[:] + titles.reverse() + if cut: + titles = titles[:cut] + + save_day = None + for key, tmpl, title, lead in titles: + year, month, day = key + href = [] + if show_year: + href.append(year) + if show_month: + href.append(month) + href.append(day) + href.append(tmpl) + href = '/'.join(href) + 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)) + else: + index_tmpl.write('\n

%s %s

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

+ %s%s. +

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

+''') + for year in sorted(years.keys()): + if first_year: + first_year = False + else: + index_tmpl.write(' - ') + index_tmpl.write('%s' % (year, year)) + index_tmpl.write(''' +

+''') + + index_tmpl.write("""\ +#end def +$phd_pp_ru.respond(self) +""") + index_tmpl.close() + + +def translate(tmpl): + if tmpl == "index.tmpl": tmpl = '' + if tmpl.endswith(".tmpl"): tmpl = tmpl[:-len("tmpl")] + "html" + return tmpl + + +all_titles = [] +for key in sorted(blog.keys()): + title, tmpl, lead = blog[key] + all_titles.append((key, translate(tmpl), title, lead)) + +for year in sorted(years.keys()): + year_titles = [] + months = years[year] + for month in sorted(months.keys()): + month_titles = [] + for day in sorted(months[month]): + day_parts = day.split(os.sep) + key = tuple(day_parts) + if key in blog: + title, tmpl, lead = blog[key] + 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) diff --git a/reindex_blog_ru b/reindex_blog_ru new file mode 100755 index 0000000..ced4032 --- /dev/null +++ b/reindex_blog_ru @@ -0,0 +1,7 @@ +#! /bin/sh + +LC_TIME=ru_RU.KOI8-R +export LC_TIME + +cd ../htdocs/phd.pp.ru/Russian/blog && \ +exec ../../../../phd.pp.ru/reindex_blog.py ../../../../phd.pp.ru/index_ru "$@" diff --git a/update-ALL b/update-ALL new file mode 100755 index 0000000..69ea955 --- /dev/null +++ b/update-ALL @@ -0,0 +1,3 @@ +#! /bin/sh +cd ../htdocs && distribute -d phd.pp.ru && ssh oper.med.ru bin/sc && \ +cd "$HOME" && rsync -avPz oper.med.ru:.sitecopy . && exec distribute .sitecopy diff --git a/update-all b/update-all new file mode 100755 index 0000000..4423f10 --- /dev/null +++ b/update-all @@ -0,0 +1,2 @@ +#! /bin/sh +cd ../htdocs && exec distribute -d phd.pp.ru -- 2.39.2