From 016b779316cc862be025b1cc03565dd7a0a72f78 Mon Sep 17 00:00:00 2001 From: Josip Date: Wed, 9 Apr 2014 23:43:09 +0200 Subject: [PATCH] backport [7fdf0f] and [6836db] from master --- gramps/gen/const.py | 5 ++++- gramps/gen/db/write.py | 2 +- gramps/gen/plug/_manager.py | 33 ++++++++++++++++++++++++++++++--- gramps/gen/plug/_pluginreg.py | 3 +-- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/gramps/gen/const.py b/gramps/gen/const.py index 8f214dcaa..2ccc37f37 100644 --- a/gramps/gen/const.py +++ b/gramps/gen/const.py @@ -135,7 +135,10 @@ if sys.version_info[0] < 3: ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname( unicode(__file__, sys.getfilesystemencoding())), os.pardir)) -VERSION += get_git_revision(ROOT_DIR) +git_revision = get_git_revision(ROOT_DIR) +if sys.platform == 'win32' and git_revision == "": + git_revision = get_git_revision(os.path.split(ROOT_DIR)[1]) +VERSION += git_revision #VERSION += "-1" # diff --git a/gramps/gen/db/write.py b/gramps/gen/db/write.py index 6ccdf45d9..fbab4f38c 100644 --- a/gramps/gen/db/write.py +++ b/gramps/gen/db/write.py @@ -1134,7 +1134,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): if sys.version_info[0] >= 3: key= str(key) else: - key = str(tuple(str(k) for k in key)) + key = str(tuple(k.encode('utf-8') for k in key)) if isinstance(key, UNITYPE): key = key.encode('utf-8') if not self.readonly: diff --git a/gramps/gen/plug/_manager.py b/gramps/gen/plug/_manager.py index caa23fc61..6315cdcdf 100644 --- a/gramps/gen/plug/_manager.py +++ b/gramps/gen/plug/_manager.py @@ -54,7 +54,7 @@ _ = glocale.translation.gettext #------------------------------------------------------------------------- from ..config import config from . import PluginRegister, ImportPlugin, ExportPlugin, DocGenPlugin -from ..constfunc import STRTYPE +from ..constfunc import STRTYPE, win #------------------------------------------------------------------------- # @@ -256,9 +256,36 @@ class BasePluginManager(object): try: module = __import__(pdata.mod_name) except ValueError as err: - LOG.warning('Plugin error: %s', err) + # Python3 on Windows work with unicode in sys.path + # but they are mbcs encode for checking validity + if (sys.version_info[0] >= 3) and win(): + # we don't want to load Gramps core plugin like this + # only 3rd party plugins + if "gramps" in pdata.fpath: + try: + sys.path.insert(0, ".") + oldwd = os.getcwd() + os.chdir(pdata.fpath) + module = __import__(pdata.mod_name) + os.chdir(oldwd) + sys.path.pop(0) + except ValueError as err: + LOG.warning('Plugin error: %s', err) + else: + LOG.warning('Plugin error: %s', err) except ImportError as err: - LOG.warning('Plugin error: %s', err) + # Python2 on Windows not work with unicode in sys.path + # but module can be loaded from current directory + if (sys.version_info[0] < 3) and win(): + try: + oldwd = os.getcwd() + os.chdir(pdata.fpath) + module = __import__(pdata.mod_name) + os.chdir(oldwd) + except ImportError as err: + LOG.warning('Plugin error: %s', err) + else: + LOG.warning('Plugin error: %s', err) sys.path.pop(0) else: print("WARNING: module cannot be loaded") diff --git a/gramps/gen/plug/_pluginreg.py b/gramps/gen/plug/_pluginreg.py index 39cf9d5b3..d35b3ce57 100644 --- a/gramps/gen/plug/_pluginreg.py +++ b/gramps/gen/plug/_pluginreg.py @@ -1082,10 +1082,9 @@ class PluginRegister(object): lenpd = len(self.__plugindata) full_filename = os.path.join(dir, filename) if sys.version_info[0] < 3: - full_filename = full_filename.encode(glocale.getfilesystemencoding()) fd = open(full_filename, "r") else: - fd = io.open(full_filename, 'r', encoding = 'utf-8') + fd = io.open(full_filename, 'r') stream = fd.read() fd.close() if os.path.exists(os.path.join(os.path.dirname(full_filename),