]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/www_post.py
c568734c1b8e16a63f5065de4a57a3acd86d09d9
[lilypond.git] / scripts / build / 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 OUTDIR TARGETS
7 # please call me from top of the source directory
8
9 import sys
10 import os
11 import re
12
13 import langdefs
14
15 import mirrortree
16 import postprocess_html
17
18 package_name, package_version, outdir, targets = sys.argv[1:]
19 targets = targets.split (' ')
20 outdir = os.path.normpath (outdir)
21 doc_dirs = ['input', 'Documentation', outdir]
22 target_pattern = os.path.join (outdir, '%s-root')
23
24 # these redirection pages allow to go back to the documentation index
25 # from HTML manuals/snippets page
26 static_files = {
27     os.path.join (outdir, 'index.html'):
28         '''<META HTTP-EQUIV="refresh" content="0;URL=Documentation/index.html">
29 <html><body>Redirecting to the documentation index...</body></html>\n''',
30     os.path.join (outdir, 'VERSION'):
31         package_version + '\n',
32     os.path.join ('input', 'lsr', outdir, 'index.html'):
33         '''<META HTTP-EQUIV="refresh" content="0;URL=../../index.html">
34 <html><body>Redirecting to the documentation index...</body></html>\n'''
35     }
36
37 for l in langdefs.LANGUAGES:
38     static_files[os.path.join (
39             'Documentation',
40             'user',
41             outdir,
42             l.file_name ('index', '.html'))] = \
43             '<META HTTP-EQUIV="refresh" content="0;URL=../' + l.file_name ('index', '.html') + \
44             '">\n<html><body>Redirecting to the documentation index...</body></html>\n'
45
46 for f, contents in static_files.items ():
47     open (f, 'w').write (contents)
48
49 sys.stderr.write ("Mirroring...\n")
50 dirs, symlinks, files = mirrortree.walk_tree (
51     tree_roots = doc_dirs,
52     process_dirs = outdir,
53     exclude_dirs = '(^|/)((' + \
54         r'po|out|out-test|out-cov|.*?[.]t2d|\w*?-root)|^Documentation/(' + \
55         '|'.join ([l.code for l in langdefs.LANGUAGES]) + '))(/|$)',
56     find_files = r'.*?\.(?:midi|html|pdf|png|txt|i?ly|signature|css|zip)$|VERSION',
57     exclude_files = r'lily-[0-9a-f]+.*\.(pdf|txt)')
58
59 # actual mirrorring stuff
60 html_files = []
61 hardlinked_files = []
62 for f in files:
63     if f.endswith ('.html'):
64         html_files.append (f)
65     else:
66         hardlinked_files.append (f)
67 dirs = [re.sub ('/' + outdir, '', d) for d in dirs]
68 while outdir in dirs:
69     dirs.remove (outdir)
70 dirs = list (set (dirs))
71 dirs.sort ()
72
73 strip_file_name = {}
74 strip_re = re.compile (outdir + '/')
75 for t in targets:
76     out_root = target_pattern % t
77     strip_file_name[t] = lambda s: os.path.join (target_pattern % t, (strip_re.sub ('', s)))
78     os.mkdir (out_root)
79     map (os.mkdir, [os.path.join (out_root, d) for d in dirs])
80     for f in hardlinked_files:
81         os.link (f, strip_file_name[t] (f))
82     for l in symlinks:
83         p = mirrortree.new_link_path (os.path.normpath (os.readlink (l)), os.path.dirname (l), strip_re)
84         dest = strip_file_name[t] (l)
85         if not os.path.exists (dest):
86             os.symlink (p, dest)
87
88     ## ad-hoc renaming to make xrefs between PDFs work
89     os.rename (os.path.join (out_root, 'input/lsr/lilypond-snippets.pdf'),
90                os.path.join (out_root, 'Documentation/user/lilypond-snippets.pdf'))
91
92 # need this for content negotiation with documentation index
93 if 'online' in targets:
94     f = open (os.path.join (target_pattern % 'online', 'Documentation/.htaccess'), 'w')
95     f.write ('#.htaccess\nDirectoryIndex index\n')
96     f.close ()
97
98 postprocess_html.build_pages_dict (html_files)
99 for t in targets:
100     sys.stderr.write ("Processing HTML pages for %s target...\n" % t)
101     postprocess_html.process_html_files (
102         package_name = package_name,
103         package_version = package_version,
104         target = t,
105         name_filter = strip_file_name[t])
106