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