3 __author__ = "Oleg Broytman <phd@phdru.name>"
4 __copyright__ = "Copyright (C) 2004-2020 PhiloSoft Design"
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, first, prev, next, last):
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 if fname in ("muttrc", "procmailrc", "vimrc"):
36 html_file.write("#encoding koi8-r\n")
37 html_file.write("#extends phd_site\n")
38 html_file.write("#implements respond\n")
39 html_file.write("#attr $Title = \"%s\"\n" % dot_name)
40 html_file.write("#attr $Copyright = 2003\n")
41 html_file.write("#attr $First = \"%s.html\"\n" % first)
43 html_file.write("#attr $Prev = \"%s.html\"\n" % prev)
45 html_file.write("#attr $Next = \"%s.html\"\n" % next)
46 html_file.write("#attr $Last = \"%s.html\"\n" % last)
47 html_file.write('#attr $alternates = (("Plain text version", "text/plain", "%s"),)' % txt_name)
49 html_file.write("#def body_html\n")
50 html_file.write("#raw\n")
54 html_file.write("#end raw\n")
55 html_file.write("#end def\n")
56 html_file.write("$phd_site.respond(self)\n")
61 ("bashrc", "sh"), ("profile", "sh"), ("shellrc", "sh"),
62 ("mailcap", "conf"), ("mime.types", "conf"),
63 ("muttrc", "muttrc"), ("procmailrc", "procmail"),
64 ("gitconfig", "gitconfig"), ("vimrc", "vim"),
67 mc_file_types = (("mc.ext", "conf"), ("menu", "conf"))
69 python_file_types = (("init.py", "python"),
70 ("pdbrc", "python"), ("pdbrc.py", "python"))
72 def process_dotfile(i, fname, ftype, file_types):
73 if os.path.exists('.' + fname) and not os.path.exists(fname):
74 shutil.copy2('.' + fname, fname)
76 if not os.path.exists(fname):
79 file = open(fname, 'r')
83 text = re.sub('cgmem_nice \d+ ', '', text)
85 if fname in ('mailcap', 'mc.ext', 'menu'):
86 file = open(fname, 'w')
87 text = text.replace('mplay', 'mplayer')
88 text = text.replace('mplayerer', 'mplayer')
89 if fname == 'mailcap':
91 '-a -n "`which mplayer 2>/dev/null`" -a -n "`which mplayer 2>/dev/null`"',
92 '-a -n "`which mplayer 2>/dev/null`"')
96 elif fname == 'vimrc':
97 file = open(fname, 'w')
98 text = text.replace('\033', '<Esc>')
102 os.system("""exec gvim -f -c "set filetype=%s" -c ":source %s/dotfile2html.vim" "%s"
103 """ % (ftype, home_dir, fname))
105 first = file_types[0][0]
109 prev = file_types[i-1][0]
110 if i >= len(file_types) - 1:
113 next = file_types[i+1][0]
114 last = file_types[-1][0]
115 add_headers(fname, first, prev, next, last)
117 if os.path.exists(fname + ".tmpl") and filecmp.cmp(fname + ".html", fname + ".tmpl"):
118 os.remove(fname + ".html")
120 os.rename(fname + ".html", fname + ".tmpl")
122 if fname.endswith('.py'):
123 new_name = fname + '.txt'
124 os.rename(fname, new_name)
127 if fname == 'vimrc' and os.path.exists('.' + fname):
128 shutil.copy2('.' + fname, fname)
130 if os.path.exists(fname):
131 os.chmod(fname, 0644)
133 def process_files(file_types):
134 for i, (fname, ftype) in enumerate(file_types):
135 process_dotfile(i, fname, ftype, file_types)
137 process_files(home_file_types)
138 process_files(mc_file_types)
139 process_files(python_file_types)