From d2ad9769bd34051a3350748b626e2e4ea50ef5e3 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Wed, 31 Mar 2010 23:45:41 -0400 Subject: [PATCH] Removed old files, and some old modules. Made write() a system call --- src/config.py | 32 ++++++++++- src/core/cli.py | 18 ++++--- src/core/coredefaults.py | 1 + src/core/ct/__init__.py | 3 +- src/core/ct/call.py | 14 +++-- src/core/ct/cmd.py | 113 --------------------------------------- src/core/ct/message.py | 38 ------------- src/core/gstreamer.py | 14 +---- src/core/manager.py | 56 ------------------- src/core/ocarina-core.py | 1 - src/core/ocarina.py | 7 --- src/core/scripting.py | 39 -------------- src/coreplug/echo.py | 18 ------- src/coreplug/exit.py | 20 ------- src/coreplug/list.py | 26 --------- src/coreplug/load.py | 18 ------- src/coreplug/pause.py | 18 ------- src/coreplug/play.py | 19 ------- src/coreplug/stop.py | 21 -------- src/corescr/init.oc | 2 - src/ocarina | 5 -- 21 files changed, 54 insertions(+), 429 deletions(-) delete mode 100644 src/core/ct/cmd.py delete mode 100644 src/core/ct/message.py delete mode 100644 src/core/manager.py delete mode 100644 src/core/scripting.py delete mode 100644 src/coreplug/echo.py delete mode 100644 src/coreplug/exit.py delete mode 100644 src/coreplug/list.py delete mode 100644 src/coreplug/load.py delete mode 100644 src/coreplug/pause.py delete mode 100644 src/coreplug/play.py delete mode 100644 src/coreplug/stop.py delete mode 100644 src/corescr/init.oc delete mode 100755 src/ocarina diff --git a/src/config.py b/src/config.py index 5537c2d7..2d8fa38a 100644 --- a/src/config.py +++ b/src/config.py @@ -1,3 +1,31 @@ -from ocarina import vars -vars["$verbose"] = 4 \ No newline at end of file +import ocarina +from ct.opts import args +from ct.path import * +from ct.call import * + +# Disable immediately playing a song when it is loaded +ocarina.vars["$playonload"] = False + +# Load a song if we were passed one on load +space = ' ' +song = space.join(args) +if exists( song ): + load(song) + + +# Enable readline tab completion +import readline +import rlcompleter +readline.parse_and_bind("tab:complete") + +# Configure readline history. +# This file is written after every command entered, but you can comment out +# these lines to ignore the file +history = join(ocarina.vars["$ocarina"],"history") +if exists( history ): + readline.read_history_file(history) + +# Set the max number of lines to store in the history file. +# A negative number means unlimited length +readline.set_history_length(50) \ No newline at end of file diff --git a/src/core/cli.py b/src/core/cli.py index b0950ef5..8cf4e75a 100644 --- a/src/core/cli.py +++ b/src/core/cli.py @@ -6,22 +6,26 @@ __author__="bjschuma" __date__ ="$Mar 13, 2010 9:08:56 PM$" -import readline -import rlcompleter - import ocarina -readline.parse_and_bind("tab:complete") +from ct.path import * from ct.call import * -from ct.message import * +import readline + +global history +history = join(ocarina.vars["$ocarina"],"history") def loop(): while True: try: - enable() + state = ocarina.vars["$writeenable"] + ocarina.vars["$writeenable"] = True exec raw_input(ocarina.vars["$prompt"] + " ") - restore() + ocarina.vars["$writeenable"] = state + + global history + readline.write_history_file(history) # Catch this so that we can use ctrl-d to exit except EOFError: diff --git a/src/core/coredefaults.py b/src/core/coredefaults.py index fd0e7669..01643e7c 100644 --- a/src/core/coredefaults.py +++ b/src/core/coredefaults.py @@ -19,6 +19,7 @@ vars["$path"] = "coreplug" vars["$prompt"] = ">>>" vars["$playonload"] = True vars["$playing"] = False +vars["$writeenable"] = True opts.parse() diff --git a/src/core/ct/__init__.py b/src/core/ct/__init__.py index 63529afb..ff944f0b 100644 --- a/src/core/ct/__init__.py +++ b/src/core/ct/__init__.py @@ -2,5 +2,4 @@ __author__="bjschuma" __date__ ="$Mar 13, 2010 4:20:16 PM$" -__all__ = ["call", "cmd", "dict", "message", "opts", "path", - "plugin", "slist", "times"] \ No newline at end of file +__all__ = ["call", "dict", "opts", "path", "plugin", "slist", "times"] \ No newline at end of file diff --git a/src/core/ct/call.py b/src/core/ct/call.py index fb08d05c..b83cad50 100644 --- a/src/core/ct/call.py +++ b/src/core/ct/call.py @@ -8,11 +8,15 @@ __date__ ="$Mar 30, 2010 11:24:43 PM$" import ocarina -from ct import message from ct import times from ct import path +def write(s,verbose): + if (ocarina.vars["$writeenable"]==True) and (ocarina.vars["$verbose"]>=verbose): + print str(s) + + def load(path): '''Load the song located at path''' import gstreamer @@ -26,14 +30,14 @@ def seek(prcnt): import gstreamer good = gstreamer.seek(prcnt) if good == -1: - message.write("There was an error seeking to: "+str(prcnt)) + write("There was an error seeking to: "+str(prcnt)) def progress(): '''Return the fraction of the song that we have already played''' import gstreamer progress = gstreamer.getProgress() - message.write(progress) + write(progress) return progress @@ -43,7 +47,7 @@ def duration(): hh:mm:ss form''' import gstreamer duration = gstreamer.duration() - message.write(times.ms2str(duration)) + write(times.ms2str(duration)) return duration @@ -84,5 +88,5 @@ def stop(): def pyfile(file): '''If file exists, try to execute it as a python script''' if path.exists(file) == True: - message.write("Running script: "+file,1) + write("Running script: "+file,1) execfile(file) \ No newline at end of file diff --git a/src/core/ct/cmd.py b/src/core/ct/cmd.py deleted file mode 100644 index f787a383..00000000 --- a/src/core/ct/cmd.py +++ /dev/null @@ -1,113 +0,0 @@ -#! /usr/bin/python - -# To change this template, choose Tools | Templates -# and open the template in the editor. - -__author__="bjschuma" -__date__ ="$Feb 20, 2010 2:19:10 PM$" - -from ct.message import * -from ocarina import alias -from ocarina import plugins -from ocarina import vars - - - -def runCmd(input): - write("Running command: "+input,2) - - # Find command - split = input.split(' ',1) - cmd = split[0] - args=None - if len(split) > 1: - args = split[1] - - try: - result = ocarina.plugins.run(cmd,args) - except: - result = None - - if result == None: - return input - else: - return result - - -# 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() - if not var[0]=="$": - var = "$" + var - 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): - for key in vars.keys(): - v = "`"+key+"`" - if cmd.find(v) > -1: - new = str(vars[key]) - write(key + " => " + new, 2) - cmd = cmd.replace(v, new) - return cmd - - -# 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 fixType(text): - if text.lower() == "false": - return False - elif text.lower() == "true": - return True - elif text.isdigit()==True: - return int(text) - return text - - -def run(string): - split = string.split(";") - ans = [] - for cmd in split: - (var,cmd) = varCheck(cmd) - cmd = varReplace(cmd) - cmd = aliasReplace(cmd) - - if var == None: - ans += [ runCmd(cmd) ] - else: - disable() - vars[var] = fixType( runCmd(cmd) ) - enable() - - if len(ans) == 1: - return ans[0] - return ans - - -def call(string): - # disable text printing - disable() - result = run(string) - # enable text printing - enable() - return result - diff --git a/src/core/ct/message.py b/src/core/ct/message.py deleted file mode 100644 index 3ebf5829..00000000 --- a/src/core/ct/message.py +++ /dev/null @@ -1,38 +0,0 @@ -#! /usr/bin/python - -__author__="bjschuma" -__date__ ="$Mar 13, 2010 4:32:22 PM$" - -import ocarina - -global enabled -global lastState -enabled = True -lastState = True - - -def write(s,verbose=0): - global enabled - if (enabled==True) and (ocarina.vars["$verbose"] >= verbose): - s = str(s) - print s - - -def disable(): - global enabled - global lastState - lastState = enabled - enabled = False - - -def enable(): - global enabled - global lastState - lastState = enabled - enabled = True - - -def restore(): - global enabled - global lastState - enabled = lastState \ No newline at end of file diff --git a/src/core/gstreamer.py b/src/core/gstreamer.py index 2c00ac37..a133889b 100644 --- a/src/core/gstreamer.py +++ b/src/core/gstreamer.py @@ -4,7 +4,8 @@ __author__ = "bjschuma" __date__ = "$Feb 5, 2010 7:53:19 PM$" from ct import path -from ct.message import write +#from ct.message import write +from ct.call import write from ct.opts import args import gst import ocarina @@ -72,16 +73,6 @@ def uninit(): player.set_state(gst.STATE_NULL) -def init(): - #ocarina.events.invite("ocarina-stop",uninit) - if len(args) == 0: - return - space = ' ' - song = space.join(args) - load(song) - - - def onMessage(bus, message): #print message.type @@ -153,7 +144,6 @@ def seek(prcnt,fraction=False): bus.add_signal_watch() bus.connect("message", onMessage) -ocarina.events.invite("ocarina-start", init, 60) ocarina.events.invite("ocarina-stop", uninit) ocarina.events.invite("ocarina-play", play,50) ocarina.events.invite("ocarina-pause", pause,50) diff --git a/src/core/manager.py b/src/core/manager.py deleted file mode 100644 index 46e46784..00000000 --- a/src/core/manager.py +++ /dev/null @@ -1,56 +0,0 @@ -#! /usr/bin/python - -# To change this template, choose Tools | Templates -# and open the template in the editor. - -__author__="bjschuma" -__date__ ="$Mar 14, 2010 3:06:37 PM$" - -import re -import sys - -import ocarina - -from ct.message import write -from ct import path -from ct.dict import Dict - - -class PlManager(Dict): - def __init__(self): - Dict.__init__(self) - write("Creating Plugin Manager",1) - #self.plugins = dict() - - - def load(self, name): - write("Importing plugin: "+name, 2) - __import__(name) - plugin = sys.modules[name].Plugin() - plugin.enabled = True - self[name] = plugin - - - def run(self,name,args=None): - if self[name].enabled == True: - if args == None: - args = [] - else: - args = args.split() - return self[name].start(args) - return None - - - - - -def init(): - ocarina.plugins = PlManager() - - for p in ocarina.vars["$path"].split(":"): - for mod in path.addPyPath(p): - ocarina.plugins.load(mod) - - -ocarina.events.invite("ocarina-start",init,5) - \ No newline at end of file diff --git a/src/core/ocarina-core.py b/src/core/ocarina-core.py index fabdb2db..8f7d2e5d 100644 --- a/src/core/ocarina-core.py +++ b/src/core/ocarina-core.py @@ -6,7 +6,6 @@ __date__ ="$Mar 13, 2010 4:19:31 PM$" import ocarina import coredefaults -from ct.message import write import cli from ct.call import * diff --git a/src/core/ocarina.py b/src/core/ocarina.py index 45c0273a..9186f1d6 100644 --- a/src/core/ocarina.py +++ b/src/core/ocarina.py @@ -11,9 +11,7 @@ import event global vars global events -#settings = Dict() vars = Dict() -#alias = Dict() events = event.Event() plugins = None @@ -24,8 +22,3 @@ def config(): config = "config.py" pyfile(path.join(vars["$ocarina"],config)) pyfile(config) - - #config = "config.py" - #config = path.join(vars["$ocarina"],"config.py") - #from ct.call import pyfile - #pyfile(config) \ No newline at end of file diff --git a/src/core/scripting.py b/src/core/scripting.py deleted file mode 100644 index d6557bd1..00000000 --- a/src/core/scripting.py +++ /dev/null @@ -1,39 +0,0 @@ -#! /usr/bin/python - -# To change this template, choose Tools | Templates -# and open the template in the editor. - -__author__="bjschuma" -__date__ ="$Mar 14, 2010 7:33:16 PM$" - -import re -from ct import cmd -import ocarina - - -def runOcaScript(file): - fin = open(file) - for line in fin: - # Do some formatting for each line - line = line.split("#",1)[0] - line = line.strip() - if len(line) > 0: - cmd.run(line) - - -def runScript(file): - if re.match("(.*?)\.py",file) == None: - runOcaScript(file) - else: - try: - execfile(file) - except: - print "Error in: " + file - - - -def init(): - runScript("corescr/init.oc") - - -ocarina.events.invite("ocarina-start",init,10) \ No newline at end of file diff --git a/src/coreplug/echo.py b/src/coreplug/echo.py deleted file mode 100644 index 9e91bf6e..00000000 --- a/src/coreplug/echo.py +++ /dev/null @@ -1,18 +0,0 @@ -#! /usr/bin/python - -__author__="bjschuma" -__date__ ="$Mar 14, 2010 4:29:57 PM$" - - -from ct import plugin -from ct.message import write - -class Plugin(plugin.Plugin): - def __init__(self): - plugin.Plugin.__init__(self) - - - def run(self,args): - space = ' ' - write(space.join(args)) - diff --git a/src/coreplug/exit.py b/src/coreplug/exit.py deleted file mode 100644 index f7ee60a9..00000000 --- a/src/coreplug/exit.py +++ /dev/null @@ -1,20 +0,0 @@ -#! /usr/bin/python - -# To change this template, choose Tools | Templates -# and open the template in the editor. - -__author__="bjschuma" -__date__ ="$Mar 14, 2010 3:02:10 PM$" - -import ocarina -from ct import plugin - - -class Plugin(plugin.Plugin): - def __init__(self): - plugin.Plugin.__init__(self) - - - def run(self,args): - ocarina.events.start("ocarina-stop") - #print args diff --git a/src/coreplug/list.py b/src/coreplug/list.py deleted file mode 100644 index d1f376fb..00000000 --- a/src/coreplug/list.py +++ /dev/null @@ -1,26 +0,0 @@ -#! /usr/bin/python - -__author__="bjschuma" -__date__ ="$Mar 14, 2010 7:17:57 PM$" - -import ocarina - -from ct import plugin -from ct.message import write - -class Plugin(plugin.Plugin): - def __init__(self): - plugin.Plugin.__init__(self) - self.minarg = 1 - - - def run(self,args): - for arg in args: - arg = arg.lower() - if arg == "events": - write(ocarina.events.keys()) - elif arg == "plugins": - write(ocarina.plugins.keys()) - elif arg == "vars": - write(ocarina.vars.keys()) - diff --git a/src/coreplug/load.py b/src/coreplug/load.py deleted file mode 100644 index ed78ed3b..00000000 --- a/src/coreplug/load.py +++ /dev/null @@ -1,18 +0,0 @@ -#! /usr/bin/python - -__author__="bjschuma" -__date__ ="$Mar 14, 2010 5:25:41 PM$" - -from ct import plugin -import gstreamer - - -class Plugin(plugin.Plugin): - def __init__(self): - plugin.Plugin.__init__(self) - - - def run(self,args): - space = " " - gstreamer.load(space.join(args)) - diff --git a/src/coreplug/pause.py b/src/coreplug/pause.py deleted file mode 100644 index 9797cdc5..00000000 --- a/src/coreplug/pause.py +++ /dev/null @@ -1,18 +0,0 @@ -#! /usr/bin/python - -__author__="bjschuma" -__date__ ="$Mar 14, 2010 5:16:51 PM$" - -from ct import plugin -import ocarina -#import gstreamer - -class Plugin(plugin.Plugin): - def __init__(self): - plugin.Plugin.__init__(self) - - - def run(self,args): - ocarina.events.start("ocarina-pause") - #gstreamer.pause() - diff --git a/src/coreplug/play.py b/src/coreplug/play.py deleted file mode 100644 index 70e588ac..00000000 --- a/src/coreplug/play.py +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/python - -__author__="bjschuma" -__date__ ="$Mar 14, 2010 5:12:02 PM$" - -from ct import plugin -import ocarina -#import gstreamer - - -class Plugin(plugin.Plugin): - def __init__(self): - plugin.Plugin.__init__(self) - - - def run(self,args): - ocarina.events.start("ocarina-play") - #gstreamer.play() - diff --git a/src/coreplug/stop.py b/src/coreplug/stop.py deleted file mode 100644 index b69fbe85..00000000 --- a/src/coreplug/stop.py +++ /dev/null @@ -1,21 +0,0 @@ -#! /usr/bin/python - -__author__="bjschuma" -__date__ ="$Mar 18, 2010 12:16:07 AM$" - -import ocarina - -from ct import plugin -from ct.message import write -from ct import cmd -import gstreamer - -class Plugin(plugin.Plugin): - def __init__(self): - plugin.Plugin.__init__(self) - - - def run(self,args): - cmd.run("pause") - gstreamer.seek(0) - diff --git a/src/corescr/init.oc b/src/corescr/init.oc deleted file mode 100644 index 0a4badea..00000000 --- a/src/corescr/init.oc +++ /dev/null @@ -1,2 +0,0 @@ -$playonload = False -#load ~/Music/theme-pokemon.mp3 \ No newline at end of file diff --git a/src/ocarina b/src/ocarina deleted file mode 100755 index d471a2c5..00000000 --- a/src/ocarina +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -CORE=`pwd`/`dirname $0`"/core" -EXTRA=`pwd`/`dirname $0`"/extra" -cd && `which scion` "-p $CORE -p $EXTRA" $*