using support::onlyPath;
using support::onlyFilename;
using support::quoteName;
+using support::quote_python;
using support::subst;
using support::tempName;
using support::unlink;
return pimpl_->finished_ ? pimpl_->to_file_ : empty;
}
-} // namespace graphics
-} // namespace lyx
-
-
-//------------------------------
-// Implementation details follow
-//------------------------------
-
-namespace {
-
/** Build the conversion script.
* The script is output to the stream \p script.
*/
-void build_script(string const & from_file, string const & to_file_base,
+static void build_script(string const & from_file, string const & to_file_base,
string const & from_format, string const & to_format,
ostream & script);
-} // namespace anon
-
-
-namespace lyx {
-namespace graphics {
Converter::Impl::Impl(string const & from_file, string const & to_file_base,
string const & from_format, string const & to_format)
}
}
-} // namespace graphics
-} // namespace lyx
-
-namespace {
-string const move_file(string const & from_file, string const & to_file)
+static string const move_file(string const & from_file, string const & to_file)
{
if (from_file == to_file)
return string();
}
-void build_conversion_command(string const & command, ostream & script)
+static void build_conversion_command(string const & command, ostream & script)
{
// Store in the python script
script << "\nif os.system(r'" << command << "') != 0:\n";
}
-void build_script(string const & from_file,
+static void build_script(string const & from_file,
string const & to_file_base,
string const & from_format,
string const & to_format,
// in python, but the converters might be shell scripts and have more
// troubles with it.
string outfile = changeExtension(to_base, getExtension(from_file));
- script << "infile = '"
- << subst(subst(from_file, "\\", "\\\\"), "'", "\\'") << "'\n"
- "outfile = " << quoteName(outfile) << "\n"
+ script << "infile = " << quoteName(from_file, quote_python) << "\n"
+ "outfile = " << quoteName(outfile, quote_python) << "\n"
"shutil.copy(infile, outfile)\n";
+ // Some converters (e.g. lilypond) can only output files to the
+ // current directory, so we need to change the current directory.
+ // This has the added benefit that all other files that may be
+ // generated by the converter are deleted when LyX closes and do not
+ // clutter the real working directory.
+ script << "os.chdir(" << quoteName(onlyPath(outfile)) << ")\n";
+
if (edgepath.empty()) {
// Either from_format is unknown or we don't have a
// converter path from from_format to to_format, so we use
// the default converter.
script << "infile = outfile\n"
- << "outfile = " << quoteName(to_file) << '\n';
+ << "outfile = " << quoteName(to_file, quote_python)
+ << '\n';
ostringstream os;
- os << support::os::python() << " \""
- << libFileSearch("scripts", "convertDefault.py") << "\" ";
+ os << support::os::python() << ' '
+ << libScriptSearch("$$s/scripts/convertDefault.py",
+ quote_python) << ' ';
if (!from_format.empty())
os << from_format << ':';
+ // The extra " quotes around infile and outfile are needed
+ // because the filename may contain spaces and it is used
+ // as argument of os.system().
os << "' + '\"' + infile + '\"' + ' "
<< to_format << ":' + '\"' + outfile + '\"' + '";
string const command = os.str();
EdgePath::const_iterator end = edgepath.end();
for (; it != end; ++it) {
- ::Converter const & conv = converters.get(*it);
+ lyx::Converter const & conv = converters.get(*it);
// Build the conversion command
string const infile = outfile;
outfile = changeExtension(to_base, conv.To->extension());
// Store these names in the python script
- script << "infile = " << quoteName(infile) << '\n'
- << "infile_base = " << quoteName(infile_base) << '\n'
- << "outfile = " << quoteName(outfile) << '\n';
+ script << "infile = " << quoteName(infile, quote_python) << "\n"
+ "infile_base = " << quoteName(infile_base, quote_python) << "\n"
+ "outfile = " << quoteName(outfile, quote_python) << '\n';
+ // See comment about extra " quotes above (although that
+ // applies only for the first loop run here).
string command = conv.command;
command = subst(command, token_from, "' + '\"' + infile + '\"' + '");
command = subst(command, token_base, "' + '\"' + infile_base + '\"' + '");
command = subst(command, token_to, "' + '\"' + outfile + '\"' + '");
- command = libScriptSearch(command);
+ command = libScriptSearch(command, quote_python);
build_conversion_command(command, script);
}
// Move the final outfile to to_file
- script << move_file("outfile", quoteName(to_file));
+ script << move_file("outfile", quoteName(to_file, quote_python));
lyxerr[Debug::GRAPHICS] << "ready!" << endl;
}
-} // namespace anon
+} // namespace graphics
+
+} // namespace lyx