Delete a bunch of superflous re-encodings of path names
This commit is contained in:
@@ -462,7 +462,7 @@ def find_next_db_name(name_list):
|
|||||||
while True:
|
while True:
|
||||||
title = "%s %d" % (DEFAULT_TITLE, i)
|
title = "%s %d" % (DEFAULT_TITLE, i)
|
||||||
if title not in name_list:
|
if title not in name_list:
|
||||||
return title
|
return conv_to_unicode(title)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
def find_next_db_dir():
|
def find_next_db_dir():
|
||||||
|
@@ -55,10 +55,10 @@ WINDOWS = ["Windows", "win32"]
|
|||||||
|
|
||||||
#python 2 and 3 support, use correct conversion to unicode
|
#python 2 and 3 support, use correct conversion to unicode
|
||||||
if sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
def conv_to_unicode(x, y):
|
def conv_to_unicode(x, y=None):
|
||||||
if isinstance(x, unicode):
|
if isinstance(x, unicode):
|
||||||
return x
|
return x
|
||||||
return unicode(x, y)
|
return unicode(x, y) if y else unicode(x)
|
||||||
|
|
||||||
conv_to_unicode_direct = unicode
|
conv_to_unicode_direct = unicode
|
||||||
STRTYPE = basestring
|
STRTYPE = basestring
|
||||||
|
@@ -31,6 +31,7 @@ from xml.sax import make_parser, SAXParseException
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import collections
|
import collections
|
||||||
|
import io
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@@ -108,7 +109,7 @@ class FilterList(object):
|
|||||||
if os.path.isfile(self.file):
|
if os.path.isfile(self.file):
|
||||||
parser = make_parser()
|
parser = make_parser()
|
||||||
parser.setContentHandler(FilterParser(self))
|
parser.setContentHandler(FilterParser(self))
|
||||||
the_file = open(self.file)
|
the_file = io.open(self.file, 'r', encoding='utf8')
|
||||||
parser.parse(the_file)
|
parser.parse(the_file)
|
||||||
the_file.close()
|
the_file.close()
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
@@ -125,7 +126,7 @@ class FilterList(object):
|
|||||||
return l.replace('"', '"')
|
return l.replace('"', '"')
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
f = open(self.file.encode(glocale.getfilesystemencoding()), 'w')
|
f = io.open(self.file, 'w', encoding='utf8')
|
||||||
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
||||||
f.write('<filters>\n')
|
f.write('<filters>\n')
|
||||||
for namespace in self.filter_namespaces:
|
for namespace in self.filter_namespaces:
|
||||||
|
@@ -433,6 +433,7 @@ class DbManager(CLIDbManager):
|
|||||||
#path is a string, convert to TreePath first
|
#path is a string, convert to TreePath first
|
||||||
path = Gtk.TreePath(path=path)
|
path = Gtk.TreePath(path=path)
|
||||||
if len(new_text) > 0:
|
if len(new_text) > 0:
|
||||||
|
new_text = conv_to_unicode(new_text, 'utf8')
|
||||||
node = self.model.get_iter(path)
|
node = self.model.get_iter(path)
|
||||||
old_text = self.model.get_value(node, NAME_COL)
|
old_text = self.model.get_value(node, NAME_COL)
|
||||||
if not old_text.strip() == new_text.strip():
|
if not old_text.strip() == new_text.strip():
|
||||||
|
@@ -525,16 +525,13 @@ class GalleryTab(ButtonTab, DbGUIElement):
|
|||||||
d = fix_encoding(file.replace('\0',' ').strip())
|
d = fix_encoding(file.replace('\0',' ').strip())
|
||||||
protocol, site, mfile, j, k, l = urlparse(d)
|
protocol, site, mfile, j, k, l = urlparse(d)
|
||||||
if protocol == "file":
|
if protocol == "file":
|
||||||
name = fix_encoding(mfile)
|
mime = get_type(mfile)
|
||||||
name = cuni(url2pathname(
|
|
||||||
name.encode(glocale.getfilesystemencoding())))
|
|
||||||
mime = get_type(name)
|
|
||||||
if not is_valid_type(mime):
|
if not is_valid_type(mime):
|
||||||
return
|
return
|
||||||
photo = MediaObject()
|
photo = MediaObject()
|
||||||
base_dir = cuni(media_path(self.dbstate.db))
|
base_dir = cuni(media_path(self.dbstate.db))
|
||||||
if os.path.exists(base_dir):
|
if os.path.exists(base_dir):
|
||||||
name = relative_path(name, base_dir)
|
name = relative_path(mfile, base_dir)
|
||||||
photo.set_path(name)
|
photo.set_path(name)
|
||||||
photo.set_mime_type(mime)
|
photo.set_mime_type(mime)
|
||||||
basename = os.path.basename(name)
|
basename = os.path.basename(name)
|
||||||
|
@@ -1299,13 +1299,10 @@ class ViewManager(CLIManager):
|
|||||||
basefile = file_entry.get_text()
|
basefile = file_entry.get_text()
|
||||||
basefile = basefile.replace("/", r"-")
|
basefile = basefile.replace("/", r"-")
|
||||||
filename = os.path.join(path_entry.get_text(), basefile)
|
filename = os.path.join(path_entry.get_text(), basefile)
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
filename = filename.encode(glocale.getfilesystemencoding())
|
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
sfilename = get_unicode_path_from_env_var(filename)
|
|
||||||
question = QuestionDialog2(
|
question = QuestionDialog2(
|
||||||
_("Backup file already exists! Overwrite?"),
|
_("Backup file already exists! Overwrite?"),
|
||||||
_("The file '%s' exists.") % sfilename,
|
_("The file '%s' exists.") % filename,
|
||||||
_("Proceed and overwrite"),
|
_("Proceed and overwrite"),
|
||||||
_("Cancel the backup"))
|
_("Cancel the backup"))
|
||||||
yes_no = question.run()
|
yes_no = question.run()
|
||||||
|
@@ -96,8 +96,6 @@ class CairoDocgen(libcairodoc.CairoDoc):
|
|||||||
|
|
||||||
# create cairo context and pango layout
|
# create cairo context and pango layout
|
||||||
filename = self._backend.filename
|
filename = self._backend.filename
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
filename = self._backend.filename.encode(glocale.getfilesystemencoding())
|
|
||||||
try:
|
try:
|
||||||
surface = self.create_cairo_surface(filename, paper_width, paper_height)
|
surface = self.create_cairo_surface(filename, paper_width, paper_height)
|
||||||
except IOError as msg:
|
except IOError as msg:
|
||||||
|
@@ -153,16 +153,10 @@ class GeoGraphyView(OsmGps, NavigationView):
|
|||||||
self.geo_mainmap = None
|
self.geo_mainmap = None
|
||||||
path = os.path.join(IMAGE_DIR, "48x48",
|
path = os.path.join(IMAGE_DIR, "48x48",
|
||||||
('gramps-geo-mainmap' + '.png' ))
|
('gramps-geo-mainmap' + '.png' ))
|
||||||
pathu = path
|
self.geo_mainmap = cairo.ImageSurface.create_from_png(path)
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
pathu = path.encode(glocale.getfilesystemencoding())
|
|
||||||
self.geo_mainmap = cairo.ImageSurface.create_from_png(pathu)
|
|
||||||
path = os.path.join(IMAGE_DIR, "48x48",
|
path = os.path.join(IMAGE_DIR, "48x48",
|
||||||
('gramps-geo-altmap' + '.png' ))
|
('gramps-geo-altmap' + '.png' ))
|
||||||
pathu = path
|
self.geo_altmap = cairo.ImageSurface.create_from_png(path)
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
pathu = path.encode(glocale.getfilesystemencoding())
|
|
||||||
self.geo_altmap = cairo.ImageSurface.create_from_png(pathu)
|
|
||||||
if ( config.get('geography.map_service') in
|
if ( config.get('geography.map_service') in
|
||||||
( constants.OPENSTREETMAP,
|
( constants.OPENSTREETMAP,
|
||||||
constants.MAPS_FOR_FREE,
|
constants.MAPS_FOR_FREE,
|
||||||
@@ -178,10 +172,7 @@ class GeoGraphyView(OsmGps, NavigationView):
|
|||||||
EventType.MARRIAGE ):
|
EventType.MARRIAGE ):
|
||||||
path = os.path.join(IMAGE_DIR, "48x48",
|
path = os.path.join(IMAGE_DIR, "48x48",
|
||||||
(constants.ICONS.get(int(ident), default_image) + '.png' ))
|
(constants.ICONS.get(int(ident), default_image) + '.png' ))
|
||||||
pathu = path
|
self.geo_othermap[ident] = cairo.ImageSurface.create_from_png(path)
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
pathu = path.encode(glocale.getfilesystemencoding())
|
|
||||||
self.geo_othermap[ident] = cairo.ImageSurface.create_from_png(pathu)
|
|
||||||
|
|
||||||
def add_bookmark(self, menu, handle):
|
def add_bookmark(self, menu, handle):
|
||||||
if handle:
|
if handle:
|
||||||
|
@@ -191,11 +191,7 @@ class MediaView(ListView):
|
|||||||
file.replace('\0',' ').replace("\r", " ").strip())
|
file.replace('\0',' ').replace("\r", " ").strip())
|
||||||
protocol, site, mfile, j, k, l = urlparse(clean_string)
|
protocol, site, mfile, j, k, l = urlparse(clean_string)
|
||||||
if protocol == "file":
|
if protocol == "file":
|
||||||
if sys.version_info[0] < 3:
|
name = mfile
|
||||||
name = cuni(url2pathname(
|
|
||||||
mfile.encode(glocale.getfilesystemencoding())))
|
|
||||||
else:
|
|
||||||
name = cuni(url2pathname(mfile))
|
|
||||||
mime = get_type(name)
|
mime = get_type(name)
|
||||||
if not is_valid_type(mime):
|
if not is_valid_type(mime):
|
||||||
return
|
return
|
||||||
|
@@ -208,8 +208,6 @@ class PersonBoxWidgetCairo(_PersonWidgetBase):
|
|||||||
self.img_surf = None
|
self.img_surf = None
|
||||||
if image:
|
if image:
|
||||||
image_path = self.get_image(dbstate, person)
|
image_path = self.get_image(dbstate, person)
|
||||||
if sys.version_info[0] < 3 and isinstance(image_path, STRTYPE):
|
|
||||||
image_path = image_path.encode(glocale.getfilesystemencoding())
|
|
||||||
if image_path and os.path.exists(image_path):
|
if image_path and os.path.exists(image_path):
|
||||||
self.img_surf = cairo.ImageSurface.create_from_png(image_path)
|
self.img_surf = cairo.ImageSurface.create_from_png(image_path)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user