3 __author__ = "Oleg Broytman <phd@phdru.name>"
4 __copyright__ = "Copyright (C) 2004-2016 PhiloSoft Design"
6 import os, shutil, filecmp
7 os.umask(0022) # octal; -rw-r--r--
9 from m_lib.m_path import get_homedir
10 home_dir = get_homedir()
13 def add_headers(fname, first, prev, next, last):
14 head_fname = os.path.join(home_dir, fname + ".head")
15 head_file = open(head_fname, 'r')
16 head = head_file.read()
19 html_fname = fname + ".html"
20 html_file = open(html_fname, 'r')
21 html = html_file.read()
24 if fname in ("init.py", "pdbrc.py"):
26 txt_name = fname + '.txt'
28 dot_name = '.' + fname
31 html_file = open(html_fname, 'w')
32 if fname in ("muttrc", "procmailrc", "vimrc"):
33 html_file.write("#encoding koi8-r\n")
34 html_file.write("#extends phd_site\n")
35 html_file.write("#implements respond\n")
36 html_file.write("#attr $Title = \"%s\"\n" % dot_name)
37 html_file.write("#attr $Copyright = 2003\n")
38 html_file.write("#attr $First = \"%s.html\"\n" % first)
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 $Last = \"%s.html\"\n" % last)
44 html_file.write('#attr $alternates = (("Plain text version", "text/plain", "%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_site.respond(self)\n")
57 home_file_types = (("bashrc", "sh"), ("profile", "sh"), ("shellrc", "sh"),
58 ("fvwm2rc", "fvwm2m4"), ("mailcap", "conf"), ("mime.types", "conf"),
59 ("muttrc", "muttrc"), ("procmailrc", "procmail"),
60 ("gitconfig", "gitconfig"), ("vimrc", "vim"))
62 mc_file_types = (("mc.ext", "conf"), ("menu", "conf"))
64 python_file_types = (("init.py", "python"),
65 ("pdbrc", "python"), ("pdbrc.py", "python"))
67 def process_dotfile(i, fname, ftype, file_types):
68 if os.path.exists('.' + fname) and not os.path.exists(fname):
69 shutil.copy2('.' + fname, fname)
71 if not os.path.exists(fname):
74 if fname == 'vimrc' and os.path.exists(fname):
75 file = open('vimrc', 'r')
78 file = open('vimrc', 'w')
79 file.write(text.replace('\033', '<Esc>'))
82 elif fname in ('mailcap', 'mc.ext', 'menu') and os.path.exists(fname):
83 file = open(fname, 'r')
86 file = open(fname, 'w')
87 if fname == 'mailcap':
89 '-a -n "`which smplayer 2>/dev/null`" -a -n "`which smplayer 2>/dev/null`"',
90 '-a -n "`which smplayer 2>/dev/null`"')
92 '-a -n "`which mplayer 2>/dev/null`" -a -n "`which mplayer 2>/dev/null`"',
93 '-a -n "`which mplayer 2>/dev/null`"')
97 os.system("""exec gvim -f -c "set filetype=%s" -c ":source %s/dotfile2html.vim" "%s"
98 """ % (ftype, home_dir, fname))
100 first = file_types[0][0]
104 prev = file_types[i-1][0]
105 if i >= len(file_types) - 1:
108 next = file_types[i+1][0]
109 last = file_types[-1][0]
110 add_headers(fname, first, prev, next, last)
112 if os.path.exists(fname + ".tmpl") and filecmp.cmp(fname + ".html", fname + ".tmpl"):
113 os.remove(fname + ".html")
115 os.rename(fname + ".html", fname + ".tmpl")
117 if fname == 'vimrc' and os.path.exists('.' + fname):
118 shutil.copy2('.' + fname, fname)
120 if fname.endswith('.py'):
121 new_name = fname + '.txt'
122 os.rename(fname, new_name)
125 if os.path.exists(fname):
126 os.chmod(fname, 0644)
128 def process_files(file_types):
129 for i, (fname, ftype) in enumerate(file_types):
130 process_dotfile(i, fname, ftype, file_types)
132 process_files(home_file_types)
133 process_files(mc_file_types)
134 process_files(python_file_types)