]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/www_post.py
Gettextize add_html_footer
[lilypond.git] / buildscripts / www_post.py
1 #!@PYTHON@
2
3 ## This is www_post.py. This script is the main stage
4 ## of toplevel GNUmakefile local-WWW-post target.
5
6 # USAGE: www_post PACKAGE_NAME TOPLEVEL_VERSION BUILDSCRIPT-DIR OUTDIR TARGETS
7 # please call me from top of the source directory
8
9 import sys
10 import os
11 import re
12
13 package_name, package_version, buildscript_dir, outdir, targets = sys.argv[1:]
14 targets = targets.split (' ')
15 outdir = os.path.normpath (outdir)
16 doc_dirs = ['input', 'Documentation', outdir]
17 target_pattern = os.path.join (outdir, '%s-root')
18
19 static_files = {
20     # ugly hack: the following overwrites HTML Info dir with a link to
21     # the (more useful) documentation index
22     os.path.join ('Documentation/user', outdir, 'index.html'):
23     '''<META HTTP-EQUIV="refresh" content="0;URL=../index.html">
24 <html><body>Redirecting to the documentation index...</body></html>\n''',
25     os.path.join (outdir, 'index.html'):
26     '''<META HTTP-EQUIV="refresh" content="0;URL=Documentation/index.html">
27 <html><body>Redirecting to the documentation index...</body></html>\n''',
28     os.path.join (outdir, 'VERSION'):
29     package_version + '\n' }
30
31 for f, contents in static_files.items ():
32     open (f, 'w').write (contents)
33
34
35 sys.path.append (buildscript_dir)
36 import mirrortree
37 import add_html_footer
38 import langdefs
39
40 sys.stderr.write ("Mirrorring...\n")
41 dirs, symlinks, files = mirrortree.walk_tree (
42     tree_roots = doc_dirs,
43     process_dirs = outdir,
44     exclude_dirs = '(' + '|'.join ([l.code for l in langdefs.LANGUAGES]) + r'|po|out|\w*?-root)(/|$)',
45     find_files = r'.*?\.(?:midi|html|pdf|png|txt|ly|signature)$|VERSION',
46     exclude_files = r'lily-[0-9a-f]+.*\.pdf')
47
48 # actual mirrorring stuff
49 html_files = []
50 hardlinked_files = []
51 for f in files:
52     if f.endswith ('.html'):
53         html_files.append (f)
54     else:
55         hardlinked_files.append (f)
56 dirs = [re.sub ('/' + outdir, '', d) for d in dirs]
57 while outdir in dirs:
58     dirs.remove (outdir)
59 dirs = list( set (dirs))
60 dirs.sort ()
61
62 strip_file_name = {}
63 strip_re = re.compile (outdir + '/')
64 for t in targets:
65     out_root = target_pattern % t
66     strip_file_name[t] = lambda s: os.path.join (target_pattern % t, (strip_re.sub ('', s)))
67     os.mkdir (out_root)
68     map (os.mkdir, [os.path.join (out_root, d) for d in dirs])
69     for f in hardlinked_files:
70         os.link (f, strip_file_name[t] (f))
71     for l in symlinks:
72         p = mirrortree.new_link_path (os.path.normpath (os.readlink (l)), os.path.dirname (l), strip_re)
73         os.symlink (p, strip_file_name[t] (l))
74
75 # need this for content negotiation with documentation index
76 if 'online' in targets:
77     f = open (os.path.join (target_pattern % 'online', 'Documentation/.htaccess'), 'w')
78     f.write ('#.htaccess\nDirectoryIndex index\n')
79     f.close ()
80
81 # load gettext messages catalogs
82 t = {}
83 localedir = os.path.join (buildscript_dir, '../Documentation/po', outdir)
84 for l in langdefs.LANGUAGES:
85     if l.enabled and l.code != 'en':
86         try:
87             t[l.code] = gettext.translation('lilypond-doc', localedir, [l.code]).gettext
88         except:
89             t[l.code] = lambda s: s
90
91 add_html_footer.build_pages_dict (html_files)
92 for t in targets:
93     sys.stderr.write ("Processing HTML pages for %s target...\n" % t)
94     add_html_footer.add_html_footer (
95         translation = t
96         package_name = package_name,
97         package_version = package_version,
98         target = t,
99         name_filter = strip_file_name[t])
100