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 OUTDIR TARGETS
7 # please call me from top of the source directory
16 import postprocess_html
18 package_name
, package_version
, outdir
, targets
= sys
.argv
[1:]
19 targets
= targets
.split (' ')
20 outdir
= os
.path
.normpath (outdir
)
21 doc_dirs
= ['input', 'Documentation', outdir
]
22 target_pattern
= os
.path
.join (outdir
, '%s-root')
24 # these redirection pages allow to go back to the documentation index
25 # from HTML manuals/snippets page
27 os
.path
.join (outdir
, 'index.html'):
28 '''<META HTTP-EQUIV="refresh" content="0;URL=Documentation/index.html">
29 <html><body>Redirecting to the documentation index...</body></html>\n''',
30 os
.path
.join (outdir
, 'VERSION'):
31 package_version
+ '\n',
34 for f
, contents
in static_files
.items ():
35 open (f
, 'w').write (contents
)
37 sys
.stderr
.write ("Mirroring...\n")
38 dirs
, symlinks
, files
= mirrortree
.walk_tree (
39 tree_roots
= doc_dirs
,
40 process_dirs
= outdir
,
41 exclude_dirs
= '(^|/)((' + \
42 r
'po|xref-maps|out|out-test|out-cov|.*?[.]t2d|\w*?-root)|^Documentation/(' + \
43 '|'.join ([l
.code
for l
in langdefs
.LANGUAGES
]) + '))(/|$)',
44 find_files
= r
'.*?\.(?:midi|html|pdf|png|txt|i?ly|signature|css|zip)$|VERSION',
45 exclude_files
= r
'lily-[0-9a-f]+.*\.(pdf|txt)')
47 # actual mirrorring stuff
51 if f
.endswith ('.html'):
54 hardlinked_files
.append (f
)
55 dirs
= [re
.sub ('/' + outdir
, '', d
) for d
in dirs
]
58 dirs
= list (set (dirs
))
62 strip_re
= re
.compile (outdir
+ '/')
64 out_root
= target_pattern
% t
65 strip_file_name
[t
] = lambda s
: os
.path
.join (target_pattern
% t
, (strip_re
.sub ('', s
)))
67 map (os
.mkdir
, [os
.path
.join (out_root
, d
) for d
in dirs
])
68 for f
in hardlinked_files
:
69 os
.link (f
, strip_file_name
[t
] (f
))
71 p
= mirrortree
.new_link_path (os
.path
.normpath (os
.readlink (l
)), os
.path
.dirname (l
), strip_re
)
72 dest
= strip_file_name
[t
] (l
)
73 if not os
.path
.exists (dest
):
77 # need this for content negotiation with documentation index
78 if 'online' in targets
:
79 f
= open (os
.path
.join (target_pattern
% 'online', 'Documentation/.htaccess'), 'w')
80 f
.write ('#.htaccess\nDirectoryIndex index\n')
83 postprocess_html
.build_pages_dict (html_files
)
85 sys
.stderr
.write ("Processing HTML pages for %s target...\n" % t
)
86 postprocess_html
.process_html_files (
87 package_name
= package_name
,
88 package_version
= package_version
,
90 name_filter
= strip_file_name
[t
])