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