Added system calls and documentation. Read a config file on ocarina
startup
This commit is contained in:
parent
e9561d5351
commit
e0f4eb45bb
|
@ -1,4 +1,4 @@
|
||||||
java.lib.path=
|
java.lib.path=
|
||||||
platform.active=Python_2.6.4
|
platform.active=Python_2.6.4
|
||||||
python.lib.path=
|
python.lib.path=/home/bjschuma/Programs/ocarina/src/core|/home/bjschuma/Programs/ocarina/src/core/ct|/home/bjschuma/Programs/ocarina/src/extra|
|
||||||
src.dir=src
|
src.dir=src
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
from ocarina import vars
|
||||||
|
vars["$verbose"] = 4
|
|
@ -11,13 +11,17 @@ import rlcompleter
|
||||||
|
|
||||||
import ocarina
|
import ocarina
|
||||||
readline.parse_and_bind("tab:complete")
|
readline.parse_and_bind("tab:complete")
|
||||||
|
|
||||||
from ct.call import *
|
from ct.call import *
|
||||||
|
from ct.message import *
|
||||||
|
|
||||||
|
|
||||||
def loop():
|
def loop():
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
enable()
|
||||||
exec raw_input(ocarina.vars["$prompt"] + " ")
|
exec raw_input(ocarina.vars["$prompt"] + " ")
|
||||||
|
restore()
|
||||||
|
|
||||||
# Catch this so that we can use ctrl-d to exit
|
# Catch this so that we can use ctrl-d to exit
|
||||||
except EOFError:
|
except EOFError:
|
||||||
|
@ -27,4 +31,4 @@ def loop():
|
||||||
print e
|
print e
|
||||||
|
|
||||||
|
|
||||||
ocarina.events.invite("ocarina-start",loop)
|
#ocarina.events.invite("ocarina-start",loop)
|
|
@ -8,6 +8,7 @@ __date__ ="$Mar 15, 2010 9:53:46 PM$"
|
||||||
|
|
||||||
import ocarina
|
import ocarina
|
||||||
from ct import path
|
from ct import path
|
||||||
|
from ct import opts
|
||||||
from ocarina import vars
|
from ocarina import vars
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +21,13 @@ vars["$playonload"] = True
|
||||||
vars["$playing"] = False
|
vars["$playing"] = False
|
||||||
|
|
||||||
|
|
||||||
ocarina.init()
|
opts.parse()
|
||||||
import scripting
|
path.mkdir(vars["$ocarina"])
|
||||||
import manager
|
|
||||||
|
# Set verbose value
|
||||||
|
if opts.opts.has("v") == True:
|
||||||
|
vars["$verbose"] += opts.opts["v"]
|
||||||
|
if opts.opts.has("verbose") == True:
|
||||||
|
vars["$verbose"] += opts.opts["verbose"]
|
||||||
|
|
||||||
import gstreamer
|
import gstreamer
|
||||||
|
|
|
@ -2,4 +2,5 @@ __author__="bjschuma"
|
||||||
__date__ ="$Mar 13, 2010 4:20:16 PM$"
|
__date__ ="$Mar 13, 2010 4:20:16 PM$"
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["call", "cmd", "dict", "message", "opts", "path", "plugin","slist"]
|
__all__ = ["call", "cmd", "dict", "message", "opts", "path",
|
||||||
|
"plugin", "slist", "times"]
|
|
@ -1,33 +1,88 @@
|
||||||
#! /usr/bin/python
|
#! /usr/bin/python
|
||||||
|
|
||||||
# To change this template, choose Tools | Templates
|
'''These are core Ocarina system calls that should help in both development
|
||||||
# and open the template in the editor.
|
of future Ocarina features and in usage of ocarina-core'''
|
||||||
|
|
||||||
__author__="bjschuma"
|
__author__="bjschuma"
|
||||||
__date__ ="$Mar 30, 2010 11:24:43 PM$"
|
__date__ ="$Mar 30, 2010 11:24:43 PM$"
|
||||||
|
|
||||||
|
|
||||||
import ocarina
|
import ocarina
|
||||||
|
from ct import message
|
||||||
|
from ct import times
|
||||||
|
from ct import path
|
||||||
|
|
||||||
|
|
||||||
def load(path):
|
def load(path):
|
||||||
|
'''Load the song located at path'''
|
||||||
import gstreamer
|
import gstreamer
|
||||||
gstreamer.load(path)
|
gstreamer.load(path)
|
||||||
|
|
||||||
|
|
||||||
def seek(prcnt):
|
def seek(prcnt):
|
||||||
|
''' Seek to prcnt% of the song. If 0 < prcnt < 1, then we will seek to
|
||||||
|
(prcnt * 100)% of song's duration. If prcnt < 100, then we will seek
|
||||||
|
to prcnt% of the song's duration.'''
|
||||||
import gstreamer
|
import gstreamer
|
||||||
gstreamer.seek(prcnt)
|
good = gstreamer.seek(prcnt)
|
||||||
|
if good == -1:
|
||||||
|
message.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)
|
||||||
|
return progress
|
||||||
|
|
||||||
|
|
||||||
|
def duration():
|
||||||
|
'''Return the total duration of the song. If message printing is enabled,
|
||||||
|
then we will also print out string representing the duration in
|
||||||
|
hh:mm:ss form'''
|
||||||
|
import gstreamer
|
||||||
|
duration = gstreamer.duration()
|
||||||
|
message.write(times.ms2str(duration))
|
||||||
|
return duration
|
||||||
|
|
||||||
|
|
||||||
|
def time():
|
||||||
|
'''Returns how far into the song gstreamer currently is. If message printing
|
||||||
|
is enabled, then we will also print out a string representing the duration in
|
||||||
|
hh:mm:ss form'''
|
||||||
|
import gstreamer
|
||||||
|
time = gstreamer.currentpos()
|
||||||
|
message.write(times.ms2str(time))
|
||||||
|
return time
|
||||||
|
|
||||||
|
|
||||||
|
def gsstate():
|
||||||
|
'''Returns the current gstreamer state'''
|
||||||
|
import gstreamer
|
||||||
|
state = gstreamer.getstate()
|
||||||
|
message.write(state)
|
||||||
|
return state
|
||||||
|
|
||||||
|
|
||||||
def play():
|
def play():
|
||||||
|
'''Begin playback of the loaded song'''
|
||||||
ocarina.events.start("ocarina-play")
|
ocarina.events.start("ocarina-play")
|
||||||
|
|
||||||
|
|
||||||
def pause():
|
def pause():
|
||||||
|
'''Pause playback of the current song'''
|
||||||
ocarina.events.start("ocarina-pause")
|
ocarina.events.start("ocarina-pause")
|
||||||
|
|
||||||
|
|
||||||
def stop():
|
def stop():
|
||||||
|
'''Pause playback of the current song and seek to the beginning'''
|
||||||
pause()
|
pause()
|
||||||
seek(0)
|
seek(0)
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
execfile(file)
|
|
@ -4,8 +4,11 @@ __author__="bjschuma"
|
||||||
__date__ ="$Mar 13, 2010 4:32:22 PM$"
|
__date__ ="$Mar 13, 2010 4:32:22 PM$"
|
||||||
|
|
||||||
import ocarina
|
import ocarina
|
||||||
|
|
||||||
global enabled
|
global enabled
|
||||||
|
global lastState
|
||||||
enabled = True
|
enabled = True
|
||||||
|
lastState = True
|
||||||
|
|
||||||
|
|
||||||
def write(s,verbose=0):
|
def write(s,verbose=0):
|
||||||
|
@ -17,9 +20,19 @@ def write(s,verbose=0):
|
||||||
|
|
||||||
def disable():
|
def disable():
|
||||||
global enabled
|
global enabled
|
||||||
|
global lastState
|
||||||
|
lastState = enabled
|
||||||
enabled = False
|
enabled = False
|
||||||
|
|
||||||
|
|
||||||
def enable():
|
def enable():
|
||||||
global enabled
|
global enabled
|
||||||
enabled = True
|
global lastState
|
||||||
|
lastState = enabled
|
||||||
|
enabled = True
|
||||||
|
|
||||||
|
|
||||||
|
def restore():
|
||||||
|
global enabled
|
||||||
|
global lastState
|
||||||
|
enabled = lastState
|
|
@ -0,0 +1,41 @@
|
||||||
|
#! /usr/bin/python
|
||||||
|
|
||||||
|
# To change this template, choose Tools | Templates
|
||||||
|
# and open the template in the editor.
|
||||||
|
|
||||||
|
__author__="bjschuma"
|
||||||
|
__date__ ="$Mar 16, 2010 7:36:48 PM$"
|
||||||
|
|
||||||
|
|
||||||
|
def ftime(time):
|
||||||
|
time = int(time)
|
||||||
|
|
||||||
|
#print time
|
||||||
|
# Find hour
|
||||||
|
length = ""
|
||||||
|
if time >= 3600:
|
||||||
|
hour = time/3600
|
||||||
|
time = time - (hour * 3600)
|
||||||
|
if hour > 0:
|
||||||
|
length=str(hour)+":"
|
||||||
|
# Find minute
|
||||||
|
if time >= 60:
|
||||||
|
min = time/60
|
||||||
|
time = time - (min * 60)
|
||||||
|
if min < 10:
|
||||||
|
length+="0"
|
||||||
|
length+=str(min)+":"
|
||||||
|
else:
|
||||||
|
length+="00:"
|
||||||
|
# Remainder is seconds
|
||||||
|
sec = time
|
||||||
|
if sec < 10:
|
||||||
|
length+="0"
|
||||||
|
length+=str(sec)
|
||||||
|
return length
|
||||||
|
|
||||||
|
|
||||||
|
def ms2str(ms):
|
||||||
|
# Convert ms to s
|
||||||
|
time = int(ms) / 1000000000
|
||||||
|
return ftime(time)
|
|
@ -142,12 +142,13 @@ def seek(prcnt,fraction=False):
|
||||||
if fraction == False:
|
if fraction == False:
|
||||||
prcnt = float(prcnt)
|
prcnt = float(prcnt)
|
||||||
if prcnt < 0:
|
if prcnt < 0:
|
||||||
return
|
return -1
|
||||||
elif prcnt > 100:
|
elif prcnt > 100:
|
||||||
return
|
return -1
|
||||||
prcnt = prcnt / 100.0
|
prcnt = prcnt / 100.0
|
||||||
newTime = duration() * prcnt
|
newTime = duration() * prcnt
|
||||||
player.seek_simple(time,gst.SEEK_FLAG_FLUSH,newTime)
|
player.seek_simple(time,gst.SEEK_FLAG_FLUSH,newTime)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
bus.add_signal_watch()
|
bus.add_signal_watch()
|
||||||
|
|
|
@ -17,6 +17,8 @@ def main():
|
||||||
write("Welcome to Ocarina (core)", 1)
|
write("Welcome to Ocarina (core)", 1)
|
||||||
|
|
||||||
ocarina.events.start("ocarina-start")
|
ocarina.events.start("ocarina-start")
|
||||||
|
ocarina.config()
|
||||||
|
cli.loop()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":main()
|
if __name__ == "__main__":main()
|
||||||
|
|
|
@ -5,32 +5,27 @@ __date__ ="$Mar 13, 2010 4:19:39 PM$"
|
||||||
|
|
||||||
|
|
||||||
from ct.dict import Dict
|
from ct.dict import Dict
|
||||||
from ct import opts
|
|
||||||
from ct import path
|
from ct import path
|
||||||
from ct import call
|
|
||||||
import event
|
import event
|
||||||
|
|
||||||
|
|
||||||
global settings
|
|
||||||
global vars
|
global vars
|
||||||
global events
|
global events
|
||||||
global plugins
|
|
||||||
global alias
|
|
||||||
|
|
||||||
settings = Dict()
|
#settings = Dict()
|
||||||
vars = Dict()
|
vars = Dict()
|
||||||
alias = Dict()
|
#alias = Dict()
|
||||||
events = event.Event()
|
events = event.Event()
|
||||||
plugins = None
|
plugins = None
|
||||||
|
|
||||||
|
'''Attempt to read in a configuration file'''
|
||||||
|
def config():
|
||||||
|
global vars
|
||||||
|
from ct.call import pyfile
|
||||||
|
config = "config.py"
|
||||||
|
pyfile(path.join(vars["$ocarina"],config))
|
||||||
|
pyfile(config)
|
||||||
|
|
||||||
# Set default values
|
#config = "config.py"
|
||||||
def init():
|
#config = path.join(vars["$ocarina"],"config.py")
|
||||||
opts.parse()
|
#from ct.call import pyfile
|
||||||
path.mkdir(vars["$ocarina"])
|
#pyfile(config)
|
||||||
|
|
||||||
# Set verbose value
|
|
||||||
if opts.opts.has("v") == True:
|
|
||||||
vars["$verbose"] += opts.opts["v"]
|
|
||||||
if opts.opts.has("verbose") == True:
|
|
||||||
vars["$verbose"] += opts.opts["verbose"]
|
|
Loading…
Reference in New Issue