]> git.lyx.org Git - features.git/commitdiff
use the movers also for copying from temp dir -> export dir
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 1 Nov 2004 08:50:42 +0000 (08:50 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 1 Nov 2004 08:50:42 +0000 (08:50 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9153 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
lib/ChangeLog
lib/Makefile.am
lib/configure.m4
lib/external_templates
lib/scripts/tex_copy.py [new file with mode: 0644]
src/ChangeLog
src/exporter.C
src/exporter.h
src/insets/ChangeLog
src/insets/ExternalSupport.C
src/mover.C
src/mover.h

index a933f48ad671d2a29997e4566c882dce0132565e..8bd9afe3f20e56d7dfae8b5a3d136e1b482ea30b 100644 (file)
@@ -1,3 +1,10 @@
+2004-11-01  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * configure.m4: add copier for pstex_t and pdftex_t files
+       * external_templates: (Template XFig): correct referenced files
+       * scripts/tex_copy.py: new
+       * Makefile.am: add scripts/tex_copy.py
+
 2004-10-30  José Matos  <jamatos@lyx.org>
 
        * db_stdclasses.inc:
index cc2acbeab751715a886f851420eb12634bca553f..c0387616bb73fbc9d242d6e19c475d6e9ff187fa 100644 (file)
@@ -861,7 +861,8 @@ dist_scripts_SCRIPTS = \
        scripts/fig2pstex.sh \
        scripts/listerrors \
        scripts/legacy_lyxpreview2ppm.py \
-       scripts/lyxpreview2bitmap.py
+       scripts/lyxpreview2bitmap.py \
+       scripts/tex_copy.py
 
 templatesdir = $(pkgdatadir)/templates
 dist_templates_DATA = \
index 232b829bfb2a8ca9e40f0269f5e8d699701022cb..ad2af1dae87d27dad5e440a546dc1a594caa1249 100644 (file)
@@ -587,8 +587,6 @@ cat >$outfile <<EOF
 \\converter ps         fax        "$fax_command"       ""
 \\converter ps         pdf        "$ps_to_pdf_command" ""
 \\converter word       latex      "$word_to_latex_command"     ""
-
-\\copier    fig        "sh \$\$s/fig_copy.sh \$\$i \$\$o"
 EOF
 
 ### the graphic converter part with the predefined ones
@@ -638,6 +636,10 @@ fi
 
 cat >>$outfile <<EOF
 
+\\copier    fig        "sh \$\$s/fig_copy.sh \$\$i \$\$o"
+\\copier    pstex      "python \$\$s/tex_copy.py \$\$i \$\$o \$\$l"
+\\copier    pdftex     "python \$\$s/tex_copy.py \$\$i \$\$o \$\$l"
+
 $rc_entries
 \\font_encoding "$chk_fontenc"
 EOF
index 651d7e6a587eb27961abbaf641a1b2eda673f8f6..c552511a4618d16392e67af3c946440cd78b4bd0 100644 (file)
@@ -121,9 +121,9 @@ Template XFig
                Requirement "graphicx"
                # Preamble WarnNotFound
                # Preamble InputOrWarn
-               ReferencedFile latex "$$AbsPath$$Basename.pstex_t"
-               ReferencedFile latex "$$AbsPath$$Basename.pstex"
-               ReferencedFile dvi   "$$AbsPath$$Basename.pstex"
+               ReferencedFile latex "$$AbsOrRelPathMaster$$Basename.pstex_t"
+               ReferencedFile latex "$$AbsPath$$Basename.eps"
+               ReferencedFile dvi   "$$AbsPath$$Basename.eps"
        FormatEnd
        Format PDFLaTeX
                TransformCommand Rotate RotationLatexCommand
@@ -134,8 +134,8 @@ Template XFig
                Requirement "graphicx"
                # Preamble WarnNotFound
                # Preamble InputOrWarn
-               ReferencedFile latex "$$AbsPath$$Basename.pdftex_t"
-               ReferencedFile latex "$$AbsPath$$Basename.pdftex"
+               ReferencedFile latex "$$AbsOrRelPathMaster$$Basename.pdftex_t"
+               ReferencedFile latex "$$AbsPath$$Basename.pdf"
        FormatEnd
        Format Ascii
                Product "$$Contents(\"$$AbsPath$$Basename.asc\")"
diff --git a/lib/scripts/tex_copy.py b/lib/scripts/tex_copy.py
new file mode 100644 (file)
index 0000000..6c634c1
--- /dev/null
@@ -0,0 +1,69 @@
+#! /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 Angus Leeming
+# author Georg Baum
+
+# Full author contact details are available in file CREDITS
+
+# Usage:
+# tex_copy.py from file> <to file> <latex name>
+
+# This script will copy a file <from file> to <to file>.
+# <to file> is no exact copy of <from file>, but any occurence of <basename>
+# where <basename> is <from file> without directory and extension parts is
+# replaced by <latex name> without extension.
+
+
+import os, string, sys
+
+from lyxpreview_tools import error
+
+
+def usage(prog_name):
+    return "Usage: %s <from file> <to file> <latex name>" % prog_name
+
+
+def main(argv):
+    # Parse and manipulate the command line arguments.
+    if len(argv) != 4:
+        error(usage(argv[0]))
+
+    # input file
+    abs_from_file = argv[1]
+    if not os.path.isabs(abs_from_file):
+        error("%s is no absolute file name.\n%s"\
+              % abs_from_file, usage(argv[0]))
+    from_dir, rel_from_file = os.path.split(abs_from_file)
+    from_base, from_ext = os.path.splitext(rel_from_file)
+
+    # output file
+    abs_to_file = argv[2]
+    if not os.path.isabs(abs_to_file):
+        error("%s is no absolute file name.\n%s"\
+              % abs_to_file, usage(argv[0]))
+    to_dir, rel_to_file = os.path.split(abs_to_file)
+    to_base, to_ext = os.path.splitext(rel_to_file)
+
+    # latex file name
+    latex_file = argv[3]
+    latex_base, latex_ext = os.path.splitext(latex_file)
+
+    # Read the input file and write the output file
+    from_file = open(abs_from_file, 'rb')
+    to_file = open(abs_to_file, 'wb')
+    lines = from_file.readlines()
+    for line in lines:
+        to_file.write(line.replace(from_base, latex_base))
+    from_file.close()
+    to_file.close()
+
+    return 0
+
+
+if __name__ == "__main__":
+    main(sys.argv)
index fa4973e95023bed59d267bd6c301f6b51414df54..543c5d7a8578d8053d983c8f4b6d38550f18cfa9 100644 (file)
@@ -1,3 +1,10 @@
+2004-11-01  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * exporter.C (copyFile): use the mover instead of support::copy()
+       * exporter.C (Export): pass format and latex name to copyFile()
+       * exporter.h (addExternalFile): document
+       * mover.[Ch] (do_copy, do_rename): new methods with 3 arguments
+
 2004-10-31  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * text.C (leftMargin): do not indent paragraphs in charstyle insets.
index bf270b5ba7be84af449f5d8b83e1ee1fdf92ec42..1c12aa2d2fd723ace7bbdba4828bd9f537a48ebc 100644 (file)
@@ -25,6 +25,7 @@
 #include "format.h"
 #include "gettext.h"
 #include "lyxrc.h"
+#include "mover.h"
 #include "output_plaintext.h"
 #include "outputparams.h"
 #include "frontends/Alert.h"
@@ -38,6 +39,7 @@ using lyx::support::AddName;
 using lyx::support::bformat;
 using lyx::support::ChangeExtension;
 using lyx::support::contains;
+using lyx::support::getFormatFromContents;
 using lyx::support::MakeAbsPath;
 using lyx::support::MakeDisplayPath;
 using lyx::support::OnlyFilename;
@@ -92,8 +94,9 @@ enum CopyStatus {
  *            overwriting files anymore.
  *  - CANCEL  if the export should be cancelled
  */
-CopyStatus copyFile(string const & sourceFile, string const & destFile,
-                   bool force)
+CopyStatus copyFile(string const & format,
+                    string const & sourceFile, string const & destFile,
+                    string const & latexFile, bool force)
 {
        CopyStatus ret = force ? FORCE : SUCCESS;
 
@@ -117,7 +120,8 @@ CopyStatus copyFile(string const & sourceFile, string const & destFile,
                }
        }
 
-       if (!lyx::support::copy(sourceFile, destFile))
+       Mover const & mover = movers(format);
+       if (!mover.copy(sourceFile, destFile, latexFile))
                Alert::error(_("Couldn't copy file"),
                             bformat(_("Copying %1$s to %2$s failed."),
                                     MakeDisplayPath(sourceFile),
@@ -203,15 +207,18 @@ bool Exporter::Export(Buffer * buffer, string const & format,
                string const dest = OnlyPath(result_file);
                CopyStatus status = SUCCESS;
                for (vector<ExportedFile>::const_iterator it = files.begin();
-                               it != files.end() && status != CANCEL; ++it)
-                       status = copyFile(it->sourceName,
+                               it != files.end() && status != CANCEL; ++it) {
+                       string const fmt = getFormatFromContents(it->sourceName);
+                       status = copyFile(fmt, it->sourceName,
                                          MakeAbsPath(it->exportName, dest),
-                                         status == FORCE);
+                                         it->exportName, status == FORCE);
+               }
                if (status == CANCEL) {
                        buffer->message(_("Document export cancelled."));
                } else {
                        // Finally copy the main file
-                       status = copyFile(tmp_result_file, result_file,
+                       status = copyFile(format, tmp_result_file,
+                                         result_file, result_file,
                                          status == FORCE);
                        buffer->message(bformat(_("Document exported as %1$s"
                                                  "to file `%2$s'"),
index 0cdbd4e96e4801f21d78d4b5d804851a2717ac0d..1f912a6f5b2257987e763d9cb8caf0408306fecb 100644 (file)
@@ -66,15 +66,24 @@ public:
         *  with this method.
         *  Then the exporter mechanism copies them to the right place, asks
         *  for confirmation before overwriting existing files etc.
+        * \param format     format that references the given file
+        * \param sourceName source file name. Needs to be absolute
+        * \param exportName resulting file name. Can be either absolute
+        *                   or relative to the exported document.
         */
-       void addExternalFile(std::string const &, std::string const &,
-                            std::string const &);
-       /// add a referenced file for one format.
-       /// The final name is the source file name without path
-       void addExternalFile(std::string const &, std::string const &);
-       /// get referenced files for one format
+       void addExternalFile(std::string const & format,
+                            std::string const & sourceName,
+                            std::string const & exportName);
+       /** add a referenced file for one format.
+        *  The final name is the source file name without path.
+        * \param format     format that references the given file
+        * \param sourceName source file name. Needs to be absolute
+        */
+       void addExternalFile(std::string const & format,
+                            std::string const & sourceName);
+       /// get referenced files for \p format
        std::vector<ExportedFile> const
-       externalFiles(std::string const &) const;
+       externalFiles(std::string const & format) const;
 private:
        typedef std::map<std::string, std::vector<ExportedFile> > FileMap;
        /** Files that are referenced by the export result in the
index a9bcff86e455e9aad0b5caa5b22ade642e35b594..f1e5193cc3d28187b7b4724e6a1cc612c9d8341b 100644 (file)
@@ -1,3 +1,7 @@
+2004-11-01  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * ExternalSupport.C (updateExternal): convert files in the temp dir
+
 2004-10-31  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * insetcharstyle.C: drawing cosmetics.
index b60fee1f02106403d50503fbe43a43bf0508b377..c2ea3fa767a6f2bf6b4333b79cf8f2ae81e8948c 100644 (file)
@@ -196,11 +196,12 @@ void updateExternal(InsetExternalParams const & params,
        // of include files
        Buffer const * m_buffer = buffer.getMasterBuffer();
 
-       if (external_in_tmpdir && !abs_from_file.empty()) {
-               // We are running stuff through LaTeX
-               string const temp_file =
-                       support::MakeAbsPath(params.filename.mangledFilename(),
-                                            m_buffer->temppath());
+       // We copy the source file to the temp dir and do the conversion
+       // there if necessary
+       string const temp_file =
+               support::MakeAbsPath(params.filename.mangledFilename(),
+                                    m_buffer->temppath());
+       if (!abs_from_file.empty()) {
                unsigned long const from_checksum = support::sum(abs_from_file);
                unsigned long const temp_checksum = support::sum(temp_file);
 
@@ -214,20 +215,17 @@ void updateExternal(InsetExternalParams const & params,
                                return; // FAILURE
                        }
                }
-
-               abs_from_file = temp_file;
        }
 
+       // the generated file (always in the temp dir)
        string const to_file = doSubstitution(params, buffer,
                                              outputFormat.updateResult,
-                                             external_in_tmpdir);
-
+                                             true);
        string const abs_to_file =
-               support::MakeAbsPath(to_file, external_in_tmpdir
-                       ? m_buffer->temppath()
-                       : buffer.filePath());
+               support::MakeAbsPath(to_file, m_buffer->temppath());
 
-       // record the referenced files for the exporter
+       // Record the referenced files for the exporter.
+       // The exporter will copy them to the export dir.
        typedef Template::Format::FileMap FileMap;
        FileMap::const_iterator rit  = outputFormat.referencedFiles.begin();
        FileMap::const_iterator rend = outputFormat.referencedFiles.end();
@@ -235,22 +233,27 @@ void updateExternal(InsetExternalParams const & params,
                vector<string>::const_iterator fit  = rit->second.begin();
                vector<string>::const_iterator fend = rit->second.end();
                for (; fit != fend; ++fit) {
+                       string const source = support::MakeAbsPath(
+                                       doSubstitution(params, buffer, *fit,
+                                                      true),
+                                       m_buffer->temppath());
                        string const file = doSubstitution(params, buffer,
                                                           *fit,
                                                           external_in_tmpdir);
-                       exportdata.addExternalFile(rit->first, file);
+                       // if file is a relative name, it is interpreted
+                       // relative to the master document.
+                       exportdata.addExternalFile(rit->first, source, file);
                }
        }
 
        // Do we need to perform the conversion?
        // Yes if to_file does not exist or if from_file is newer than to_file
-       if (support::compare_timestamps(abs_from_file, abs_to_file) < 0)
+       if (support::compare_timestamps(temp_file, abs_to_file) < 0)
                return; // SUCCESS
-
        string const to_file_base =
                support::ChangeExtension(to_file, string());
        /* bool const success = */
-               converters.convert(&buffer, abs_from_file, to_file_base,
+               converters.convert(&buffer, temp_file, to_file_base,
                                   from_format, to_format);
        // return success
 }
index a646f49478ce8d28923a131fceec26d398d4fcb9..4ffb3458fde4676549aa92ef2d96488ab4609e7f 100644 (file)
@@ -26,38 +26,43 @@ Movers movers;
 Movers system_movers;
 
 
-bool Mover::do_copy(string const & from, string const & to) const
+bool Mover::do_copy(string const & from, string const & to,
+                    string const &) const
 {
        return support::copy(from, to);
 }
 
 
-bool Mover::do_rename(string const & from, string const & to) const
+bool Mover::do_rename(string const & from, string const & to,
+                      string const &) const
 {
        return support::rename(from, to);
 }
 
 
-bool SpecialisedMover::do_copy(string const & from, string const & to) const
+bool SpecialisedMover::do_copy(string const & from, string const & to,
+                               string const & latex) const
 {
        if (command_.empty())
-               return Mover::do_copy(from, to);
+               return Mover::do_copy(from, to, latex);
 
        string command = support::LibScriptSearch(command_);
        command = support::subst(command, "$$i", from);
        command = support::subst(command, "$$o", to);
+       command = support::subst(command, "$$l", latex);
 
        support::Systemcall one;
        return one.startscript(support::Systemcall::Wait, command) == 0;
 }
 
 
-bool SpecialisedMover::do_rename(string const & from, string const & to) const
+bool SpecialisedMover::do_rename(string const & from, string const & to,
+                                 string const & latex) const
 {
        if (command_.empty())
-               return Mover::do_rename(from, to);
+               return Mover::do_rename(from, to, latex);
 
-       if (!do_copy(from, to))
+       if (!do_copy(from, to, latex))
                return false;
        return support::unlink(from) == 0;
 }
index 3e807536016139cf935b9deae4dfc80eb5021819..153a20ba89f8871407340f862913524c1758e7ea 100644 (file)
@@ -25,29 +25,67 @@ public:
        virtual ~Mover() {}
 
        /** Copy file @c from to @c to.
+        *  This version should be used to copy files from the original
+        *  location to the temporary directory, since @c to and @c latex
+        *  would be equal in this case.
         *  \returns true if successful.
         */
        bool
        copy(std::string const & from, std::string const & to) const
        {
-               return do_copy(from, to);
+               return do_copy(from, to, to);
+       }
+
+       /** Copy file @c from to @c to.
+        *  \see SpecialisedMover::SpecialisedMover() for an explanation of
+        *  @c latex.
+        *  This version should be used to copy files from the temporary
+        *  directory to the export location, since @c to and @c latex may
+        *  not be equal in this case.
+        *  \returns true if successful.
+        */
+       bool
+       copy(std::string const & from, std::string const & to,
+            std::string const & latex) const
+       {
+               return do_copy(from, to, latex);
        }
 
        /** Rename file @c from as @c to.
+        *  This version should be used to move files from the original
+        *  location to the temporary directory, since @c to and @c latex
+        *  would be equal in this case.
         *  \returns true if successful.
         */
        bool
        rename(std::string const & from, std::string const & to) const
        {
-               return do_rename(from, to);
+               return do_rename(from, to, to);
+       }
+
+       /** Rename file @c from as @c to.
+        *  \see SpecialisedMover::SpecialisedMover() for an explanation of
+        *  @c latex.
+        *  This version should be used to move files from the temporary
+        *  directory to the export location, since @c to and @c latex may
+        *  not be equal in this case.
+        *  \returns true if successful.
+        */
+       bool
+       rename(std::string const & from, std::string const & to,
+              std::string const & latex) const
+       {
+               return do_rename(from, to, latex);
        }
 
 protected:
        virtual bool
-       do_copy(std::string const & from, std::string const & to) const;
+       do_copy(std::string const & from, std::string const & to,
+               std::string const &) const;
 
        virtual bool
-       do_rename(std::string const & from, std::string const & to) const;
+       do_rename(std::string const & from, std::string const & to,
+                 std::string const &) const;
 };
 
 
@@ -66,11 +104,19 @@ struct SpecialisedMover : public Mover
 
        /** @c command should be of the form
         *  <code>
-        *      sh $$s/copy_fig.sh $$i $$o
+        *      sh $$s/copy_fig.sh $$i $$o $$l
         *  </code>
         *  where $$s is a placeholder for the lyx script directory,
         *        $$i is a placeholder for the name of the file to be moved,
-        *        $$o is a placeholder for the name of the file after moving.
+        *        $$o is a placeholder for the name of the file after moving,
+        *        $$l is a placeholder for the name of the file after moving,
+        *        suitable as argument to a latex include command. This is
+        *        either an absolute filename or relative to the master
+        *        document.
+        *        $$o and $$l can only differ if the file is copied from the
+        *        temporary directory to the export location. If it is copied
+        *        from the original location to the temporary directory, they
+        *        are the same, so $$l may be ommitted in this case.
         */
        SpecialisedMover(std::string const & command)
                : command_(command) {}
@@ -80,10 +126,12 @@ struct SpecialisedMover : public Mover
 
 private:
        virtual bool
-       do_copy(std::string const & from, std::string const & to) const;
+       do_copy(std::string const & from, std::string const & to,
+               std::string const & latex) const;
 
        virtual bool
-       do_rename(std::string const & from, std::string const & to) const;
+       do_rename(std::string const & from, std::string const & to,
+                 std::string const & latex) const;
 
        std::string command_;
 };