7258: Metadata viewer: Exiv2 can't handle Windows's UTF16 pathnames

So open the file and pass the handle.
This commit is contained in:
John Ralls 2014-04-19 17:11:13 -07:00
parent 94518f2577
commit 74336a7ca8

View File

@ -178,41 +178,45 @@ class MetadataView(Gtk.TreeView):
self.sections = {} self.sections = {}
self.model.clear() self.model.clear()
if os.path.exists(full_path): if not os.path.exists(full_path):
try:
metadata = GExiv2.Metadata(full_path)
except:
return False
else:
return False return False
get_human = metadata.get_tag_interpreted_string
for section, key, key2, func in TAGS: retval = False
if not key in metadata.get_exif_tags(): with open(full_path, 'rb') as fd:
continue try:
metadata = GExiv2.Metadata(self.fd)
if func is not None: get_human = metadata.get_tag_interpreted_string
if key2 is None:
human_value = func(metadata[key]) for section, key, key2, func in TAGS:
else: if not key in metadata.get_exif_tags():
if key2 in metadata.get_exif_tags(): continue
human_value = func(metadata[key], metadata[key2])
if func is not None:
if key2 is None:
human_value = func(metadata[key])
else: else:
human_value = func(metadata[key], None) if key2 in metadata.get_exif_tags():
else: human_value = func(metadata[key], metadata[key2])
human_value = get_human(key) else:
if key2 in metadata.get_exif_tags(): human_value = func(metadata[key], None)
human_value += ' ' + get_human(key2) else:
human_value = get_human(key)
if key2 in metadata.get_exif_tags():
human_value += ' ' + get_human(key2)
label = metadata.get_tag_label(key) label = metadata.get_tag_label(key)
node = self.__add_section(section) node = self.__add_section(section)
if human_value is None: if human_value is None:
human_value = '' human_value = ''
self.model.add((label, human_value), node=node) self.model.add((label, human_value), node=node)
self.model.tree.expand_all() self.model.tree.expand_all()
return self.model.count > 0 retval = self.model.count > 0
except:
pass
return retval
def __add_section(self, section): def __add_section(self, section):
""" """
@ -229,15 +233,17 @@ class MetadataView(Gtk.TreeView):
""" """
Return True if the gramplet has data, else return False. Return True if the gramplet has data, else return False.
""" """
if os.path.exists(full_path): if not os.path.exists(full_path):
try:
metadata = GExiv2.Metadata(full_path)
except:
return False
else:
return False return False
with open(full_path, 'rb') as fd:
retval = False
try:
metadata = GExiv2.Metadata(fd)
for tag in TAGS:
if tag in metadata.get_exif_tags():
retval = True
break
except:
pass
for tag in TAGS: return retval
if tag in metadata.get_exif_tags():
return True
return False