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