backport [7fdf0f] and [6836db] from master

This commit is contained in:
Josip 2014-04-09 23:43:09 +02:00
parent 659433dd82
commit 016b779316
4 changed files with 36 additions and 7 deletions

View File

@ -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"
#

View File

@ -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:

View File

@ -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")

View File

@ -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),