]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/www_post.py
Merge remote-tracking branch 'origin/release/unstable' into staging
[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/web/index.html">
29 <html><body>Redirecting to the documentation index...</body></html>\n''',
30     os.path.join (outdir, 'VERSION'):
31         package_version + '\n',
32     }
33
34 for f, contents in static_files.items ():
35     open (f, 'w').write (contents)
36
37 sys.stderr.write ("Mirroring...\n")
38 dirs, symlinks, files = mirrortree.walk_tree (
39     tree_roots = doc_dirs,
40     process_dirs = outdir,
41     exclude_dirs = '(^|/)((' + \
42         r'po|xref-maps|out|out-test|out-cov|.*?[.]t2d|\w*?-root)|^Documentation/(' + \
43         '|'.join ([l.code for l in langdefs.LANGUAGES]) + '))(/|$)',
44     find_files = r'.*?\.(?:midi|html|pdf|png|jpe?g|txt|i?ly|signature|css|zip|js|..\.idx|php)$|VERSION',
45     exclude_files = r'lily-[0-9a-f]+.*\.(pdf|txt)')
46 # extra files: info and tex output from lilypond-book regtests
47 extra_files = mirrortree.walk_tree (
48     tree_roots = ['input/regression/lilypond-book'],
49     process_dirs = outdir,
50     exclude_dirs = r'(^|/)(out|out-test)(/|$)',
51     find_files = r'.+\.(info|tex)$',
52     exclude_files = r'lily-[0-9a-f]+.*\.tex')[2]
53 files.extend(extra_files)
54
55 # actual mirrorring stuff
56 html_files = []
57 hardlinked_files = []
58 # These whitelisted files actually do contain the string
59 # 'UNTRANSLATED NODE: IGNORE ME' for documentation purposes.
60 whitelisted_files = [
61     'Documentation/out-www/contributor-big-page.html',
62     'Documentation/out-www/contributor/website-build.html',
63 ]
64 for f in files:
65     if f.endswith ('.html'):
66         if f in whitelisted_files or not 'UNTRANSLATED NODE: IGNORE ME' in open (f).read ():
67             html_files.append (f)
68     else:
69         hardlinked_files.append (f)
70 dirs = [re.sub ('/' + outdir, '', d) for d in dirs]
71 while outdir in dirs:
72     dirs.remove (outdir)
73 dirs = list (set (dirs))
74 dirs.sort ()
75
76 strip_file_name = {}
77 strip_re = re.compile (outdir + '/')
78 for t in targets:
79     out_root = target_pattern % t
80     strip_file_name[t] = lambda s: os.path.join (target_pattern % t, (strip_re.sub ('', s)))
81     if not os.path.exists (out_root):
82         os.mkdir (out_root)
83     for d in dirs:
84         new_dir = os.path.join (out_root, d)
85         if not os.path.exists (new_dir):
86             os.mkdir (new_dir)
87     for f in hardlinked_files:
88         if not os.path.isfile (strip_file_name[t] (f)):
89             os.link (f, strip_file_name[t] (f))
90     for l in symlinks:
91         p = mirrortree.new_link_path (os.path.normpath (os.readlink (l)), os.path.dirname (l), strip_re)
92         dest = strip_file_name[t] (l)
93         if not os.path.lexists (dest):
94             os.symlink (p, dest)
95
96
97 # need this for content negotiation with documentation index
98 if 'online' in targets:
99     f = open (os.path.join (target_pattern % 'online', 'Documentation/.htaccess'), 'w')
100     f.write ('#.htaccess\nDirectoryIndex index\n')
101     f.close ()
102
103 postprocess_html.build_pages_dict (html_files)
104 for t in targets:
105     sys.stderr.write ("Processing HTML pages for %s target...\n" % t)
106     postprocess_html.process_html_files (
107         package_name = package_name,
108         package_version = package_version,
109         target = t,
110         name_filter = strip_file_name[t])
111