3 __version__ = "$Revision$"[11:-2]
4 __revision__ = "$Id$"[5:-2]
5 __date__ = "$Date$"[7:-2]
6 __author__ = "Oleg Broytman <phd@phd.pp.ru>"
7 __copyright__ = "Copyright (C) 2004-2009 PhiloSoft Design"
10 import os, shutil, filecmp
11 os.umask(0022) # octal; -rw-r--r--
13 from m_lib.m_path import get_homedir
14 home_dir = get_homedir()
17 def add_headers(fname, prev, next):
18 head_fname = os.path.join(home_dir, fname + ".head")
19 head_file = open(head_fname, 'r')
20 head = head_file.read()
23 html_fname = fname + ".html"
24 html_file = open(html_fname, 'r')
25 html = html_file.read()
28 if fname in ("init.py", "pdbrc.py"):
30 txt_name = fname + '.txt'
32 dot_name = '.' + fname
35 html_file = open(html_fname, 'w')
36 html_file.write("#extends phd_pp_ru\n")
37 html_file.write("#implements respond\n")
38 html_file.write("#attr $Title = \"%s\"\n" % dot_name)
39 html_file.write("#attr $Copyright = 2003\n")
41 html_file.write("#attr $Prev = \"%s.html\"\n" % prev)
43 html_file.write("#attr $Next = \"%s.html\"\n" % next)
44 html_file.write('#attr $alternates = (("text/plain", "Plain text version", "%s"),)' % txt_name)
46 html_file.write("#def body_html\n")
47 html_file.write("#raw\n")
51 html_file.write("#end raw\n")
52 html_file.write("#end def\n")
53 html_file.write("$phd_pp_ru.respond(self)\n")
57 file_types = (("fvwm2rc", "fvwm2m4"),
58 ("mailcap", "conf"), ("mime.types", "conf"),
59 ("muttrc", "muttrc"), ("procmailrc", "procmail"),
60 ("vimrc", "vim"), ("gvimrc", "vim"),
61 ("init.py", "python"), ("pdbrc", "python"), ("pdbrc.py", "python"))
62 ft_len = len(file_types)
64 for i, (fname, ftype) in enumerate(file_types):
65 if os.path.exists('.' + fname) and not os.path.exists(fname):
66 shutil.copy2('.' + fname, fname)
67 if fname == 'vimrc' and os.path.exists(fname):
68 file = open('vimrc', 'r')
71 file = open('vimrc', 'w')
72 file.write(text.replace('
\e', '<Esc>'))
74 if not os.path.exists(fname):
76 os.system("""exec gvim -f -c "set filetype=%s" -c ":source %s/dotfile2html.vim" "%s"
77 """ % (ftype, home_dir, fname))
81 prev = file_types[i-1][0]
85 next = file_types[i+1][0]
86 add_headers(fname, prev, next)
87 if os.path.exists(fname + ".tmpl") and filecmp.cmp(fname + ".html", fname + ".tmpl"):
88 os.remove(fname + ".html")
90 os.rename(fname + ".html", fname + ".tmpl")
91 if fname == 'vimrc' and os.path.exists('.' + fname):
92 shutil.copy2('.' + fname, fname)
93 if fname.endswith('.py'):
94 new_name = fname + '.txt'
95 os.rename(fname, new_name)
97 if os.path.exists(fname):