* 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>
|
2005-11-17 Martin Hawlisch <Martin.Hawlisch@gmx.de>
|
||||||
* src/gramps.glade,
|
* src/gramps.glade,
|
||||||
src/TipOfDay.py: Add window title
|
src/TipOfDay.py: Add window title
|
||||||
|
@ -156,7 +156,8 @@ class AddMediaObject:
|
|||||||
self.description.set_text(root)
|
self.description.set_text(root)
|
||||||
self.temp_name = root
|
self.temp_name = root
|
||||||
|
|
||||||
if os.path.isfile(filename):
|
filename = Utils.find_file( filename)
|
||||||
|
if filename:
|
||||||
mtype = GrampsMime.get_type(filename)
|
mtype = GrampsMime.get_type(filename)
|
||||||
if mtype and mtype.startswith("image"):
|
if mtype and mtype.startswith("image"):
|
||||||
image = RelImage.scale_image(filename,const.thumbScale)
|
image = RelImage.scale_image(filename,const.thumbScale)
|
||||||
|
@ -166,7 +166,8 @@ class ImageSelect:
|
|||||||
self.description.set_text(root)
|
self.description.set_text(root)
|
||||||
self.temp_name = root
|
self.temp_name = root
|
||||||
|
|
||||||
if os.path.isfile(filename):
|
filename = Utils.find_file( filename)
|
||||||
|
if filename:
|
||||||
mtype = GrampsMime.get_type(filename)
|
mtype = GrampsMime.get_type(filename)
|
||||||
if mtype and mtype.startswith("image"):
|
if mtype and mtype.startswith("image"):
|
||||||
image = RelImage.scale_image(filename,const.thumbScale)
|
image = RelImage.scale_image(filename,const.thumbScale)
|
||||||
|
@ -144,12 +144,13 @@ def get_thumbnail_image(path,mtype=None):
|
|||||||
filename = _build_thumb_path(path)
|
filename = _build_thumb_path(path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
path = Utils.find_file( path)
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
set_thumbnail_image(path,mtype)
|
set_thumbnail_image(path,mtype)
|
||||||
elif os.path.getmtime(path) > os.path.getmtime(filename):
|
elif os.path.getmtime(path) > os.path.getmtime(filename):
|
||||||
set_thumbnail_image(path,mtype)
|
set_thumbnail_image(path,mtype)
|
||||||
return gtk.gdk.pixbuf_new_from_file(filename)
|
return gtk.gdk.pixbuf_new_from_file(filename)
|
||||||
except gobject.GError:
|
except (gobject.GError, OSError):
|
||||||
if mtype:
|
if mtype:
|
||||||
return Utils.find_mime_type_pixbuf(mtype)
|
return Utils.find_mime_type_pixbuf(mtype)
|
||||||
else:
|
else:
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import locale
|
import locale
|
||||||
import sets
|
import sets
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
@ -262,6 +263,29 @@ def get_mime_description(mime_type):
|
|||||||
except:
|
except:
|
||||||
return ''
|
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):
|
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.progress.set_pass(_('Looking for character encoding errors'),
|
||||||
self.db.get_number_of_media_objects())
|
self.db.get_number_of_media_objects())
|
||||||
|
|
||||||
@ -171,10 +166,8 @@ class CheckIntegrity:
|
|||||||
(handle,data) = value
|
(handle,data) = value
|
||||||
if type(data[2]) != unicode or type(data[4]) != unicode:
|
if type(data[2]) != unicode or type(data[4]) != unicode:
|
||||||
obj = self.db.get_object_from_handle(handle)
|
obj = self.db.get_object_from_handle(handle)
|
||||||
if type(obj.path) != unicode:
|
obj.path = Utils.fix_encoding( obj.path)
|
||||||
obj.path = unicode(obj.path,codeset)
|
obj.desc = Utils.fix_encoding( obj.desc)
|
||||||
if type(obj.desc) != unicode:
|
|
||||||
obj.desc = unicode(obj.desc,codeset)
|
|
||||||
self.db.commit_media_object(obj,self.trans)
|
self.db.commit_media_object(obj,self.trans)
|
||||||
self.progress.step()
|
self.progress.step()
|
||||||
value = cursor.next()
|
value = cursor.next()
|
||||||
@ -346,7 +339,7 @@ class CheckIntegrity:
|
|||||||
for ObjectId in self.db.get_media_object_handles():
|
for ObjectId in self.db.get_media_object_handles():
|
||||||
obj = self.db.get_object_from_handle(ObjectId)
|
obj = self.db.get_object_from_handle(ObjectId)
|
||||||
photo_name = obj.get_path()
|
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:
|
if cl:
|
||||||
print "Warning: media file %s was not found." \
|
print "Warning: media file %s was not found." \
|
||||||
% os.path.basename(photo_name)
|
% os.path.basename(photo_name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user