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