ocarina/src/core/bt/scripting.py

74 lines
1.4 KiB
Python

#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Feb 16, 2010 11:56:00 PM$"
global scripts
import re
scripts = []
from bt import file
from bt.message import write
import session
global extension
extension = ["scion","py"]
def add(script):
global scripts
scripts += [script]
def runScript(script):
# Run commands if the script is not a python script
if re.match("(\/|\w)*\.py",script) == None:
from bt import cmd
f = file.fopen(script)
for line in f:
cmd.run(line)
f.close()
# Execute the script with the python interpreter as a backend
else:
write("Running python script: "+script,2)
execfile(script)
def runScripts():
global scripts
write("===== Begin output =====",1)
write(" ",1)
for script in scripts:
runScript(script)
write(" ",1)
write("====== End output ======",1)
from bt import cmd
cmd.run("exit")
def checkForScripts():
global scripts
if len(scripts) > 0:
session.events.invite("scion-begin",runScripts,0)
# If the given file is a script, we add it to the script list
def isScript(script):
global scripts
write("Checking if file is a script: "+script,2)
for ext in extension:
if not re.match("(\/|\w)*\."+ext,script) == None:
scripts += [script]
session.events.invite("scion-plugins-loaded",checkForScripts)
session.events.invite("scion-process-args",isScript)