Added new script used by new embedded python implementation.

This makes it easier to control restricted/unrestricted python
environments without requiring a client recompilation. Future
enhancements are now more likely to be strictly python code
changes.
This commit is contained in:
Greg Copeland 2008-07-24 16:09:52 +00:00
parent 7c36c0f0ef
commit b47d5722eb
2 changed files with 50 additions and 0 deletions

View File

@ -16,6 +16,9 @@ Version 1.5.2+svn:
areas and their schedules during scenario events. Removal requires to
associate an id. to [time_area]s, or it won't work.
* Python AI
* Added ai_init.py and ai_launcher.py to make it easier to customize
AI environment and startup. Both are used by the new embedded python
implementation.
* reversed builtin is now allowed. This allows for random.shuffle to be
called.

47
data/ais/ai_launcher.py Normal file
View File

@ -0,0 +1,47 @@
#!/bin/env python
# Copyright Greg Copeland, 2008
# Released under GPL license for Wesnoth. See Wesnoth's
# licensing terms for this module's specific license.
#
import os
import sys
import traceback
print "launch has been imported!"
def launch( script, restrict ):
# Launch one of two possible environments
# If restrict arg is True, run inside the available
# restrictied python environment (safe.py). If restrict
# is False, then run without any type of restrictions.
if restrict:
print "restricted environment detected - running parse/safe"
try:
import safe
import parse
parse.paths = ""
code, context = parse.parse( script )
safe.safe_exec( code, context, restrict )
except:
err = str( traceback.format_exc() )
raise
else:
print "unrestricted environment detected...running directly."
__import__( script )
scrpt = sys.modules[ script ]
# Call our entry points
scrpt.start()
scrpt.turn()
scrpt.end()
print "launch has completed."