LSR: Update.
[lilypond.git] / buildscripts / www_post.py
blob29f80cf09fa2bb208995e7c5094974782c6ee566
1 #!@PYTHON@
3 ## This is www_post.py. This script is the main stage
4 ## of toplevel GNUmakefile local-WWW-post target.
6 # USAGE: www_post PACKAGE_NAME TOPLEVEL_VERSION OUTDIR TARGETS
7 # please call me from top of the source directory
9 import sys
10 import os
11 import re
13 import langdefs
15 import mirrortree
16 import postprocess_html
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')
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'''
37 for l in langdefs.LANGUAGES:
38 static_files[os.path.join ('Documentation', 'user', outdir, l.file_name ('index', '.html'))] = \
39 '<META HTTP-EQUIV="refresh" content="0;URL=../' + l.file_name ('index', '.html') + \
40 '">\n<html><body>Redirecting to the documentation index...</body></html>\n'
42 for f, contents in static_files.items ():
43 open (f, 'w').write (contents)
45 sys.stderr.write ("Mirrorring...\n")
46 dirs, symlinks, files = mirrortree.walk_tree (
47 tree_roots = doc_dirs,
48 process_dirs = outdir,
49 exclude_dirs = '(^|/)(' + r'|po|out|out-test|.*?[.]t2d|\w*?-root)(/|$)|Documentation/(' + '|'.join ([l.code for l in langdefs.LANGUAGES]) + ')',
50 find_files = r'.*?\.(?:midi|html|pdf|png|txt|i?ly|signature|css)$|VERSION',
51 exclude_files = r'lily-[0-9a-f]+.*\.(pdf|txt)')
53 # actual mirrorring stuff
54 html_files = []
55 hardlinked_files = []
56 for f in files:
57 if f.endswith ('.html'):
58 html_files.append (f)
59 else:
60 hardlinked_files.append (f)
61 dirs = [re.sub ('/' + outdir, '', d) for d in dirs]
62 while outdir in dirs:
63 dirs.remove (outdir)
64 dirs = list (set (dirs))
65 dirs.sort ()
67 strip_file_name = {}
68 strip_re = re.compile (outdir + '/')
69 for t in targets:
70 out_root = target_pattern % t
71 strip_file_name[t] = lambda s: os.path.join (target_pattern % t, (strip_re.sub ('', s)))
72 os.mkdir (out_root)
73 map (os.mkdir, [os.path.join (out_root, d) for d in dirs])
74 for f in hardlinked_files:
75 os.link (f, strip_file_name[t] (f))
76 for l in symlinks:
77 p = mirrortree.new_link_path (os.path.normpath (os.readlink (l)), os.path.dirname (l), strip_re)
78 dest = strip_file_name[t] (l)
79 if not os.path.exists (dest):
80 os.symlink (p, dest)
82 ## ad-hoc renaming to make xrefs between PDFs work
83 os.rename (os.path.join (out_root, 'input/lsr/lilypond-snippets.pdf'),
84 os.path.join (out_root, 'Documentation/user/lilypond-snippets.pdf'))
86 # need this for content negotiation with documentation index
87 if 'online' in targets:
88 f = open (os.path.join (target_pattern % 'online', 'Documentation/.htaccess'), 'w')
89 f.write ('#.htaccess\nDirectoryIndex index\n')
90 f.close ()
92 postprocess_html.build_pages_dict (html_files)
93 for t in targets:
94 sys.stderr.write ("Processing HTML pages for %s target...\n" % t)
95 postprocess_html.process_html_files (
96 package_name = package_name,
97 package_version = package_version,
98 target = t,
99 name_filter = strip_file_name[t])