os.environ['HOME'] may not exists on Windows

Alexander Belchenko bialix at ukr.net
Mon Apr 11 14:29:24 BST 2005


Hi!

I'm try to run bzr-0.0.3 and got error message:

Traceback (most recent call last):
   File "C:\Python24\Scripts\bzr.py", line 24, in ?
     sys.exit(bzrlib.commands.main(sys.argv))
   File "C:\Python24\Lib\site-packages\bzrlib\commands.py", line 989, in
main
     bzrlib.trace.create_tracefile(argv)
   File "C:\Python24\Lib\site-packages\bzrlib\trace.py", line 89, in
create_trace
file
     trace_fname = os.path.join(os.environ['HOME'], '.bzr.log')
   File "C:\Python24\lib\os.py", line 422, in __getitem__
     return self.data[key.upper()]
KeyError: 'HOME'

In interpreter session I found that on my machine (Windows 2000 SP4)
os.environ contain two another parts started with 'HOME' word:

HOMEDRIVE:  'C:'
HOMEPATH: '\\'

I add to bzrlib/trace.py at line 88
(after your comment '# XXX: Is HOME always set on Windows?')
next statement:

     if not os.environ.has_key('HOME'):
         os.environ['HOME'] = os.path.join(os.environ['HOMEDRIVE'], \
                                           os.environ['HOMEPATH'])

In this case bzr works well and create .bzr.log in C:\ directory.
May be there must be checking for HOMEDRIVE and HOMEPATH exists in
os.environ, but if it is not? What next variant for HOME? Windows also
has two another key in os.environ:

USERPROFILE - profile of current user (unique directory for each user)
APPDATA - application-specific data for current user (this is
subdirectory 'Application Data' of `USERPROFILE` directory).

--
Alexander





More information about the bazaar mailing list