From fe261ab5648aa9827f66a72f14d1fe0422a96308 Mon Sep 17 00:00:00 2001 From: John Mandereau Date: Sun, 1 Jul 2007 17:46:30 +0200 Subject: [PATCH 1/1] Fix and improve documentation files linking - fix linking bugs introduced when adding mass-link.py and support for translated PDFs, - get rid of symlinks in offline docs target so the docs are more usable on Windows. --- GNUmakefile.in | 1 + buildscripts/add_html_footer.py | 27 ++++++++++++++++----------- buildscripts/mass-link.py | 18 +++++++++++++----- buildscripts/www_post.py | 15 +++++++++------ make/doclang-targets.make | 2 +- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/GNUmakefile.in b/GNUmakefile.in index f821cc57d7..00345e39dc 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -99,6 +99,7 @@ local-WWW-post: rm -rf $(outdir)/online-root rm -rf $(outdir)/offline-root $(PYTHON) $(buildscript-dir)/www_post.py $(PACKAGE_NAME) $(TOPLEVEL_VERSION) $(buildscript-dir) $(top-build-dir)/Documentation/po/$(outdir) $(outdir) "$(WEB_TARGETS)" + find $(outdir)/offline-root -type l -delete tree-prefix = $(outdir) diff --git a/buildscripts/add_html_footer.py b/buildscripts/add_html_footer.py index 7e331ba710..802134f9f4 100644 --- a/buildscripts/add_html_footer.py +++ b/buildscripts/add_html_footer.py @@ -83,6 +83,20 @@ def build_pages_dict (filelist): else: pages_dict[g[0]].append (e) +def source_links_replace (m, source_val): + return 'href="' + os.path.join (source_val, m.group (1)) + '"' + +# On systems without symlinks (e.g. Windows), docs are not very usable +# Get rid of symlinks here (also in GNUmakefile.in (local-WWW-post)) +def replace_symlinks_urls (s, prefix): + if prefix.startswith ('Documentation/user/'): + s = re.sub ('(href|src)="(lily-.*?|.*?-flat-.*?)"', '\\1="../\\2"', s) + source_path = os.path.join (os.path.dirname (prefix), 'source') + if not os.path.islink (source_path): + return s + source_val = os.readlink (source_path) + return re.sub ('href="source/(.*?)"', lambda m: source_links_replace (m, source_val), s) + def add_header (s): """Add header ( and doctype)""" if re.search (header_tag, s) == None: @@ -102,10 +116,6 @@ def add_header (s): s = doctype + s return s -def info_external_ref_remove (s): - """Remove info's annoying's indication of referencing external document""" - return re.sub (' \((lilypond|lilypond-internals|music-glossary)\)', '', s) - def add_title (s): # urg # maybe find first node? @@ -247,9 +257,9 @@ def add_html_footer (translation, in_f.close() s = re.sub ('%', '%%', s) + if target == 'offline': + s = replace_symlinks_urls (s, prefix) s = add_header (s) - # seems to be no more needed - # s = info_external_ref_remove (s) ### add footer if re.search (footer_tag, s) == None: @@ -259,11 +269,6 @@ def add_html_footer (translation, page_flavors = process_links (s, prefix, lang_ext, file_name, missing, target) # Add menu after stripping: must not have autoselection for language menu. page_flavors = add_menu (page_flavors, prefix, available, target, translation) - # urg, this stuff is outdated and seems useless, let's disable it - #else: - # for e in [l.webext for l in langdefs.LANGUAGES]: - # if not e in pages_dict[prefix]: - # page_flavors[langdefs.lang_file_name (prefix, e, '.html')] = s subst = dict ([i for i in globals().items() if type (i[1]) is str]) subst.update (dict ([i for i in locals().items() if type (i[1]) is str])) for k in page_flavors.keys(): diff --git a/buildscripts/mass-link.py b/buildscripts/mass-link.py index 61ea81e2db..113495512d 100644 --- a/buildscripts/mass-link.py +++ b/buildscripts/mass-link.py @@ -5,20 +5,23 @@ # # create hard or symbolic links to SOURCEDIR/FILES in DESTDIR # -# if --prepend-suffix is specified, link to foo.bar will be called fooSUFFIX.bar -# shell-wildcard expansion is performed on FILES. - -print "mass_link.py" +# If --prepend-suffix is specified, link to foo.bar will be called fooSUFFIX.bar. +# Shell wildcards expansion is performed on FILES. import sys import os import glob import getopt +print "mass-link.py" + optlist, args = getopt.getopt (sys.argv[1:], '', ['prepend-suffix=']) link_type, source_dir, dest_dir = args[0:3] files = args[3:] +source_dir = os.path.normpath (source_dir) +dest_dir = os.path.normpath (dest_dir) + prepended_suffix = '' for x in optlist: if x[0] == '--prepend-suffix': @@ -46,7 +49,12 @@ sourcefiles = [] for pattern in files: sourcefiles += (glob.glob (os.path.join (source_dir, pattern))) -destfiles = map (lambda f: os.path.join (dest_dir, insert_suffix (os.path.basename (f))), sourcefiles) +def relative_path (f): + if source_dir == '.': + return f + return f[len (source_dir) + 1:] + +destfiles = map (lambda f: os.path.join (dest_dir, insert_suffix (relative_path (f))), sourcefiles) def force_link (src,dest): if os.path.exists (dest): diff --git a/buildscripts/www_post.py b/buildscripts/www_post.py index 39c0747d7e..a61c75961b 100644 --- a/buildscripts/www_post.py +++ b/buildscripts/www_post.py @@ -18,17 +18,21 @@ doc_dirs = ['input', 'Documentation', outdir] target_pattern = os.path.join (outdir, '%s-root') static_files = { - # ugly hack: the following overwrites HTML Info dir with a link to - # the (more useful) documentation index - os.path.join ('Documentation/user', outdir, 'index.html'): - ''' -Redirecting to the documentation index...\n''', os.path.join (outdir, 'index.html'): ''' Redirecting to the documentation index...\n''', os.path.join (outdir, 'VERSION'): package_version + '\n' } +import langdefs + +# ugly hack: the following overwrites HTML Info dir with a link to +# the (more useful) documentation index +for l in langdefs.LANGUAGES: + static_files[os.path.join ('Documentation/user', outdir, l.file_name ('index', '.html'))] = \ + '\nRedirecting to the documentation index...\n' + for f, contents in static_files.items (): open (f, 'w').write (contents) @@ -36,7 +40,6 @@ for f, contents in static_files.items (): sys.path.append (buildscript_dir) import mirrortree import add_html_footer -import langdefs sys.stderr.write ("Mirrorring...\n") dirs, symlinks, files = mirrortree.walk_tree ( diff --git a/make/doclang-targets.make b/make/doclang-targets.make index 30a438692d..c585ab01ab 100644 --- a/make/doclang-targets.make +++ b/make/doclang-targets.make @@ -29,7 +29,7 @@ $(outdir)/%.pdf: $(outdir)/%.texi $(outdir)/user-ln doc-po cd $(outdir); texi2pdf --batch $(TEXINFO_PAPERSIZE_OPTION) $(notdir $*).pdftexi local-WWW: $(outdir)/lilypond.pdf $(outdir)/lilypond/index.html - find $(outdir) -name '*.html' | xargs grep -L --label="" 'UNTRANSLATED NODE: IGNORE ME' | xargs $(PYTHON) $(buildscript-dir)/mass-link.py --prepend-suffix .$(ISOLANG) hard . $(depth)/Documentation/user/$(outdir) $(outdir)/lilypond.pdf + cd $(outdir); find -name '*.html' | xargs grep -L --label="" 'UNTRANSLATED NODE: IGNORE ME' | xargs $(PYTHON) ../$(buildscript-dir)/mass-link.py --prepend-suffix .$(ISOLANG) hard . $(top-build-dir)/Documentation/user/$(outdir) lilypond.pdf # ugh, this is not enough to avoid wasting build time, $(outdir)/user-ln should be touched for all languages touch -mr $(top-build-dir)/Documentation/user/$(outdir) $(outdir)/user-ln -- 2.39.2