diff --git a/src/base/bt/message.py b/src/base/bt/message.py index 4cee3e56..037ee8da 100644 --- a/src/base/bt/message.py +++ b/src/base/bt/message.py @@ -8,14 +8,6 @@ import inspect import settings -# Print an error message -def error(text): - lineno = str(inspect.currentframe().f_back.f_lineno) - filename = inspect.currentframe().f_back.f_code.co_filename - filename = filename.rsplit(os.sep,1)[1] - print filename,"("+lineno+"):",text - - def disp(text): print text @@ -27,4 +19,12 @@ def write(text,verbose=False): w(text) +# Print an error message +def error(text): + lineno = str(inspect.currentframe().f_back.f_lineno) + filename = inspect.currentframe().f_back.f_code.co_filename + filename = filename.rsplit(os.sep,1)[1] + write(filename+" ("+lineno+"): "+text,True) + + settings.set("write", disp) \ No newline at end of file diff --git a/src/base/settings.py b/src/base/settings.py index faa52efd..f3ab8e1a 100644 --- a/src/base/settings.py +++ b/src/base/settings.py @@ -38,13 +38,24 @@ def get(key, all=False): return settings[key.upper()] +# Replace settings[key] with value def replace(key,value): global settings + key = key.upper() if (key in settings) == True: del settings[key] set(key,value) +# Pop off the first value at key.upper() +def pop(key): + key = key.upper() + global settings + if (key in settings.keys()) == True: + return settings[key].pop(0) + return None + + # Read settings from file def readfile(file): write("Reading file: "+file,True) @@ -56,12 +67,16 @@ def parseInput(): write("Parsing user input",True) input = sys.argv[1:] write(input,True) - optc = "v" - long = ["verbose"] + optc = "vp:" + long = ["verbose", "path="] # Attempt to parse user input try: opts, args = getopt.getopt(input, optc, long) + for opt in opts: + if opt[0] == "-p": + set("PLUGPATH", opt[1]) + set("ARGS", args) except getopt.GetoptError, e: error(e.msg) return @@ -74,14 +89,14 @@ write("Setting default values...", True) # Find who is running the program user = os.path.expanduser("~") -user = os.path.join(user,".ocarina2") +#user = os.path.join(user,".ocarina2") set("USER", user) set("PLUGPATH", "../core") # Find out what platform we are running on set("ARCH", sys.platform) -if get("ARCH") == 'linux2': - readfile("/etc/ocarina.conf") +#if get("ARCH") == 'linux2': +# readfile("/etc/ocarina.conf") parseInput() \ No newline at end of file diff --git a/src/core/cli.py b/src/core/cli.py index f73e0e3b..30347ffd 100644 --- a/src/core/cli.py +++ b/src/core/cli.py @@ -19,44 +19,49 @@ import cline.loop import cline.message import settings -global maxxy, stdscr, thread +global maxyx, stdscr, thread threads = [] # Called every time the plugin is enabled def open(): write("Starting CLI", True) - global maxxy, stdscr, thread + global maxyx, stdscr, thread # Initialize ncurses screen stdscr = curses.initscr() - maxxy = stdscr.getmaxyx() + maxyx = stdscr.getmaxyx() curses.cbreak() curses.noecho() stdscr.keypad(1) # Set these values in settings class for use elsewhere settings.set("stdscr", stdscr) - settings.set("maxxy", maxxy) + settings.set("maxyx", maxyx) settings.set("prompt", ">>> ") settings.set("clinex", 0) settings.set("cliney", 0) - settings.set("write", cline.message.insert) # Start loop in new thread thread = bt.needle.Needle(cline.loop.loop) thread.start() + settings.set("write", cline.message.insert) + # Called every time the plugin is stopped def close(): global stdscr, thread + + settings.pop("write") + + # Stop looping + cline.loop.quit() + # Undo ncurses initialization curses.nocbreak() curses.echo() stdscr.keypad(0) curses.endwin() - # Stop looping - cline.loop.quit() #thread.join() write("CLI has been stopped", True) diff --git a/src/core/cline/addch.py b/src/core/cline/addch.py index 72727f2d..4c0a92ee 100644 --- a/src/core/cline/addch.py +++ b/src/core/cline/addch.py @@ -9,7 +9,7 @@ __date__ ="$Dec 19, 2009 11:19:43 PM$" import curses import settings - +from bt.message import write from run import run # (Sometimes) add a character to the input string @@ -44,5 +44,6 @@ def backspace(input): # Attempt to run a command def enter(input): + write(input) input = run(input) return input \ No newline at end of file diff --git a/src/core/cline/message.py b/src/core/cline/message.py index f8e97796..daf93985 100644 --- a/src/core/cline/message.py +++ b/src/core/cline/message.py @@ -6,20 +6,31 @@ __author__="bjschuma" __date__ ="$Dec 19, 2009 11:57:19 PM$" + +import curses import settings +import bt.message # Add string to line y def insert(string): stdscr = settings.get("stdscr") + max = settings.get("maxyx")[0] y = settings.get("cliney") - y+=1 - settings.replace("cliney", y) + stdscr.addstr(y, 0, string) + if y < (max-1): + settings.replace("cliney", y+1) + else: + stdscr.move(0,0) + stdscr.deleteln() + # Replace the string on the current line def disp(string): stdscr = settings.get("stdscr") - stdscr.addstr(settings.get("cliney"), 0, string) - #insert(string, settings.get("cliney")) + try: + stdscr.addstr(settings.get("cliney"), 0, string) + except: + bt.message.error("Error displaying string: "+string) diff --git a/src/core/cline/run.py b/src/core/cline/run.py index 19e7c8ec..21a2c404 100644 --- a/src/core/cline/run.py +++ b/src/core/cline/run.py @@ -8,20 +8,22 @@ __date__ ="$Dec 19, 2009 11:38:46 PM$" from manager import manager import settings +from bt.message import write # Check for valid input def run(input): prompt = input[0:4] - input = input[4:] - split = input.strip().split() + input = input[4:].strip() + + #if len(input) == 0: + # return prompt + + split = input.split(' ') if len(split)>1: manager.run(split[0],split[1:]) else: manager.run(input) - y = settings.get("cliney") - y+=1 - settings.replace("cliney", y) return prompt diff --git a/src/install.sh b/src/install.sh index ef247508..a89fe077 100644 --- a/src/install.sh +++ b/src/install.sh @@ -7,7 +7,7 @@ rsync -avz --progress core /opt/scion/ FILE="/usr/bin/scion" touch $FILE echo "#!/bin/bash" > $FILE -echo "cd /opt/scion/base && \`which python\` scion.py \$\*" >> $FILE +echo "cd /opt/scion/base && \`which python\` scion.py \$*" >> $FILE chmod +x $FILE diff --git a/src/scion b/src/scion index 2bb3babc..b15c3db4 100755 --- a/src/scion +++ b/src/scion @@ -1,4 +1,4 @@ #!/bin/bash -# This is a simple shell script for properly starting ocarina -cd /opt/scion/base && `which python` scion.py $* \ No newline at end of file +# This is a simple shell script for properly starting scion +cd base && `which python` scion.py $*