Changed how commands are processed (before executing) to allow for
variable assignment and replacement
This commit is contained in:
parent
2dd819475f
commit
e074a74063
|
@ -9,6 +9,7 @@ __date__ ="$Feb 20, 2010 2:19:10 PM$"
|
|||
from bt.message import *
|
||||
from session import alias
|
||||
from session import manager
|
||||
from session import vars
|
||||
|
||||
|
||||
|
||||
|
@ -22,26 +23,72 @@ def runCmd(input):
|
|||
if len(split) > 1:
|
||||
args = split[1]
|
||||
|
||||
# Translate an alias to a command
|
||||
if alias.has(cmd):
|
||||
new = alias[cmd]
|
||||
if args==None:
|
||||
return runCmd(new)
|
||||
else:
|
||||
return runCmd(new+" "+args)
|
||||
|
||||
if (cmd in manager.enabled) == True:
|
||||
if args == None:
|
||||
return manager.enabled[cmd].start()
|
||||
else:
|
||||
return manager.enabled[cmd].start(args.split())
|
||||
else:
|
||||
return input
|
||||
|
||||
|
||||
# Check if we are storing in a variable
|
||||
def varCheck(cmd):
|
||||
split = cmd.split('=', 1)
|
||||
if len(split)==2 and len(split[0].split())==1:
|
||||
var = "$" + split[0].strip()
|
||||
write("Using variable: "+var, 2)
|
||||
return ( var, split[1].strip() )
|
||||
else:
|
||||
return (None, cmd)
|
||||
|
||||
|
||||
# Replace variables in the command with their real values
|
||||
def varReplace(cmd):
|
||||
split = cmd.split()
|
||||
out = ""
|
||||
for index,word in enumerate(split):
|
||||
if index > 0:
|
||||
out += " "
|
||||
if vars.has(word)==True:
|
||||
new = str(vars[word])
|
||||
write(word + " ==> " + new, 2)
|
||||
out += new
|
||||
else:
|
||||
out += word
|
||||
return out
|
||||
|
||||
|
||||
# Replace aliases with their real values
|
||||
def aliasReplace(cmd):
|
||||
split = cmd.split()
|
||||
out = ""
|
||||
for index,word in enumerate(split):
|
||||
if index > 0:
|
||||
out += " "
|
||||
if alias.has(word) == True:
|
||||
write(word + " ==> " + alias[word], 2)
|
||||
out += aliasReplace(alias[word])
|
||||
else:
|
||||
out += word
|
||||
return out
|
||||
|
||||
|
||||
def run(string):
|
||||
split = string.split(";")
|
||||
ans = []
|
||||
for command in split:
|
||||
ans += [runCmd(command.strip())]
|
||||
for cmd in split:
|
||||
(var,cmd) = varCheck(cmd)
|
||||
cmd = varReplace(cmd)
|
||||
cmd = aliasReplace(cmd)
|
||||
|
||||
result = runCmd(cmd)
|
||||
|
||||
if var == None:
|
||||
ans += [ result ]
|
||||
else:
|
||||
vars[var] = result
|
||||
|
||||
if len(ans) == 1:
|
||||
return ans[0]
|
||||
return ans
|
||||
|
|
|
@ -18,10 +18,13 @@ from bt.file import *
|
|||
from bt.message import write
|
||||
from manager import Manager
|
||||
from bt import proc
|
||||
from bt import dict
|
||||
|
||||
global alias
|
||||
global settings
|
||||
global manager
|
||||
global vars
|
||||
vars = dict.Dict()
|
||||
#global events
|
||||
|
||||
|
||||
|
|
|
@ -13,4 +13,7 @@ Scion 1.3 New Features
|
|||
- Began scripting
|
||||
|
||||
2 / 18 / 2010
|
||||
- Settings.init()
|
||||
- Settings.init()
|
||||
|
||||
2/ 24 / 2010
|
||||
- Moved from using signals to using events
|
|
@ -24,5 +24,5 @@ Scion To-Do List
|
|||
- Scripts
|
||||
- Better way to list signals, aliases, and settings
|
||||
- Command line options for plugins
|
||||
- Command line options to disable signals and/or scripting
|
||||
- Command line options to disable events and/or scripting
|
||||
- Plugin sub-function help ("help plugins disable")
|
||||
|
|
|
@ -1 +1 @@
|
|||
exec file tests/test.py
|
||||
exec file tests/test3.py
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
import session
|
||||
from bt.message import write
|
||||
|
||||
write(session.vars)
|
|
@ -0,0 +1,2 @@
|
|||
a = plugins list enabled
|
||||
exec file tests/test4.py
|
Loading…
Reference in New Issue