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"
9 import os, shutil, filecmp
10 os.umask(0022) # octal; -rw-r--r--
12 from m_lib.m_path import get_homedir
13 home_dir = get_homedir()
16 def add_headers(fname, prev, next):
17 head_fname = os.path.join(home_dir, fname + ".head")
18 head_file = open(head_fname, 'r')
19 head = head_file.read()
22 html_fname = fname + ".html"
23 html_file = open(html_fname, 'r')
24 html = html_file.read()
27 if fname in ("init.py", "pdbrc.py"):
29 txt_name = fname + '.txt'
31 dot_name = '.' + fname
34 html_file = open(html_fname, 'w')
35 html_file.write("#extends phd_pp_ru\n")
36 html_file.write("#implements respond\n")
37 html_file.write("#attr $Title = \"%s\"\n" % dot_name)
38 html_file.write("#attr $Copyright = 2003\n")
40 html_file.write("#attr $Prev = \"%s.html\"\n" % prev)
42 html_file.write("#attr $Next = \"%s.html\"\n" % next)
43 html_file.write('#attr $alternates = (("text/plain", "Plain text version", "%s"),)' % txt_name)
45 html_file.write("#def body_html\n")
46 html_file.write("#raw\n")
50 html_file.write("#end raw\n")
51 html_file.write("#end def\n")
52 html_file.write("$phd_pp_ru.respond(self)\n")
56 file_types = (("fvwm2rc", "fvwm2m4"),
57 ("mailcap", "conf"), ("mime.types", "conf"),
58 ("muttrc", "muttrc"), ("procmailrc", "procmail"),
59 ("vimrc", "vim"), ("gvimrc", "vim"),
60 ("init.py", "python"), ("pdbrc", "python"), ("pdbrc.py", "python"),
61 ("bindings", "conf"), ("menu", "conf"))
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)
68 if fname == 'vimrc' and os.path.exists(fname):
69 file = open('vimrc', 'r')
72 file = open('vimrc', 'w')
73 file.write(text.replace('
\e', '<Esc>'))
76 elif fname == 'menu' and os.path.exists(fname):
77 file = open('menu', 'r')
80 file = open('menu', 'w')
81 file.write(text.replace('mplay', 'mplayer'))
84 if not os.path.exists(fname):
87 os.system("""exec gvim -f -c "set filetype=%s" -c ":source %s/dotfile2html.vim" "%s"
88 """ % (ftype, home_dir, fname))
93 prev = file_types[i-1][0]
97 next = file_types[i+1][0]
98 add_headers(fname, prev, next)
100 if os.path.exists(fname + ".tmpl") and filecmp.cmp(fname + ".html", fname + ".tmpl"):
101 os.remove(fname + ".html")
103 os.rename(fname + ".html", fname + ".tmpl")
105 if fname == 'vimrc' and os.path.exists('.' + fname):
106 shutil.copy2('.' + fname, fname)
108 if fname.endswith('.py'):
109 new_name = fname + '.txt'
110 os.rename(fname, new_name)
113 if os.path.exists(fname):
114 os.chmod(fname, 0644)