3 __author__ = "Oleg Broytman <phd@phdru.name>"
4 __copyright__ = "Copyright (C) 2004-2020 PhiloSoft Design"
9 os.umask(0022) # octal; -rw-r--r--
11 from m_lib.m_path import get_homedir
12 home_dir = get_homedir()
15 def add_headers(fname, first, prev, next, last):
16 head_fname = os.path.join(home_dir, fname + ".head")
17 head_file = open(head_fname, 'r')
18 head = head_file.read()
21 html_fname = fname + ".html"
22 html_file = open(html_fname, 'r')
23 html = html_file.read()
26 if fname in ("init.py", "pdbrc.py"):
28 txt_name = fname + '.txt'
30 dot_name = '.' + fname
33 html_file = open(html_fname, 'w')
34 if fname in ("muttrc", "procmailrc", "vimrc"):
35 html_file.write("#encoding koi8-r\n")
36 html_file.write("#extends phd_site\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")
40 html_file.write("#attr $First = \"%s.html\"\n" % first)
42 html_file.write("#attr $Prev = \"%s.html\"\n" % prev)
44 html_file.write("#attr $Next = \"%s.html\"\n" % next)
45 html_file.write("#attr $Last = \"%s.html\"\n" % last)
46 html_file.write('#attr $alternates = (("Plain text version", "text/plain", "%s"),)' % txt_name)
48 html_file.write("#def body_html\n")
49 html_file.write("#raw\n")
53 html_file.write("#end raw\n")
54 html_file.write("#end def\n")
55 html_file.write("$phd_site.respond(self)\n")
60 ("bashrc", "sh"), ("profile", "sh"), ("shellrc", "sh"),
61 ("mailcap", "conf"), ("mime.types", "conf"),
62 ("muttrc", "muttrc"), ("procmailrc", "procmail"),
63 ("gitconfig", "gitconfig"), ("vimrc", "vim"),
66 mc_file_types = (("mc.ext", "conf"), ("menu", "conf"))
68 python_file_types = (("init.py", "python"),
69 ("pdbrc", "python"), ("pdbrc.py", "python"))
71 def process_dotfile(i, fname, ftype, file_types):
72 if os.path.exists('.' + fname) and not os.path.exists(fname):
73 shutil.copy2('.' + fname, fname)
75 if not os.path.exists(fname):
78 file = open(fname, 'r')
82 if fname in ('mailcap', 'mc.ext', 'menu'):
83 file = open(fname, 'w')
84 text = text.replace('mplay', 'mplayer')
85 text = text.replace('mplayerer', 'mplayer')
86 if fname == 'mailcap':
88 '-a -n "`which mplayer 2>/dev/null`" -a -n "`which mplayer 2>/dev/null`"',
89 '-a -n "`which mplayer 2>/dev/null`"')
93 elif fname == 'vimrc':
94 file = open(fname, 'w')
95 text = text.replace('\033', '<Esc>')
99 os.system("""exec gvim -f -c "set filetype=%s" -c ":source %s/dotfile2html.vim" "%s"
100 """ % (ftype, home_dir, fname))
102 first = file_types[0][0]
106 prev = file_types[i-1][0]
107 if i >= len(file_types) - 1:
110 next = file_types[i+1][0]
111 last = file_types[-1][0]
112 add_headers(fname, first, prev, next, last)
114 if os.path.exists(fname + ".tmpl") and filecmp.cmp(fname + ".html", fname + ".tmpl"):
115 os.remove(fname + ".html")
117 os.rename(fname + ".html", fname + ".tmpl")
119 if fname.endswith('.py'):
120 new_name = fname + '.txt'
121 os.rename(fname, new_name)
124 if fname == 'vimrc' and os.path.exists('.' + fname):
125 shutil.copy2('.' + fname, fname)
127 if os.path.exists(fname):
128 os.chmod(fname, 0644)
130 def process_files(file_types):
131 for i, (fname, ftype) in enumerate(file_types):
132 process_dotfile(i, fname, ftype, file_types)
134 process_files(home_file_types)
135 process_files(mc_file_types)
136 process_files(python_file_types)