use the movers also for copying from temp dir -> export dir

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9153 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2004-11-01 08:50:42 +00:00
parent 9499d9da38
commit e367172256
12 changed files with 216 additions and 54 deletions

View 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:

View 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 = \

View 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

View 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\")"

69
lib/scripts/tex_copy.py Normal file
View File

@ -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)

View 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.

View 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'"),

View 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

View 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.

View 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
}

View 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;
}

View 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_;
};