diff options
author | John Mandereau <john.mandereau@gmail.com> | 2009-01-05 03:22:01 +0100 |
---|---|---|
committer | John Mandereau <john.mandereau@gmail.com> | 2009-01-05 03:29:08 +0100 |
commit | 543171165412bc915d8ea1f308d070c74924b2f1 (patch) | |
tree | 5e401c33ec74c7bad43c3842e44b2a10b7158a3e /scripts/build/www_post.py | |
parent | dc22ed0f12ec6c81e04512ab40ed2dbd076712a4 (diff) |
Clean up buildscripts
- move scripts from buildscripts/ according to the new ROADMAP, create
three directories for this purpose: scripts/aux/, scripts/build/ and
python/aux;
- make permissions and interpreter specs clearer: all scripts in
scripts/build are non-executable and use an interpreter determined in
config.make, all scripts in scripts/aux use hard-coded interpreters;
- always use built avatars of scripts in scripts/build, as a
consequence remove interpreter invocations which are no longer needed;
- keep old scripts in buildscripts/ which are junked in the very next
commits.
Diffstat (limited to 'scripts/build/www_post.py')
-rw-r--r-- | scripts/build/www_post.py | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/scripts/build/www_post.py b/scripts/build/www_post.py new file mode 100644 index 0000000000..29f80cf09f --- /dev/null +++ b/scripts/build/www_post.py @@ -0,0 +1,100 @@ +#!@PYTHON@ + +## This is www_post.py. This script is the main stage +## of toplevel GNUmakefile local-WWW-post target. + +# USAGE: www_post PACKAGE_NAME TOPLEVEL_VERSION OUTDIR TARGETS +# please call me from top of the source directory + +import sys +import os +import re + +import langdefs + +import mirrortree +import postprocess_html + +package_name, package_version, outdir, targets = sys.argv[1:] +targets = targets.split (' ') +outdir = os.path.normpath (outdir) +doc_dirs = ['input', 'Documentation', outdir] +target_pattern = os.path.join (outdir, '%s-root') + +# these redirection pages allow to go back to the documentation index +# from HTML manuals/snippets page +static_files = { + os.path.join (outdir, 'index.html'): + '''<META HTTP-EQUIV="refresh" content="0;URL=Documentation/index.html"> +<html><body>Redirecting to the documentation index...</body></html>\n''', + os.path.join (outdir, 'VERSION'): + package_version + '\n', + os.path.join ('input', 'lsr', outdir, 'index.html'): + '''<META HTTP-EQUIV="refresh" content="0;URL=../../index.html"> +<html><body>Redirecting to the documentation index...</body></html>\n''' + } + +for l in langdefs.LANGUAGES: + static_files[os.path.join ('Documentation', 'user', outdir, l.file_name ('index', '.html'))] = \ + '<META HTTP-EQUIV="refresh" content="0;URL=../' + l.file_name ('index', '.html') + \ + '">\n<html><body>Redirecting to the documentation index...</body></html>\n' + +for f, contents in static_files.items (): + open (f, 'w').write (contents) + +sys.stderr.write ("Mirrorring...\n") +dirs, symlinks, files = mirrortree.walk_tree ( + tree_roots = doc_dirs, + process_dirs = outdir, + exclude_dirs = '(^|/)(' + r'|po|out|out-test|.*?[.]t2d|\w*?-root)(/|$)|Documentation/(' + '|'.join ([l.code for l in langdefs.LANGUAGES]) + ')', + find_files = r'.*?\.(?:midi|html|pdf|png|txt|i?ly|signature|css)$|VERSION', + exclude_files = r'lily-[0-9a-f]+.*\.(pdf|txt)') + +# actual mirrorring stuff +html_files = [] +hardlinked_files = [] +for f in files: + if f.endswith ('.html'): + html_files.append (f) + else: + hardlinked_files.append (f) +dirs = [re.sub ('/' + outdir, '', d) for d in dirs] +while outdir in dirs: + dirs.remove (outdir) +dirs = list (set (dirs)) +dirs.sort () + +strip_file_name = {} +strip_re = re.compile (outdir + '/') +for t in targets: + out_root = target_pattern % t + strip_file_name[t] = lambda s: os.path.join (target_pattern % t, (strip_re.sub ('', s))) + os.mkdir (out_root) + map (os.mkdir, [os.path.join (out_root, d) for d in dirs]) + for f in hardlinked_files: + os.link (f, strip_file_name[t] (f)) + for l in symlinks: + p = mirrortree.new_link_path (os.path.normpath (os.readlink (l)), os.path.dirname (l), strip_re) + dest = strip_file_name[t] (l) + if not os.path.exists (dest): + os.symlink (p, dest) + + ## ad-hoc renaming to make xrefs between PDFs work + os.rename (os.path.join (out_root, 'input/lsr/lilypond-snippets.pdf'), + os.path.join (out_root, 'Documentation/user/lilypond-snippets.pdf')) + +# need this for content negotiation with documentation index +if 'online' in targets: + f = open (os.path.join (target_pattern % 'online', 'Documentation/.htaccess'), 'w') + f.write ('#.htaccess\nDirectoryIndex index\n') + f.close () + +postprocess_html.build_pages_dict (html_files) +for t in targets: + sys.stderr.write ("Processing HTML pages for %s target...\n" % t) + postprocess_html.process_html_files ( + package_name = package_name, + package_version = package_version, + target = t, + name_filter = strip_file_name[t]) + |