Am Samstag, 12. August 2006 00:46 schrieb Jean-Marc Lasgouttes: > >>>>> "Georg" == Georg Baum <[EMAIL PROTECTED]> writes: > > Georg> Here comes my long promised fix for bug 2637 (graphics files > Georg> with ' in the name can't be previewed). > > Georg, do you think this should go to 1.4?
Yes. The backported patch looks like this. When testing this I noticed however that the bug is only fixed in the case convertDefault.py is not used, so I'd rather like to fix that in 1.5 first. My idea is to move all special casing for convertDefault.py to Converters::getPath. Converters::getPath would then get an additional bool argument try_default (like Converters::convert already has). convertDefault.py is then simply added as a normal converter to the path if this flag is true. Comments? Georg
Index: src/graphics/GraphicsCacheItem.C =================================================================== --- src/graphics/GraphicsCacheItem.C (Revision 14622) +++ src/graphics/GraphicsCacheItem.C (Arbeitskopie) @@ -427,12 +427,10 @@ void CacheItem::Impl::convertToDisplayFo } lyxerr[Debug::GRAPHICS] << "\tConverting it to " << to << " format." << endl; - // Take only the filename part of the file, without path or extension. - string const temp = ChangeExtension(OnlyFilename(filename), string()); // Add some stuff to create a uniquely named temporary file. // This file is deleted in loadImage after it is loaded into memory. - string const to_file_base = tempName(string(), temp); + string const to_file_base = tempName(string(), "CacheItem"); remove_loaded_file_ = true; // Remove the temp file, we only want the name... Index: src/graphics/GraphicsConverter.C =================================================================== --- src/graphics/GraphicsConverter.C (Revision 14622) +++ src/graphics/GraphicsConverter.C (Arbeitskopie) @@ -32,6 +32,7 @@ namespace support = lyx::support; using support::ChangeExtension; using support::Forkedcall; using support::ForkedCallQueue; +using support::GetExtension; using support::LibFileSearch; using support::LibScriptSearch; using support::OnlyPath; @@ -263,7 +264,6 @@ string const move_file(string const & fr << "try:\n" << " os.rename(fromfile, tofile)\n" << "except:\n" - << " import shutil\n" << " try:\n" << " shutil.copy(fromfile, tofile)\n" << " except:\n" @@ -274,50 +274,6 @@ string const move_file(string const & fr } -/* -A typical script looks like: - -#!/usr/bin/env python -import os, sys - -def unlinkNoThrow(file): - ''' remove a file, do not throw if error occurs ''' - try: - os.unlink(file) - except: - pass - -infile = '/home/username/Figure3a.eps' -infile_base = '/home/username/Figure3a' -outfile = '/tmp/lyx_tmpdir12992hUwBqt/gconvert0129929eUBPm.pdf' - -if os.system(r'epstopdf ' + '"' + infile + '"' + ' --output ' + '"' + outfile + '"' + '') != 0: - unlinkNoThrow(outfile) - sys.exit(1) - -if not os.path.isfile(outfile): - if os.path.isfile(outfile + '.0'): - os.rename(outfile + '.0', outfile) - import glob - for file in glob.glob(outfile + '.?'): - unlinkNoThrow(file) - else: - sys.exit(1) - -fromfile = outfile -tofile = '/tmp/lyx_tmpdir12992hUwBqt/Figure3a129927ByaCl.ppm' - -try: - os.rename(fromfile, tofile) -except: - import shutil - try: - shutil.copy(fromfile, tofile) - except: - sys.exit(1) - unlinkNoThrow(fromfile) - -*/ bool build_script(string const & from_file, string const & to_file_base, string const & from_format, @@ -331,7 +287,7 @@ bool build_script(string const & from_fi return false; script << "#!/usr/bin/env python\n" - << "import os, sys\n\n" + << "import os, shutil, sys\n\n" << "def unlinkNoThrow(file):\n" << " ''' remove a file, do not throw if an error occurs '''\n" << " try:\n" @@ -364,7 +320,15 @@ bool build_script(string const & from_fi string const to_base = tempName(string(), tmp); unlink(to_base); - string outfile = from_file; + // Create a copy of the file in case the original name contains + // problematic characters like ' or ". We can work around that problem + // 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" + "shutil.copy(infile, outfile)\n"; // The conversion commands may contain these tokens that need to be // changed to infile, infile_base, outfile respectively. @@ -416,10 +380,8 @@ bool build_script(string const & from_fi << " else:\n" << " sys.exit(1)\n\n"; - // Delete the infile, if it isn't the original, from_file. - if (infile != from_file) { - script << "unlinkNoThrow(infile)\n\n"; - } + // Delete the infile + script << "unlinkNoThrow(infile)\n\n"; } // Move the final outfile to to_file