Author: oracle
Date: Thu Jul 24 15:21:40 2008
New Revision: 28172

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28172&view=rev
Log:
Sets environment for new embedded python implementation.


Added:
    trunk/data/ais/ai_init.py

Added: trunk/data/ais/ai_init.py
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/ais/ai_init.py?rev=28172&view=auto
==============================================================================
--- trunk/data/ais/ai_init.py (added)
+++ trunk/data/ais/ai_init.py Thu Jul 24 15:21:40 2008
@@ -1,0 +1,29 @@
+# Copyright Greg Copeland, 2008
+# Released under GPL license for Wesnoth. See Wesnoth's
+# licensing terms for this module's specific license.
+
+# This file should only be called once per python instance. It
+# sets up stderr to a per python instance file.
+import os
+import sys
+import traceback
+
+
+def initEnv( instName ):
+    """
+    Initialize a python AI's environment. Call exactly once per
+    python instance. Call before an attempt to launch a python
+    AI is made.
+    """
+    # Create an output filename for each
+    # python instance.
+    fn = "pyerr-%s.txt" % (str(instName))
+
+    # Override stderr to write to a file
+    try:
+        errFile = file( fn, "wb" )
+        sys.stderr = errFile
+
+    except IOError, e:
+        sys.stderr.write( "Python: Unable to create '%s'; '%s'." % (fn, 
str(e)) )
+


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to