Automatically creating a HOME environ variable on Windows?

2005-10-28 Thread jim . eggleston
Windows doesn't have a HOME environment variable, but it does have
HOMEDRIVE and HOMEPATH. Could Windows versions of Python automatically
populate os.environ with HOME, where HOME =
os.path.join(os.environ['HOMEDRIVE'], os.environ['HOMEPATH'])?

If this was done, then modules such as pdb, which load resource files
from HOME, would work under Windows.

Alternatively, here is a patch to make pdb.py read .pdbrc under
Windows.

*** pdb_orig.py Mon Jun 16 01:26:30 2003
--- pdb.py  Sat Oct 29 11:11:07 2005
***
*** 65,72 
--- 65,76 

  # Read $HOME/.pdbrc and ./.pdbrc
  self.rcLines = []
+ envHome = ''
  if 'HOME' in os.environ:
  envHome = os.environ['HOME']
+ elif 'HOMEDRIVE' in os.environ and 'HOMEPATH' in os.environ:
+ envHome = os.path.join(os.environ['HOMEDRIVE'],
os.environ['HOMEPATH'])
+ if envHome:
  try:
  rcFile = open(os.path.join(envHome, ".pdbrc"))
  except IOError:

-- 
http://mail.python.org/mailman/listinfo/python-list


Debugging with SciTE

2005-10-28 Thread jim . eggleston
I just figured out a reasonably decent way to use pdb in SciTE for
debugging Python scripts. Debugging takes place in the SciTE output
window. I have only tested this with SciTE on Windows.

Here are the pieces you need:

1. Create a debug.py script file (I save this in
c:\usr\python\scripts):
import sys
from pdb import pm, set_trace
from inspect import getmembers
if sys.platform == 'win32':
import os
os.environ['HOME'] = os.path.join(os.environ['HOMEDRIVE'],
os.environ['HOMEPATH'])
del sys.argv[0]
execfile(sys.argv[0])

2. Create a .pdbrc file in HOME (optional, but very useful):
#Print instance variables (usage "pi classInst")
alias pi for k in %1.__dict__.keys(): print "%1."+k,"=",%1.__dict__[k]
#Print instance variables in self
alias ps pi self
#pprint locals
alias ppl pp locals()
#pprint globals
alias ppg pp globals()
#pprint getmembers
alias ppm pp getmembers(%1)

3. Modify the Build line of the Scite Python.properties file:
# Use python instead of pythonw on non-windows platforms
command.build.*.py=pythonw -i -u c:\usr\python\scripts\debug.py
"$(FileNameExt)"
command.build.subsystem.*.py=1

Now if you hit F7 when editing a Python script, output will be sent to
the
SciTE output window, after which you will see a python prompt. Assuming
there is an exception, entering pm() will start post-mortem debugging,
and you will see the (Pdb) prompt. You can then use pdb commands and
aliases to inspect variable values.

To set a break point in your script, enter set_trace() at the
appropriate point. This will fire up pdb, and you can use s (step) to
step through the code, and the aliases in .pdbrc to list values.

Use Ctrl-Break to kill the debugging session.

You have to be carefull how you type in the output window. Backspaces
tend to confuse things, so you need to make sure your typing is right
the first time. .pdbrc aliases help to reduce typing, so make use of
them.

Cheers,
Jim

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automatically creating a HOME environ variable on Windows?

2005-10-29 Thread jim . eggleston
Cool, even better. So what's best, having code to add HOME
(=USERPROFILE) to os.environ, or change the various places that HOME is
used to check for USERPROFILE?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Debugging with SciTE

2005-10-29 Thread jim . eggleston
Based on information from  Jarek Zgoda in another thread on the Windows
USERPROFILE environment variable, debug.py should be:
import sys
from pdb import pm, set_trace
from inspect import getmembers
if sys.platform == 'win32':
import os
os.environ['HOME'] = os.environ['USERPROFILE']
del sys.argv[0]
execfile(sys.argv[0])

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automatically creating a HOME environ variable on Windows?

2005-11-01 Thread jim . eggleston
Having a function is definitely cleaner. Creating a HOME environment
variable where one does not exist in the calling shell is misleading.

There are 10 modules in the python 2.3 lib directory that contain
os.environ['HOME']:

lib\ftplib.py
lib\mailbox.py
lib\mailcap.py
lib\netrc.py
lib\ntpath.py
lib\os2emxpath.py
lib\pdb.py
lib\posixpath.py
lib\rfc822.py
lib\user.py

It's probably not a huge effort to change these (but that's easy for me
to say ...) It would be nice to start of with having a standard way to
find out what the home directory is.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automatically creating a HOME environ variable on Windows?

2005-11-01 Thread jim . eggleston
Does Windows 98 have a %USERPROFILE% environment variable?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automatically creating a HOME environ variable on Windows?

2005-11-01 Thread jim . eggleston
os.path.expanduser('~') is a bit cryptic for non-unix people.
os.path.gethome() or something like that would be nicer. expanduser()
should then call gethome() so the logic is in one place.

It looks like the existing logic in expanduser() is out of date anyway.
It should be updated to use %USERPROFILE% before %HOMEDRIVE% +
%HOMEPATH% .

-- 
http://mail.python.org/mailman/listinfo/python-list