return string();
ostringstream command;
- command << "fromfile = " << from_file << "\n"
- << "tofile = " << to_file << "\n\n"
+ command << "fromfile = utf8ToDefaultEncoding(" << from_file << ")\n"
+ << "tofile = utf8ToDefaultEncoding(" << to_file << ")\n\n"
<< "try:\n"
<< " os.rename(fromfile, tofile)\n"
<< "except:\n"
// If this occurs, move ${outfile}.0 to ${outfile}
// and delete ${outfile}.? (ignore errors)
script << "if not os.path.isfile(outfile):\n"
- " if os.path.isfile(outfile + '.0'):\n"
- " os.rename(outfile + '.0', outfile)\n"
- " import glob\n"
- " for file in glob.glob(outfile + '.?'):\n"
- " unlinkNoThrow(file)\n"
- " else:\n"
- " sys.exit(1)\n\n";
+ " if os.path.isfile(outfile + '.0'):\n"
+ " os.rename(outfile + '.0', outfile)\n"
+ " import glob\n"
+ " for file in glob.glob(outfile + '.?'):\n"
+ " unlinkNoThrow(file)\n"
+ " else:\n"
+ " sys.exit(1)\n\n";
// Delete the infile
script << "unlinkNoThrow(infile)\n\n";
typedef Converters::EdgePath EdgePath;
script << "#!/usr/bin/env python\n"
- "# -*- coding: utf-8 -*-\n"
- "import os, shutil, sys, locale\n\n"
- "def unlinkNoThrow(file):\n"
- " ''' remove a file, do not throw if an error occurs '''\n"
- " try:\n"
- " os.unlink(file)\n"
- " except:\n"
- " pass\n\n"
- "def utf8ToDefaultEncoding(file):\n"
- " ''' if possible, convert to the default encoding '''\n"
- " try:\n"
- " language, output_encoding = locale.getdefaultlocale()\n"
- " if output_encoding == None:\n"
- " output_encoding = 'latin1'\n"
- " return unicode(file, 'utf8').encode(output_encoding)\n"
- " except:\n"
- " return file\n\n";
+ "# -*- coding: utf-8 -*-\n"
+ "import os, shutil, sys, locale\n\n"
+ "def unlinkNoThrow(file):\n"
+ " ''' remove a file, do not throw if an error occurs '''\n"
+ " try:\n"
+ " os.unlink(file)\n"
+ " except:\n"
+ " pass\n\n"
+ "def utf8ToDefaultEncoding(file):\n"
+ " ''' if possible, convert to the default encoding '''\n"
+ " try:\n"
+ " language, output_encoding = locale.getdefaultlocale()\n"
+ " if output_encoding == None:\n"
+ " output_encoding = 'latin1'\n"
+ " return unicode(file, 'utf8').encode(output_encoding)\n"
+ " except:\n"
+ " return file\n\n";
// we do not use ChangeExtension because this is a basename
// which may nevertheless contain a '.'
script << "infile = utf8ToDefaultEncoding("
<< quoteName(from_file.absFilename(), quote_python)
<< ")\n"
- "outfile = " << quoteName(outfile, quote_python) << "\n"
- "shutil.copy(infile, outfile)\n";
+ "outfile = utf8ToDefaultEncoding("
+ << 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";
+ script << "os.chdir(utf8ToDefaultEncoding("
+ << 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, quote_python)
- << '\n';
+ << "outfile = utf8ToDefaultEncoding("
+ << quoteName(to_file, quote_python) << ")\n";
ostringstream os;
os << support::os::python() << ' '
<< libScriptSearch("$$s/scripts/convertDefault.py",
- quote_python) << ' ';
+ quote_python) << ' ';
if (!from_format.empty())
os << from_format << ':';
// The extra " quotes around infile and outfile are needed
outfile = addExtension(to_base.absFilename(), conv.To->extension());
// Store these names in the python script
- script << "infile = " << quoteName(infile, quote_python) << "\n"
- "infile_base = " << quoteName(infile_base, quote_python) << "\n"
- "outfile = " << quoteName(outfile, quote_python) << '\n';
+ script << "infile = utf8ToDefaultEncoding("
+ << quoteName(infile, quote_python) << ")\n"
+ "infile_base = utf8ToDefaultEncoding("
+ << quoteName(infile_base, quote_python) << ")\n"
+ "outfile = utf8ToDefaultEncoding("
+ << quoteName(outfile, quote_python) << ")\n";
// See comment about extra " quotes above (although that
// applies only for the first loop run here).