From aedfc3a6734bb4822e9e81fce6a4c332f65df5d3 Mon Sep 17 00:00:00 2001 From: Josip Date: Sun, 13 Apr 2014 10:11:22 +0200 Subject: [PATCH] 7258: transcode os.path.join args from the fs enc to prevent a crash fix plugin registration fix textual, html report etc (except cairo based report) fix web calendar report for python3 --- gramps/gen/db/write.py | 7 +++++++ gramps/gen/plug/_options.py | 6 +++--- gramps/gen/plug/_pluginreg.py | 2 +- gramps/gen/plug/docbackend/docbackend.py | 3 ++- gramps/gen/plug/report/_options.py | 7 ++++--- gramps/gui/plug/report/_graphvizreportdialog.py | 2 +- gramps/plugins/webreport/webcal.py | 7 +++++-- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/gramps/gen/db/write.py b/gramps/gen/db/write.py index 7965d0f8a..a52afd19a 100644 --- a/gramps/gen/db/write.py +++ b/gramps/gen/db/write.py @@ -554,7 +554,14 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): def __make_zip_backup(self, dirname): import zipfile + if sys.version_info[0] < 3: + from string import maketrans title = self.get_dbname() + # In Windows resrved characters is "<>:"/\|?*" + reserved_char = r':,<>"/\|?* ' + replace_char = "-__________" + trans = title.maketrans(reserved_char, replace_char) + title = title.translate(trans) if not os.access(dirname, os.W_OK): _LOG.warning("Can't write technical DB backup for %s" % title) diff --git a/gramps/gen/plug/_options.py b/gramps/gen/plug/_options.py index 6f0e0afaf..212129751 100644 --- a/gramps/gen/plug/_options.py +++ b/gramps/gen/plug/_options.py @@ -32,8 +32,8 @@ General option handling, including saving and parsing. # Standard Python modules # #------------------------------------------------------------------------- -from __future__ import print_function -import os +from __future__ import print_function, unicode_literals +import os, io import sys #------------------------------------------------------------------------- @@ -208,7 +208,7 @@ class OptionListCollection(object): """ Saves the current OptionListCollection to the associated file. """ - f = open(self.filename,"w") + f = io.open(self.filename,"w", encoding="utf-8") f.write("\n") f.write('\n') diff --git a/gramps/gen/plug/_pluginreg.py b/gramps/gen/plug/_pluginreg.py index 6721019b5..8ea39892f 100644 --- a/gramps/gen/plug/_pluginreg.py +++ b/gramps/gen/plug/_pluginreg.py @@ -1104,7 +1104,7 @@ class PluginRegister(object): if sys.version_info[0] < 3: fd = open(full_filename, "r") else: - fd = io.open(full_filename, "r") + fd = io.open(full_filename, "r", encoding='utf-8') stream = fd.read() fd.close() if os.path.exists(os.path.join(os.path.dirname(full_filename), diff --git a/gramps/gen/plug/docbackend/docbackend.py b/gramps/gen/plug/docbackend/docbackend.py index 20e3df62f..bbd62a815 100644 --- a/gramps/gen/plug/docbackend/docbackend.py +++ b/gramps/gen/plug/docbackend/docbackend.py @@ -32,6 +32,7 @@ from __future__ import print_function from ...const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext +import io #------------------------------------------------------------------------- # @@ -159,7 +160,7 @@ class DocBackend(object): % self.filename) self._checkfilename() try: - self.__file = open(self.filename, "w") + self.__file = io.open(self.filename, "w", encoding="utf-8") except IOError as msg: errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg) raise DocBackendError(errmsg) diff --git a/gramps/gen/plug/report/_options.py b/gramps/gen/plug/report/_options.py index 2cc3874ca..0992edc50 100644 --- a/gramps/gen/plug/report/_options.py +++ b/gramps/gen/plug/report/_options.py @@ -33,7 +33,8 @@ Report option handling, including saving and parsing. # Standard Python modules # #------------------------------------------------------------------------- -import os +from __future__ import unicode_literals +import os, io import copy from xml.sax.saxutils import escape @@ -505,7 +506,7 @@ class OptionListCollection(_options.OptionListCollection): if os.path.isfile(self.filename): p = make_parser() p.setContentHandler(OptionParser(self)) - the_file = open(self.filename) + the_file = io.open(self.filename, encoding="utf-8") p.parse(the_file) the_file.close() except (IOError, OSError, SAXParseException): @@ -1001,7 +1002,7 @@ class DocOptionListCollection(_options.OptionListCollection): if os.path.isfile(self.filename): p = make_parser() p.setContentHandler(DocOptionParser(self)) - the_file = open(self.filename) + the_file = io.open(self.filename, encoding="utf-8") p.parse(the_file) the_file.close() except (IOError, OSError, SAXParseException): diff --git a/gramps/gui/plug/report/_graphvizreportdialog.py b/gramps/gui/plug/report/_graphvizreportdialog.py index 8dd7ebc12..569f44db4 100644 --- a/gramps/gui/plug/report/_graphvizreportdialog.py +++ b/gramps/gui/plug/report/_graphvizreportdialog.py @@ -155,7 +155,7 @@ class GraphvizReportDialog(ReportDialog): yoptions=Gtk.AttachOptions.SHRINK) self.row += 1 - self.open_with_app = Gtk.CheckButton(build=_("Open with default viewer")) + self.open_with_app = Gtk.CheckButton(_("Open with default viewer")) self.open_with_app.set_active( config.get('interface.open-with-default-viewer')) self.tbl.attach(self.open_with_app, 2, 4, self.row, self.row+1, diff --git a/gramps/plugins/webreport/webcal.py b/gramps/plugins/webreport/webcal.py index a77ae6410..24ffd1150 100644 --- a/gramps/plugins/webreport/webcal.py +++ b/gramps/plugins/webreport/webcal.py @@ -579,7 +579,7 @@ class WebCalReport(Report): elif url_fname == 'fullyearlinked': myTitle = _('Full year at a Glance') else: - myTitle = _(url_fname) + myTitle = _(url_fname) hyper = Html("a", nav_text, href = url, name = url_fname, title = myTitle) if check_cs: @@ -1728,7 +1728,10 @@ def get_day_list(event_date, holiday_list, bday_anniv_list): # sort them based on number of years # holidays will always be on top of event list - day_list.sort() + if sys.version_info[0] < 3: + day_list.sort() + else: + day_list= sorted(day_list, key=lambda x: (isinstance(x[0], str), x[0])) # return to its caller calendar_build() return day_list