* src/Utils.py (find_file): new method that tries to check the existance of a file by trying out multiple encoding variants for the filename.
* src/ImgManip.py (get_thumbnail_image): Use Utils.find_file to fix encoding problems, additionally catch OSError * src/ImageSelect.py (on_name_changed): Use Utils.find_file * src/AddMedia.py (on_name_changed): Use Utils.find_file * src/plugins/Check.py (encoding) dont encode a utf-8 string as again, (cleanup_missing_photos) Use Utils.find_file to fix encoding problems svn: r5405
This commit is contained in:
parent
94d8d28cb0
commit
86fa385a9b
@ -1,3 +1,13 @@
|
||||
2005-11-18 Martin Hawlisch <Martin.Hawlisch@gmx.de>
|
||||
* src/Utils.py (find_file): new method that tries to check the existance
|
||||
of a file by trying out multiple encoding variants for the filename.
|
||||
* src/ImgManip.py (get_thumbnail_image): Use Utils.find_file to fix
|
||||
encoding problems, additionally catch OSError
|
||||
* src/ImageSelect.py (on_name_changed): Use Utils.find_file
|
||||
* src/AddMedia.py (on_name_changed): Use Utils.find_file
|
||||
* src/plugins/Check.py (encoding) dont encode a utf-8 string as again,
|
||||
(cleanup_missing_photos) Use Utils.find_file to fix encoding problems
|
||||
|
||||
2005-11-17 Martin Hawlisch <Martin.Hawlisch@gmx.de>
|
||||
* src/gramps.glade,
|
||||
src/TipOfDay.py: Add window title
|
||||
|
@ -155,8 +155,9 @@ class AddMediaObject:
|
||||
if old_title == '' or old_title == self.temp_name:
|
||||
self.description.set_text(root)
|
||||
self.temp_name = root
|
||||
|
||||
if os.path.isfile(filename):
|
||||
|
||||
filename = Utils.find_file( filename)
|
||||
if filename:
|
||||
mtype = GrampsMime.get_type(filename)
|
||||
if mtype and mtype.startswith("image"):
|
||||
image = RelImage.scale_image(filename,const.thumbScale)
|
||||
|
@ -166,7 +166,8 @@ class ImageSelect:
|
||||
self.description.set_text(root)
|
||||
self.temp_name = root
|
||||
|
||||
if os.path.isfile(filename):
|
||||
filename = Utils.find_file( filename)
|
||||
if filename:
|
||||
mtype = GrampsMime.get_type(filename)
|
||||
if mtype and mtype.startswith("image"):
|
||||
image = RelImage.scale_image(filename,const.thumbScale)
|
||||
|
@ -144,12 +144,13 @@ def get_thumbnail_image(path,mtype=None):
|
||||
filename = _build_thumb_path(path)
|
||||
|
||||
try:
|
||||
path = Utils.find_file( path)
|
||||
if not os.path.isfile(filename):
|
||||
set_thumbnail_image(path,mtype)
|
||||
elif os.path.getmtime(path) > os.path.getmtime(filename):
|
||||
set_thumbnail_image(path,mtype)
|
||||
return gtk.gdk.pixbuf_new_from_file(filename)
|
||||
except gobject.GError:
|
||||
except (gobject.GError, OSError):
|
||||
if mtype:
|
||||
return Utils.find_mime_type_pixbuf(mtype)
|
||||
else:
|
||||
|
@ -26,6 +26,7 @@
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import os
|
||||
import sys
|
||||
import locale
|
||||
import sets
|
||||
from gettext import gettext as _
|
||||
@ -262,6 +263,29 @@ def get_mime_description(mime_type):
|
||||
except:
|
||||
return ''
|
||||
|
||||
def find_file( filename):
|
||||
# try the filename we got
|
||||
try:
|
||||
fname = filename
|
||||
if os.path.isfile( filename):
|
||||
return( filename)
|
||||
except:
|
||||
pass
|
||||
|
||||
# Build list of elternate encodings
|
||||
encodings = [sys.getfilesystemencoding(), locale.getpreferredencoding(), 'UTF-8', 'ISO-8859-1']
|
||||
encodings = list(sets.Set(encodings))
|
||||
for enc in encodings:
|
||||
try:
|
||||
fname = filename.encode(enc)
|
||||
if os.path.isfile( fname):
|
||||
return fname
|
||||
except:
|
||||
pass
|
||||
|
||||
# not found
|
||||
return ''
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
|
@ -157,11 +157,6 @@ class CheckIntegrity:
|
||||
|
||||
|
||||
def fix_encoding(self):
|
||||
import locale
|
||||
codeset = locale.nl_langinfo(locale.CODESET)
|
||||
if codeset == 'UTF-8':
|
||||
codeset = 'latin1'
|
||||
|
||||
self.progress.set_pass(_('Looking for character encoding errors'),
|
||||
self.db.get_number_of_media_objects())
|
||||
|
||||
@ -171,10 +166,8 @@ class CheckIntegrity:
|
||||
(handle,data) = value
|
||||
if type(data[2]) != unicode or type(data[4]) != unicode:
|
||||
obj = self.db.get_object_from_handle(handle)
|
||||
if type(obj.path) != unicode:
|
||||
obj.path = unicode(obj.path,codeset)
|
||||
if type(obj.desc) != unicode:
|
||||
obj.desc = unicode(obj.desc,codeset)
|
||||
obj.path = Utils.fix_encoding( obj.path)
|
||||
obj.desc = Utils.fix_encoding( obj.desc)
|
||||
self.db.commit_media_object(obj,self.trans)
|
||||
self.progress.step()
|
||||
value = cursor.next()
|
||||
@ -346,7 +339,7 @@ class CheckIntegrity:
|
||||
for ObjectId in self.db.get_media_object_handles():
|
||||
obj = self.db.get_object_from_handle(ObjectId)
|
||||
photo_name = obj.get_path()
|
||||
if photo_name is not None and photo_name != "" and not os.path.isfile(photo_name):
|
||||
if photo_name is not None and photo_name != "" and not Utils.find_file(photo_name):
|
||||
if cl:
|
||||
print "Warning: media file %s was not found." \
|
||||
% os.path.basename(photo_name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user