Made it so I can process command line arguments earlier

This commit is contained in:
bjschuma 2010-02-21 23:38:34 -05:00
parent cfbbdca966
commit a8c4b67aff
5 changed files with 38 additions and 15 deletions

View File

@ -34,6 +34,6 @@ def setname(name):
def setup():
app = session.settings["appname"]
write("Welcome to "+app+"!")
write("Welcome to "+app+"!",1)
setname(app)
session.settings["appdir"] = join(session.settings["user"], "."+app)

View File

@ -8,13 +8,16 @@ __date__ ="$Feb 16, 2010 11:56:00 PM$"
global scripts
import re
scripts = []
from bt.signal import register
from bt import file
from bt import cmd
from bt.message import write
global extension
extension = ["scion"]
def add(script):
global scripts
@ -22,6 +25,7 @@ def add(script):
def runScript(script):
from bt import cmd
f = file.fopen(script)
for line in f:
cmd.run(line)
@ -30,8 +34,17 @@ def runScript(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")
@ -41,4 +54,14 @@ def checkForScripts():
register("scion-begin",runScripts,0)
register("scion-plugins-loaded",checkForScripts)
# 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]
register("scion-plugins-loaded",checkForScripts)
register("scion-process-args",isScript)

View File

@ -23,10 +23,6 @@ class Settings(dict):
def setdefaults(self):
count = 0
if ("-v" in argv) or ("--verbose" in argv):
count = argv.count("-v") + argv.count("--verbose")
self['verbose'] = count
write("Setting default values",1)
self['user'] = os.path.expanduser("~")
self['plugpath'] = ["plugins", "extra"]

View File

@ -33,35 +33,39 @@ def setSession():
def parseInput():
from bt import scripting
write("Parsing user input",1)
input = sys.argv[1:]
write(input,True)
optc = "vp:s:"
long = ["verbose", "path=", "script="]
# Attempt to parse user input
try:
opts, args = getopt.getopt(input, optc, long)
settings["verbose"] = 0
for opt in opts:
if opt[0] == "-p":
if (opt[0]=="-p") or (opt[0]=="--path"):
settings["plugpath"] += [opt[1]]
elif opt[0] == "-s":
elif (opt[0]=="-s") or (opt[0]=="--script"):
scripting.add(opt[1])
settings["args"] = args
elif (opt[0]=="-v") or (opt[0]=="--verbose"):
settings["verbose"] += 1
for arg in args:
signal.emit("scion-process-args",arg)
#settings["args"] = args
except getopt.GetoptError, e:
write(e.msg)
write(input,2)
write("User input has been processed",1)
settings = Settings()
parseInput()
# We want to configure settings as early as possible
settings.setdefaults()
manager = Manager()
alias = Alias()
parseInput()
# Register functions to call when all plugins have been loaded
signal.register("scion-plugins-loaded",proc.setup,0)
signal.register("scion-plugins-loaded",setSession,1)

View File

@ -13,7 +13,7 @@ import button
import label
from bt.message import write
import manager
import settings
from session import settings
def empty(text=None,verbose=None):