This patch is now slightly updated. In place of the two scripts tex4html_copy.py and dir_copy.py, there is now just one, ext_copy.py. Without any optional arguments, this script acts like dir_copy.py did: It copies all files in LyX's temporary directory to a subdirectory of the target directory. But now the script takes two optional arguments:
   -e: a list of extensions to copy, by default all
-t: an extension to add to the name of the generated target directory, by default "LyXconv" The idea with the default in the latter case is simply to avoid conflicting filenames. But if, like Uwe, you feel like being reckless ;-), you can do define your HTML copier as:
   python ext_copy.py -e html,css,png -t . $$i $$o
and you'll export to /path/to/filename.html/. Note the use of the dot here.

This new patch will allow easy handling of other converters, such as hevea (and if anyone knows what kinds of files it generates, let me know, and I'll add the definition to configure.py). You just have to say what kinds of files to copy. Of course, in some cases, you may end up copying more than you really needed to copy, but avoiding this is complicated and, to my mind, not entirely necessary, as this remains an exceptional case.

The patch also includes some associated updates to the documentation.

Now seeking an OK to commit.

Richard

--
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto

Index: lib/scripts/ext_copy.py
===================================================================
--- lib/scripts/ext_copy.py	(revision 0)
+++ lib/scripts/ext_copy.py	(revision 0)
@@ -0,0 +1,86 @@
+#! /usr/bin/env python
+# -*- coding: iso-8859-1 -*-
+
+# file tex_copy.py
+# This file is part of LyX, the document processor.
+# Licence details can be found in the file COPYING.
+
+# author Richard Heck
+
+# Full author contact details are available in file CREDITS
+
+# Usage:
+# ext_copy.py [-e ext1,ext2,...] <from file> <to file>
+
+# This script is to be used as a "copier" script in the sense needed by
+# the converter definitions. Given a <from file> and <to file>, it will copy
+# all files in the directory in which from_file is found that have the 
+# extensions given in the -e argument, or all files that directory if no such 
+# argument is given. So, for example, we can do:
+#   python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
+# and all html, png, and css files in /path/from/ will be copied to the 
+# (possibly new) directory /path/to/file.html.LyXconv/.
+# The -t argument determines the extension added, the default being "LyXconv".
+# If just . is given, no extension is added.
+
+import os, sys, getopt
+from lyxpreview_tools import error
+
+
+def usage(prog_name):
+    return "Usage: %s [-e extensions] [-t target extension] <from file> <to file>" % prog_name
+
+
+def main(argv):
+    progname = argv[0]
+
+    exts = [] #list of extensions for which we're checking
+    targext = "LyXconv" #extension for target directory
+    opts, args = getopt.getopt(sys.argv[1:], "e:t:")
+    for o, v in opts:
+      if o == "-e":
+        exts = v.split(',')
+      if o == "-t":
+        targext = v
+
+    # input directory
+    if len(args) != 2:
+      error(usage(progname))
+    abs_from_file = args[0]
+    if not os.path.isabs(abs_from_file):
+      error("%s is not an absolute file name.\n%s" % abs_from_file, usage(progname))
+    from_dir = os.path.dirname(abs_from_file)
+
+    # output directory
+    to_dir = args[1]
+    if targext != '.':
+      to_dir += "." + targext
+    if not os.path.isabs(to_dir):
+      error("%s is not an absolute file name.\n%s" % to_dir, usage(progname))
+
+    # try to create the output directory if it doesn't exist
+    if not os.path.isdir(to_dir):
+      try:
+        os.makedirs(to_dir)
+      except:
+        error("Unable to create %s" % to_dir)
+
+    import shutil
+
+    # copy all matching files in from_dir to to_dir
+    for file in os.listdir(from_dir):
+      junk, ext = os.path.splitext(os.path.basename(file))
+      ext = ext.lower()[1:] #strip the leading dot
+      try:
+        # if exts is empty we ignore it
+        # otherwise check if the extension is in the list
+        not exts or exts.index(ext)
+      except:
+        continue #not found
+      from_file = os.path.join(from_dir, file)
+      to_file  = os.path.join(to_dir, file)
+      shutil.copy(from_file, to_file)
+    return 0
+
+if __name__ == "__main__":
+    main(sys.argv)
Index: lib/configure.py
===================================================================
--- lib/configure.py	(revision 18769)
+++ lib/configure.py	(working copy)
@@ -347,8 +347,19 @@
     checkProg('an MS Word -> LaTeX converter', ['wvCleanLatex $$i $$o'],
         rc_entry = [ r'\converter word       latex      "%%"	""' ])
     #
-    checkProg('a LaTeX -> MS Word converter', ["htlatex $$i 'html,word' 'symbol/!' '-cvalidate'"],
+    path, htmlconv = checkProg('a LaTeX -> HTML converter', ['htlatex $$i', 'tth  -t -e2 -L$$b < $$i > $$o', \
+        'latex2html -no_subdir -split 0 -show_section_numbers $$i', 'hevea -s $$i'],
+        rc_entry = [ r'\converter latex      html       "%%"	"needaux"' ])
+    if htmlconv == 'htlatex':
+      addToRC(r'''\copier    html       "python -tt $$s/scripts/ext_copy.py -e html,png,css $$i $$o"''')
+    else:
+      addToRC(r'''\copier    html       "python -tt $$s/scripts/ext_copy.py $$i $$o"''')
+
+    #
+    path, htmlconv = checkProg('a LaTeX -> MS Word converter', ["htlatex $$i 'html,word' 'symbol/!' '-cvalidate'"],
         rc_entry = [ r'\converter latex      wordhtml   "%%"	"needaux"' ])
+    if htmlconv == 'htlatex':
+      addToRC(r'''\copier    wordhtml       "python -tt $$s/scripts/ext_copy.py -e html,png,css $$i $$o"''')
     #
     checkProg('an OpenOffice.org -> LaTeX converter', ['w2l -clean $$i'],
         rc_entry = [ r'\converter sxw        latex      "%%"	""' ])
@@ -358,10 +369,6 @@
     #
     checkProg('a LaTeX -> Open Document converter', ['oolatex $$i', 'oolatex.sh $$i'],
         rc_entry = [ r'\converter latex      odt        "%%"	"latex"' ])
-    #
-    #FIXME Looking for the commands needed to make oolatex output sxw instad of odt...
-    #checkProg('a LaTeX -> OpenOffice.org (sxw) converter', ['oolatex $$i', 'oolatex.sh $$i'],
-    #    rc_entry = [ r'\converter latex      odt        "%%"	"latex"' ])
     # On windows it is called latex2rt.exe
     checkProg('a LaTeX -> RTF converter', ['latex2rtf -p -S -o $$o $$i', 'latex2rt -p -S -o $$o $$i'],
         rc_entry = [ r'\converter latex      rtf        "%%"	"needaux"' ])
@@ -429,9 +436,6 @@
 \converter agr        ppm        "gracebat -hardcopy -printfile $$o -hdevice PNM $$i 2>/dev/null"	""''',
             ''])
     #
-    checkProg('a LaTeX -> HTML converter', ['htlatex $$i', 'tth  -t -e2 -L$$b < $$i > $$o', \
-        'latex2html -no_subdir -split 0 -show_section_numbers $$i', 'hevea -s $$i'],
-        rc_entry = [ r'\converter latex      html       "%%"	"needaux"' ])
     #
     path, lilypond = checkProg('a LilyPond -> EPS/PDF/PNG converter', ['lilypond'])
     if (lilypond != ''):
Index: lib/doc/Customization.lyx
===================================================================
--- lib/doc/Customization.lyx	(revision 18769)
+++ lib/doc/Customization.lyx	(working copy)
@@ -1,5 +1,5 @@
 #LyX 1.5.0svn created this file. For more info see http://www.lyx.org/
-\lyxformat 271
+\lyxformat 274
 \begin_document
 \begin_header
 \textclass book
@@ -1961,7 +1961,7 @@
 references:Copiers
 \family default
  dialog.
- Since all conversions from one Format to another take place in a temporary
+ Since all conversions from one Format to another take place in LyX's temporary
  directory, it is sometimes necessary to modify a file before copying it
  to the temporary directory in order that the conversion may be performed.
 \begin_inset Foot
@@ -1977,8 +1977,70 @@
 
  This is done by the Copier: It copies a file to (or from) the temporary
  directory and may modify it in the process.
+ 
 \end_layout
 
+\begin_layout Standard
+Copiers may also be used for other purposes.
+ For example, if appropriate converters are found, LyX will automatically
+ install copiers for the html and wordhtml formats.
+ When these formats are exported, the copier sees to it that not just the
+ main HTML file but various associated files (style files, images, and the
+ like) are also copied, and all these files are written to a subdirectory
+ of the directory in which the original LyX file was found.
+ The copier may of course be customized.
+ The optional -e argument takes a comma-separated list of extensions to
+ be copied; if it is omitted, all files will be copied.
+ The -t argument determines the extension added to the generated directory.
+ By default, it is 
+\begin_inset Quotes eld
+\end_inset
+
+LyXconv
+\begin_inset Quotes erd
+\end_inset
+
+, so HTML generated from 
+\family typewriter
+/path/to/filename.lyx
+\family default
+ will end up in 
+\family typewriter
+/path/to/filename.html.LyXconv
+\family default
+.
+ 
+\end_layout
+
+\begin_layout Standard
+The definitions of the copiers may use three variables:
+\end_layout
+
+\begin_layout List
+\labelwidthstring 00.00.0000
+$$i The input file
+\end_layout
+
+\begin_layout List
+\labelwidthstring 00.00.0000
+$$o The output file
+\end_layout
+
+\begin_layout List
+\labelwidthstring 00.00.0000
+$$l The `LaTeX name'
+\end_layout
+
+\begin_layout Standard
+The latter is to be given in a form suitable for inclusion in a LaTeX 
+\family typewriter
+
+\backslash
+include
+\family default
+ command.
+\end_layout
+
 \begin_layout Subsection
 Converters
 \end_layout
Index: development/scons/scons_manifest.py
===================================================================
--- development/scons/scons_manifest.py	(revision 18769)
+++ development/scons/scons_manifest.py	(working copy)
@@ -2729,6 +2729,7 @@
     clean_dvi.py
     convertDefault.py
     date.py
+    ext_copy.py
     fen2ascii.py
     fig2pdftex.py
     fig2pstex.py
Index: lib/Makefile.am
===================================================================
--- lib/Makefile.am	(revision 18769)
+++ lib/Makefile.am	(working copy)
@@ -1017,6 +1017,7 @@
 	scripts/clean_dvi.py \
 	scripts/convertDefault.py \
 	scripts/date.py \
+	scripts/ext_copy.py \
 	scripts/fen2ascii.py \
 	scripts/fig2pdftex.py \
 	scripts/fig2pstex.py \

Reply via email to