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