|
From: Jimmy R. <ji...@re...> - 2011-09-01 15:55:35
|
See the custom-boot-script option at http://www.py2exe.org/index.cgi/ListOfOptions boot_common.py is still run, but your custom boot script is run immediately after so you can override anything it has done. Jimmy On Thu, Sep 1, 2011 at 8:13 AM, Marko Loparic <mar...@gm...>wrote: > Hello, > > Is there a way to override boot_common.py without replacing the file in the > py2exe installation directory? > > Here is my version of boot_common.py. I wrote it to have the stderr into > the popup screen instead of into a log file: > > ================================================================ > import sys > if sys.frozen == "windows_exe": > class Stderr(object): > softspace = 0 > _file = None > _alert = sys._MessageBox > def print_error(self): > text = 'Captured stderr:\n%s' % self._file.getvalue() > self._alert(0, text) > def write(self, text, alert=None, fname=None): > if self._file is None: > from StringIO import StringIO > self._file = StringIO() > import atexit > atexit.register(self.print_error) > self._file.write(text) > def flush(self): > pass > sys.stderr = Stderr() > del sys._MessageBox > del Stderr > > class Blackhole(object): > softspace = 0 > def write(self, text): > pass > def flush(self): > pass > sys.stdout = Blackhole() > del Blackhole > del sys > ================================================================ > > This worked fine in a test I did by replacing boot_common.py in > c:/Python26/Lib/site-packages/py2exe/. > > Thanks a lot, > Marko > > Note1: The reasons I have for not generating a log file are > > 1) The executable is in a folder where the users don't have the permission > to write. I could have changed the log directory in boot_common but I > couldn't imagine an alternative directory which would be safe to create a > log file. We could perhaps use %TEMP%, but I believe that users could be > afraid to look there for log files... > > 2) I believe that it is easier for a user to send us the capture of the > screen (in our experience every user knows how to do this) than to look for > a log file in a directory (%TEMP% or another). > > The inconvenience of the proposed approach could be to have a very big > popup if there are too many messages are sent to stderr. But I my case I > believe that this is unlikely to happen, because -- after parsing the > command line, opening the logging handlers and creating the output directory > where several logs and output files go -- our application redirects stderr > to a file in this output directory. So the mechanism in boot_common.py is > important only for the startup (i.e. to the errors that might happen before > this redirection) and should not contain more information than a traceback > in the case of a unforeseen exception. > > Note 2: In order to test it I just wrote a hello.py with an exception: > ===== > raise RuntimeError("test") > ===== > > and a standard setup.py > ===== > from distutils.core import setup > import py2exe > > setup(windows=['hello.py']) > ===== > > > > > ------------------------------------------------------------------------------ > Special Offer -- Download ArcSight Logger for FREE! > Finally, a world-class log management solution at an even better > price-free! And you'll get a free "Love Thy Logs" t-shirt when you > download Logger. Secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsisghtdev2dev > _______________________________________________ > Py2exe-users mailing list > Py2...@li... > https://lists.sourceforge.net/lists/listinfo/py2exe-users > > |