Changed how variable replacement works.

This commit is contained in:
bjschuma 2010-02-28 15:44:40 -05:00
parent 3d89fc26a0
commit 54bd397584
7 changed files with 48 additions and 16 deletions

View File

@ -36,7 +36,9 @@ def runCmd(input):
def varCheck(cmd): def varCheck(cmd):
split = cmd.split('=', 1) split = cmd.split('=', 1)
if len(split)==2 and len(split[0].split())==1: if len(split)==2 and len(split[0].split())==1:
var = "$" + split[0].strip() var = split[0].strip()
if not var[0]=="$":
var = "$" + var
write("Using variable: "+var, 2) write("Using variable: "+var, 2)
return ( var, split[1].strip() ) return ( var, split[1].strip() )
else: else:
@ -45,18 +47,13 @@ def varCheck(cmd):
# Replace variables in the command with their real values # Replace variables in the command with their real values
def varReplace(cmd): def varReplace(cmd):
split = cmd.split() for key in vars.keys():
out = "" v = "`"+key+"`"
for index,word in enumerate(split): if cmd.find(v) > -1:
if index > 0: new = str(vars[key])
out += " " write(key + " => " + new, 2)
if vars.has(word)==True: cmd = cmd.replace(v, new)
new = str(vars[word]) return cmd
write(word + " => " + new, 2)
out += new
else:
out += word
return out
# Replace aliases with their real values # Replace aliases with their real values

View File

@ -47,7 +47,7 @@ class PluginLoader:
# Load the module into our module array # Load the module into our module array
write("Attempting to load "+mod, 2) write("Attempting to load "+mod, 2)
#try: #try:
self.loadmod(split[0], os.path.join(dir,mod)) self.loadmod(split[0], dir)
#except: #except:
# error("Error loading "+mod) # error("Error loading "+mod)

View File

@ -25,7 +25,6 @@ global settings
global manager global manager
global vars global vars
vars = dict.Dict() vars = dict.Dict()
#global events
def setSession(): def setSession():
@ -48,6 +47,7 @@ def parseInput():
try: try:
opts, args = getopt.getopt(input, optc, long) opts, args = getopt.getopt(input, optc, long)
settings["verbose"] = 0 settings["verbose"] = 0
settings["plugpath"] = []
for opt in opts: for opt in opts:
if (opt[0]=="-p") or (opt[0]=="--path"): if (opt[0]=="-p") or (opt[0]=="--path"):
settings["plugpath"] += [opt[1]] settings["plugpath"] += [opt[1]]

View File

@ -26,7 +26,7 @@ class Settings(dict.Dict):
def setdefaults(self): def setdefaults(self):
write("Setting default values",1) write("Setting default values",1)
self['user'] = os.path.expanduser("~") self['user'] = os.path.expanduser("~")
self['plugpath'] = ["plugins", "extra"] self['plugpath'] += ["plugins", "extra"]
self['arch'] = platform self['arch'] = platform
self['appname'] = "scion" self['appname'] = "scion"
write(self,3) write(self,3)

31
src/plugins/sess.py Normal file
View File

@ -0,0 +1,31 @@
# Basic plugin class
__author__="bjschuma"
__date__ ="$Feb 26, 2010 9:13:54 PM$"
from bt import plugin
from bt.message import write
import session
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
self.help = "Display information about the current session"
self.usage = "session [list]"
def list(self,args):
if args[0] == "settings":
write(session.aliases)
def run(self, args=None):
if args==None or len(args)<2:
write(usage)
if args[0]=="list":
self.list(args[1:])

2
src/tests/test5.2.scion Normal file
View File

@ -0,0 +1,2 @@
echo Second file started
echo $a

2
src/tests/test5.scion Normal file
View File

@ -0,0 +1,2 @@
$a = test
exec file tests/test5.2.scion