[Inteproxy-commits] r98 - in trunk: . inteproxy
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed May 16 18:30:33 CEST 2007
Author: bh
Date: 2007-05-16 18:30:33 +0200 (Wed, 16 May 2007)
New Revision: 98
Modified:
trunk/ChangeLog
trunk/inteproxy/main.py
trunk/inteproxy/resources.py
Log:
* inteproxy/resources.py (in_py2exe): New function to determine
whether the program is running in a py2exe generated execitable
* inteproxy/main.py (setup_logging): New function to setup
logging.
(run_server): Call setup_logging to initialize the logging and do
it immediately after reading the config file, to avoid logging
info to end up in the wrong place.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-05-16 14:54:41 UTC (rev 97)
+++ trunk/ChangeLog 2007-05-16 16:30:33 UTC (rev 98)
@@ -1,3 +1,14 @@
+2007-05-16 Bernhard Herzog <bh at intevation.de>
+
+ * inteproxy/resources.py (in_py2exe): New function to determine
+ whether the program is running in a py2exe generated execitable
+
+ * inteproxy/main.py (setup_logging): New function to setup
+ logging.
+ (run_server): Call setup_logging to initialize the logging and do
+ it immediately after reading the config file, to avoid logging
+ info to end up in the wrong place.
+
2007-05-16 Jan-Oliver Wagner <jan-oliver.wagner at intevation.de>
Preparing 0.2.0 release.
Modified: trunk/inteproxy/main.py
===================================================================
--- trunk/inteproxy/main.py 2007-05-16 14:54:41 UTC (rev 97)
+++ trunk/inteproxy/main.py 2007-05-16 16:30:33 UTC (rev 98)
@@ -15,6 +15,7 @@
import urllib2
import inteproxy.proxyconnection as proxyconnection
import inteproxy.transcoder
+import inteproxy.resources
from inteproxy.proxycore import (InteProxyHTTPRequestHandler,
MasterWorkerServer,
log_date_time_string)
@@ -65,6 +66,35 @@
urllib2.install_opener(urllib2.build_opener(*handlers))
+def setup_logging(opts):
+ """Sets up logging according to opts.
+
+ Log output in InteProxy is written to sys.stderr. This function
+ redirects stderr to the appropriate place.
+
+ The opts parameter should be the options object returned by
+ optparse. In particular, opts.logfile is used to determine where to
+ log to. It should either be None, so that the default redirection
+ is done, or a filename in which case sys.stderr is changed to write
+ to that file.
+
+ The default behavior is trying to accomodate the following
+ requirements:
+
+ - When run directly from the source tree in a terminal, the log out
+ should simply go to stderr. That is, sys.stderr is not changed
+ at all.
+
+ - When run from an executable created with py2exe, no logging takes
+ place, to avoid py2exe popping up a message box indicating that
+ errors occurred. In this case sys.stderr is redirected to
+ os.devnull.
+ """
+ if opts.logfile:
+ sys.stderr = open(opts.logfile, "a", 0)
+ elif inteproxy.resources.in_py2exe():
+ sys.stderr = open(os.devnull, "w")
+
# The main application object. It's a global variable so that worker
# threads can easily get access to it.
the_application = None
@@ -96,13 +126,12 @@
inteproxy.transcoder.transcoder_map.read_config(opts.config_file)
+ setup_logging(opts)
+
setup_urllib2(opts.debug_level)
server_address = ('localhost', opts.port)
- if opts.logfile:
- sys.stderr = open(opts.logfile, "a", 0)
-
sys.stderr.write("InteProxy Version %s\n" % inteproxy_version)
sys.stderr.write("[%s] server starting up\n" % log_date_time_string())
Modified: trunk/inteproxy/resources.py
===================================================================
--- trunk/inteproxy/resources.py 2007-05-16 14:54:41 UTC (rev 97)
+++ trunk/inteproxy/resources.py 2007-05-16 16:30:33 UTC (rev 98)
@@ -11,6 +11,9 @@
import os
import gettext as py_gettext
+def in_py2exe():
+ """Returns whether the program is running as a py2exe executable"""
+ return getattr(sys, "frozen", None) == "windows_exe"
# determine share_dir, the name of the directroy containing the resource
# files like images and translations. When run directly from the source
@@ -18,7 +21,7 @@
# this python module. When run from a frozen windows executable created
# with py2exe that doesn't work, but we can start from the directory
# containing the executable.
-if getattr(sys, "frozen", None) == "windows_exe":
+if in_py2exe():
_base_dir = os.path.dirname(sys.executable)
else:
_base_dir = os.path.join(os.path.dirname(__file__), os.pardir)
More information about the Inteproxy-commits
mailing list