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