From: Peter L. <pet...@te...> - 2010-02-16 11:13:35
|
> 2010/2/16 Peter Landgren <pet...@te...>: > > Trying to solve more Windows path problems: > > > > I created a new user "Pär" and installed Gramps in: > > C:\Documents and Settings\Pär\Mina dokument\gramps320 > > > > In "const.py", after ROOT_DIR and PLUGINS_DIR are defined, I inserted two > > print statements: In "grampscli.py" I inserted a print statement directly > > after the "import const" statement: > > > > C:\Documents and Settings\Pär\Mina dokument\gramps320>python.exe > > gramps.py > > > > Def of ROOT_DIR: <type 'unicode'> C:\Documents and Settings\Pär\Mina > > dokument\gramps320 Def of PLUGINS_DIR: <type 'unicode'> C:\Documents and > > Settings\P"r\Mina dokument\gramps320\plugins > > > > After import const: <type 'unicode'> C:\Documents and Settings\P"r\Mina > > dokument\gramps320\plugins > > > > > > Note that Pär has changed to P"r after import! > > > > Can anyone explain this behavior? > > I think I know, you run const.py.in, this creates unicode paths, and > writes them in const.py, but const.py, does not contain that it should > use utf-8 on read. > > See PlaceUtils, the top should contain: > > # -*- coding: utf-8 -*- > > If you add that to const.py.in, it should be in const.py, and then > python will read the unicode in the const.py file correctly. > > If not above, it would appear os.path.join is to blame in const.py.in > when running makefile Can't run makefile in Win so I manipulate const.py. I have # -*- coding: utf-8 -*- on top of both const.py and grampscli.py. > Then do some tests: > PLUGINS_DIR = os.path.join(ROOT_DIR, u"plugins") Done that, no change > Or do the same differently: > PLUGINS_DIR = ROOT_DIR + os.sep + u"plugins" Done, no change More tests: With this code in const.py: print "Def of ROOT_DIR:", type(ROOT_DIR), ROOT_DIR PLUGINS_DIR = os.path.join(ROOT_DIR, u"plugins") print "Def of PLUGINS_DIR:", type(PLUGINS_DIR), PLUGINS_DIR and with this in grampscli.py: import const print "After import const:", type(const.PLUGINS_DIR), const.PLUGINS_DIR for qaz in const.__dict__.keys(): print type(qaz), qaz I get: Def of ROOT_DIR: <type 'unicode'> C:\Documents and Settings\Pär\Mina dokument\gramps320 Def of PLUGINS_DIR: <type 'unicode'> C:\Documents and Settings\Pär\Mina dokument\gramps320\plugins After import const: <type 'unicode'> C:\Documents and Settings\P"r\Mina dokument\gramps320\plugins skip many lines ... <type 'str'> ROOT_DIR ... <type 'str'> PLUGINS_DIR ... So all attributes have type 'str' after call, but const.PLUGINS_DIR is unicode???? Even tried: from const import PLUGINS_DIR, USER_PLUGINS print "After from const import ...:", type(PLUGINS_DIR), PLUGINS_DIR No change /Peter |