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 BUILDSCRIPT-DIR OUTDIR TARGETS
7 # please call me from top of the source directory
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')
20 # these redirection pages allow to go back to the documentation index
21 # from HTML manuals/snippets page
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'''
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'
40 for f, contents in static_files.items ():
41 open (f, 'w').write (contents)
44 sys.path.append (buildscript_dir)
46 import add_html_footer
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)$|VERSION',
54 exclude_files = r'lily-[0-9a-f]+.*\.(pdf|txt)')
56 # actual mirrorring stuff
60 if f.endswith ('.html'):
63 hardlinked_files.append (f)
64 dirs = [re.sub ('/' + outdir, '', d) for d in dirs]
67 dirs = list (set (dirs))
71 strip_re = re.compile (outdir + '/')
73 out_root = target_pattern % t
74 strip_file_name[t] = lambda s: os.path.join (target_pattern % t, (strip_re.sub ('', s)))
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))
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):
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'))
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')
95 # load gettext messages catalogs
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
101 add_html_footer.build_pages_dict (html_files)
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,
109 name_filter = strip_file_name[t])