diff --git a/src/base/bt/__init__.py b/src/base/bt/__init__.py index a6d0c4e8..c0020d8c 100644 --- a/src/base/bt/__init__.py +++ b/src/base/bt/__init__.py @@ -2,4 +2,4 @@ # It contains various tools needed by the base layer of ocarina2 __all__ = ["alias", "file", "map", "message", "needle", "plugin", "proc", - "signal", "sql", "xm"] \ No newline at end of file + "scripting", "signal", "sql", "xm"] \ No newline at end of file diff --git a/src/base/bt/scripting.py b/src/base/bt/scripting.py new file mode 100644 index 00000000..69e8c948 --- /dev/null +++ b/src/base/bt/scripting.py @@ -0,0 +1,51 @@ +#! /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 +scripts = [] + +from bt.message import write +from bt.signal import * +from bt import file +import manager + + +def add(script): + global scripts + scripts += [script] + + +def runScript(script): + f = file.fopen(script) + for line in f: + write(line.strip(),True) + split = line.split(';') + for word in split: + cmd = word.strip().split() + if len(cmd)>1: + manager.run(cmd[0],cmd[1:]) + else: + manager.run(line) + #write(line.strip()) + + +def runScripts(): + #write(scripts) + for script in scripts: + runScript(script) + manager.run("exit") + + +def checkForScripts(): + global scripts + if len(scripts) > 0: + register("scion-begin",runScripts,50) + + +register("scion-plugins-loaded",checkForScripts) \ No newline at end of file diff --git a/src/base/scion.py b/src/base/scion.py index d38d0443..2128fd22 100644 --- a/src/base/scion.py +++ b/src/base/scion.py @@ -31,6 +31,8 @@ def main(): for path in settings.get("PLUGPATH"): loadPluginPath(path) + emit("scion-plugins-loaded") + app = settings.get("appname") write("Welcome to "+app+"!") setname(app) diff --git a/src/base/settings.py b/src/base/settings.py index c58ca0ff..25982e08 100644 --- a/src/base/settings.py +++ b/src/base/settings.py @@ -25,13 +25,6 @@ def set(key,value): settings[key] = value -from bt.message import write -from bt.message import error -from bt.file import fopen -from bt.file import join -from bt import xm - - # Return the value at key def get(key): key = key.upper() @@ -40,6 +33,17 @@ def get(key): return settings[key] +from bt.message import write +from bt.message import error +from bt.file import fopen +from bt.file import join +from bt import xm +from bt import scripting + + + + + def delete(key): key = key.upper() if has(key) == True: @@ -57,8 +61,8 @@ def parseInput(): write("Parsing user input",True) input = sys.argv[1:] write(input,True) - optc = "vp:" - long = ["verbose", "path="] + optc = "vp:s:" + long = ["verbose", "path=", "script="] # Attempt to parse user input try: @@ -66,7 +70,8 @@ def parseInput(): for opt in opts: if opt[0] == "-p": set("plugpath",get("plugpath")+[opt[1]]) - #set("PLUGPATH", opt[1]) + elif opt[0] == "-s": + scripting.add(opt[1]) set("ARGS", args) except getopt.GetoptError, e: error(e.msg) @@ -127,7 +132,7 @@ write("Setting default values...", True) # Find who is running the program user = os.path.expanduser("~") set("USER", user) -set("PLUGPATH", ["../core", "../extra"]) +set("PLUGPATH", ["core", "extra"]) # Find out what platform we are running on set("ARCH", sys.platform) diff --git a/src/doc/newFeatures.txt b/src/doc/newFeatures.txt index 87cc691f..58a300dd 100644 --- a/src/doc/newFeatures.txt +++ b/src/doc/newFeatures.txt @@ -7,4 +7,7 @@ Scion 1.3 New Features 2 / 16 / 2010 - Rename signals -- About plugin to give scion version information \ No newline at end of file +- About plugin to give scion version information + +2 / 17 / 2010 +- Began scripting \ No newline at end of file diff --git a/src/doc/signals.txt b/src/doc/signals.txt index fc5694c1..8ac2f614 100644 --- a/src/doc/signals.txt +++ b/src/doc/signals.txt @@ -36,3 +36,10 @@ scion-end: Removed in core.cli.Plugin.close() Removed in extra.sgtk.Plugin.close() + +scion-plugins-loaded: + Called right after loading all the plugins (before restoring settings or + enabling any plugins) + Emitted in scion.main() + + diff --git a/src/doc/todo.txt b/src/doc/todo.txt index b844089e..4059b3c9 100644 --- a/src/doc/todo.txt +++ b/src/doc/todo.txt @@ -5,7 +5,7 @@ Scion To-Do List - Add more signals - Scripting - Check during startup, register as callback if some token in first line - - Run script if given as an input arg, then exit + - Run script if given as an input arg, then exit (2/17/2010) - Run script after a signal has executed - Variables (dict with name->string) - *.scion == scripts. Allow adding to list of extensions @@ -25,5 +25,5 @@ Scion To-Do List - Scripts - Better way to list signals, aliases, and settings - Command line options for plugins -- Command line optionss to disable signals and/or scripting +- Command line options to disable signals and/or scripting - Plugin sub-function help ("help plugins disable") diff --git a/src/scion b/src/scion index 407e5b8b..0af2f904 100755 --- a/src/scion +++ b/src/scion @@ -1,4 +1,4 @@ #!/bin/bash -# This is a simple shell script for properly starting scion -cd base && `which python` scion.py $* +# This is a simple shell script for properly starting scio +`which python` base/scion.py $*