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
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')
19 # these redirection pages allow to go back to the documentation index
20 # from HTML manuals/snippets page
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'''
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'
39 for f, contents in static_files.items ():
40 open (f, 'w').write (contents)
43 sys.path.append (buildscript_dir)
45 import add_html_footer
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)')
55 # actual mirrorring stuff
59 if f.endswith ('.html'):
62 hardlinked_files.append (f)
63 dirs = [re.sub ('/' + outdir, '', d) for d in dirs]
66 dirs = list (set (dirs))
70 strip_re = re.compile (outdir + '/')
72 out_root = target_pattern % t
73 strip_file_name[t] = lambda s: os.path.join (target_pattern % t, (strip_re.sub ('', s)))
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))
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):
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'))
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')
94 add_html_footer.build_pages_dict (html_files)
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,
101 name_filter = strip_file_name[t])