wxpython application vista

Hi Paul,

and py2exe by default outputs error logs there.

thanks for that, how can i redirect this to the os.environ.get(“APPDATA”)
folder…

I see the snippet

import sys
sys.stdout = open(“my_stdout.log”, “w”)
sys.stderr = open(“my_stderr.log”, “w”)

in [http://www.py2exe.org/index.cgi/StderrLog](http://www.py2exe.org/index.cgi/StderrLog)
I tried something in the lines of

    class Stderr(object):
        softspace = 0
       userDataDir = os.environ.get("APPDATA")+'\\Application Name';
        _file = None
        _error = None
        def write(self, text, alert=sys._MessageBox, fname=sys.executable + '.log'):
            if self._file is None and self._error is None:
                try:
                    if (not os.path.isdir(userDataDir)):
                       os.mkdir(userDataDir)
                    self._file = open(fname, 'a')
                except Exception, details:
                    self._error = details
                    import atexit
                    atexit.register(alert, 0,
                                    "The logfile '%s' could not be opened:\n %s" % \
                                    (fname, details),
                                    "Errors occurred")
                else:
                    import atexit
                    atexit.register(alert, 0,
                                    "See the logfile '%s' for details" % fname,
                                    "Errors occurred")
            if self._file is not None:
                self._file.write(text)
                self._file.flush()
        def flush(self):
            if self._file is not None:
                self._file.flush()
    sys.stderr = Stderr()
    del sys._MessageBox
    del Stderr
I added the above class in setup.py script..
I am getting the error
AttributeError: 'module' object has no attribute '_MessageBox'
cheers
Thomas

You can ask the registry where the appdata folder is. This worked on XP and my app also worked on Vista without modifications. Example code from my app:

from ShellFolders
import fetchShellFolders
shellFolders = fetchShellFolders()
appDataDir = os.path.join(shellFolders[
"AppData"][0], "<application name here>")

Where appDataDir then is where you should save your stuff.

The fetchSellFolders method is implemented here:
http://launcher.cvs.sourceforge.net/launcher/launcher/src/ShellFolders.py?revision=1.1.1.1&view=markup

There might be something similar already available in wxpython that can tell you the appdata dir but I don’t know if or what it is.

Regards,

···


Rune Devik

http://www.garageinnovation.org

On 5/31/07, Thomas Thomas thomas@mindz-i.co.nz wrote:

Hi Paul,

and py2exe by default outputs error logs there.

thanks for that, how can i redirect this to the os.environ.get(“APPDATA”)
folder…

I see the snippet

import sys
sys.stdout = open("my_stdout.log", "w")
sys.stderr = open("my_stderr.log", "w")

in [
http://www.py2exe.org/index.cgi/StderrLog](http://www.py2exe.org/index.cgi/StderrLog)
I tried something in the lines of


    class Stderr(object):
        softspace = 0
       userDataDir = os.environ.get("APPDATA")+'\\Application Name';
        _file = None

        _error = None
        def write(self, text, alert=sys._MessageBox, fname=sys.executable + '.log'):
            if self._file is None and self._error is None:
                try:
                    if (not os.path.isdir(userDataDir)):
                       os.mkdir(userDataDir)
                    self._file = open(fname, 'a')
                except Exception, details:

                    self._error = details
                    import atexit
                    atexit.register(alert, 0,
                                    "The logfile '%s' could not be opened:\n %s" % \

                                    (fname, details),
                                    "Errors occurred")
                else:
                    import atexit
                    atexit.register
(alert, 0,
                                    "See the logfile '%s' for details" % fname,
                                    "Errors occurred")
            if self._file is not None:

                self._file.write(text)
                self._file.flush()
        def flush(self):
            if self._file is not None:
                self._file.flush()
    sys.stderr = Stderr()

    del sys._MessageBox
    del Stderr
I added the above class in setup.py script..
I am getting the error
AttributeError: 'module' object has no attribute '_MessageBox'

cheers
Thomas