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')
20 # ugly hack: the following overwrites HTML Info dir with a link to
21 # the (more useful) documentation index
22 os.path.join ('Documentation/user', outdir, 'index.html'):
23 '''<META HTTP-EQUIV="refresh" content="0;URL=../index.html">
24 <html><body>Redirecting to the documentation index...</body></html>\n''',
25 os.path.join (outdir, 'index.html'):
26 '''<META HTTP-EQUIV="refresh" content="0;URL=Documentation/index.html">
27 <html><body>Redirecting to the documentation index...</body></html>\n''',
28 os.path.join (outdir, 'VERSION'):
29 package_version + '\n' }
31 for f, contents in static_files.items ():
32 open (f, 'w').write (contents)
35 sys.path.append (buildscript_dir)
37 import add_html_footer
40 sys.stderr.write ("Mirrorring...\n")
41 dirs, symlinks, files = mirrortree.walk_tree (
42 tree_roots = doc_dirs,
43 process_dirs = outdir,
44 exclude_dirs = '(' + '|'.join ([l.code for l in langdefs.LANGUAGES]) + r'|po|out|\w*?-root)(/|$)',
45 find_files = r'.*?\.(?:midi|html|pdf|png|txt|ly|signature)$|VERSION',
46 exclude_files = r'lily-[0-9a-f]+.*\.pdf')
48 # actual mirrorring stuff
52 if f.endswith ('.html'):
55 hardlinked_files.append (f)
56 dirs = [re.sub ('/' + outdir, '', d) for d in dirs]
59 dirs = list( set (dirs))
63 strip_re = re.compile (outdir + '/')
65 out_root = target_pattern % t
66 strip_file_name[t] = lambda s: os.path.join (target_pattern % t, (strip_re.sub ('', s)))
68 map (os.mkdir, [os.path.join (out_root, d) for d in dirs])
69 for f in hardlinked_files:
70 os.link (f, strip_file_name[t] (f))
72 p = mirrortree.new_link_path (os.path.normpath (os.readlink (l)), os.path.dirname (l), strip_re)
73 os.symlink (p, strip_file_name[t] (l))
75 # need this for content negotiation with documentation index
76 if 'online' in targets:
77 f = open (os.path.join (target_pattern % 'online', 'Documentation/.htaccess'), 'w')
78 f.write ('#.htaccess\nDirectoryIndex index\n')
81 # load gettext messages catalogs
83 localedir = os.path.join (buildscript_dir, '../Documentation/po', outdir)
84 for l in langdefs.LANGUAGES:
85 if l.enabled and l.code != 'en':
87 t[l.code] = gettext.translation('lilypond-doc', localedir, [l.code]).gettext
89 t[l.code] = lambda s: s
91 add_html_footer.build_pages_dict (html_files)
93 sys.stderr.write ("Processing HTML pages for %s target...\n" % t)
94 add_html_footer.add_html_footer (
96 package_name = package_name,
97 package_version = package_version,
99 name_filter = strip_file_name[t])