]> git.donarmstrong.com Git - lilypond.git/blob - stepmake/bin/add-html-footer.py
release: 1.0.1
[lilypond.git] / stepmake / bin / add-html-footer.py
1 #!@PYTHON@
2
3 """
4 Print a nice footer.  add the top of the NEWS file (up to the ********)
5 """
6
7 program_name = 'add-html-footer'
8 version = '0.1'
9
10 import sys
11 import os
12 from string import *
13 import getopt
14 import __main__
15
16 fullname = "unknown"
17 news_file = ''
18
19 index_file=''
20 banner_file = ''
21 news_file=''
22 news =''
23 (options, files) = getopt.getopt(sys.argv[1:], 'hp:', ['help', 'news=', 'index=', 'package=']) 
24
25 def help ():
26     sys.stdout.write ("Usage: add-html-footer [OPTION]... HTML-FILE\n"
27                  "Add a nice footer, add the top of the NEWS file (up to the ********)\n\n"
28                  + "Options:\n"
29                  + "  -h, --help             print this help\n"
30                  + "  -p, --package=DIR      specify package\n"
31                       )
32     sys.exit (0)
33
34 for opt in options:
35     o = opt[0]
36     a = opt[1]
37     if o == '--news':
38         news_file = a
39     elif o == '--index':
40         index_file = a
41     elif o == '-h' or o == '--help':
42         help ()
43     elif o == '-p' or o == '--package':
44         topdir = a
45
46 sys.path.append (topdir + '/stepmake/bin')
47 from packagepython import *
48 package = Package (topdir)
49 packager = Packager ()
50
51 def set_vars():
52     os.environ["CONFIGSUFFIX"] = 'www';
53     if os.name == 'nt':
54         import ntpwd
55         pw = ntpwd.getpwname(os.environ['USERNAME'])
56     else:
57         import pwd
58         pw = pwd.getpwuid (os.getuid());
59
60     __main__.fullname=pw[4]
61
62 set_vars ()
63
64 backstr = '\n<hr>Please take me <a href=%s>back to the index</a>\n\
65 of ' + package.Name + '\n'
66 builtstr = '\n<hr><font size=-1>\n\
67 This page was built  from ' + package.name + '-%s by <p>\n\
68 <address><br>%s &lt<a href=mailto:%s>%s</a>&gt</address>\n\
69 <p></font>' 
70
71 def footstr(index):
72     s = backstr % index
73     s = s + builtstr % (version_tuple_to_str (package.version), fullname,
74                          packager.mail, packager.mail)
75     return s
76
77 banner = footstr (index_file)
78 banner_id = '<! banner_id >'
79
80
81 if news_file:
82     news = gulp_file (news_file)
83     i = regex.search ('^\*\*', news)
84     news = news[:i]
85     
86 def check_tag (tag, sub, s, bottom):
87     tag = lower (tag)
88     TAG = upper (tag)
89     s = regsub.sub (tag, TAG, s)
90     i = regex.search (TAG, s)
91     if i < 0:
92         if bottom:
93             s = s + sub + '\n'
94         else:
95             s = sub + '\n' + s
96     return s
97     
98 for f in files:
99     s = gulp_file (f)
100
101     if news_file:
102         s = regsub.sub ('top_of_NEWS', '<XMP>\n'+ news  + '\n</XMP>\n', s)
103
104     s = check_tag ('<body', '', s, 0)
105     if regex.search ('<BODY', s) == -1:
106         s = '<BODY>\n' + s
107     s = regsub.sub ('<BODY>', '<BODY BGCOLOR=WHITE><FONT COLOR=BLACK>', s)
108     if regex.search (banner_id, s) == -1:
109         s = regsub.sub ('</body>', '</BODY>', s)
110         s = regsub.sub ('</BODY>', banner_id  + banner + '</BODY>', s)
111     else:
112         s = check_tag ('</body>', '</BODY>', s, 1)
113
114     title = '<HEAD><TITLE>' \
115         + package.Name + ' -- ' + os.path.basename (os.path.splitext(f)[0]) \
116         + '</TITLE></HEAD>'
117     s = check_tag ('<title>', title, s, 0)
118
119     s = check_tag ('<html>', '<HTML>', s, 0)
120     s = check_tag ('</html>', '</HTML>', s, 1)
121
122     #urg
123     if regex.search ('@COUNTER_REF@', s) != -1:
124         counter = ''
125         try:
126             counter = os.environ[package.NAME + '_COUNTERPATH']
127             counter = '<hr><img src="' + counter + '">\n'
128         except:
129             pass
130         s = regsub.gsub ('@COUNTER_REF@', counter, s)
131
132     dump_file (f, s)
133
134