]> git.donarmstrong.com Git - lilypond.git/blob - stepmake/bin/text2html.py
Make distributed tarball from Git file list
[lilypond.git] / stepmake / bin / text2html.py
1 #@PYTHON@
2 import os
3 import re
4 import string
5 import sys
6
7
8 entities = {
9     "&" : 'amp',
10     "`" : 'apos',
11     '>' : 'gt',
12     '<' : 'lt',
13     '"' : 'quot',
14     }
15
16 def txt2html (s):
17     for i in entities.keys ():
18         s = re.sub (i, '\001' + entities[i] + ';', s);
19     s = re.sub ('\001', '&', s);
20     return s
21
22 for a in sys.argv[1:]:
23     # hmm, we need: text2html out/foe.txt -> out/foe.html,
24     # -o is a bit overkill?
25     # outfile = os.path.basename (os.path.splitext(a)[0]) + '.html'
26     outfile = os.path.splitext(a)[0] + '.html'
27     
28     try:
29       os.unlink(outfile)
30     except:
31       pass
32
33     s = r"""
34
35 <html>
36 <head>
37  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
38 </head>
39
40 <body><pre>
41 %s
42 </pre></body></html>
43 """ % txt2html (open (a).read ())
44     open (outfile, 'w').write (s)
45
46