Removed old files, and some old modules. Made write() a system call

This commit is contained in:
bjschuma 2010-03-31 23:45:41 -04:00
parent e0f4eb45bb
commit d2ad9769bd
21 changed files with 54 additions and 429 deletions

View File

@ -1,3 +1,31 @@
from ocarina import vars
vars["$verbose"] = 4
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)

View File

@ -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:

View File

@ -19,6 +19,7 @@ vars["$path"] = "coreplug"
vars["$prompt"] = ">>>"
vars["$playonload"] = True
vars["$playing"] = False
vars["$writeenable"] = True
opts.parse()

View File

@ -2,5 +2,4 @@ __author__="bjschuma"
__date__ ="$Mar 13, 2010 4:20:16 PM$"
__all__ = ["call", "cmd", "dict", "message", "opts", "path",
"plugin", "slist", "times"]
__all__ = ["call", "dict", "opts", "path", "plugin", "slist", "times"]

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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 *

View File

@ -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)

View File

@ -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)

View File

@ -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))

View File

@ -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

View File

@ -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())

View File

@ -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))

View File

@ -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()

View File

@ -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()

View File

@ -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)

View File

@ -1,2 +0,0 @@
$playonload = False
#load ~/Music/theme-pokemon.mp3

View File

@ -1,5 +0,0 @@
#!/bin/bash
CORE=`pwd`/`dirname $0`"/core"
EXTRA=`pwd`/`dirname $0`"/extra"
cd && `which scion` "-p $CORE -p $EXTRA" $*