Added system calls and documentation. Read a config file on ocarina

startup
This commit is contained in:
bjschuma 2010-03-31 23:03:54 -04:00
parent e9561d5351
commit e0f4eb45bb
11 changed files with 152 additions and 30 deletions

View File

@ -1,4 +1,4 @@
java.lib.path=
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

3
src/config.py Normal file
View File

@ -0,0 +1,3 @@
from ocarina import vars
vars["$verbose"] = 4

View File

@ -11,13 +11,17 @@ import rlcompleter
import ocarina
readline.parse_and_bind("tab:complete")
from ct.call import *
from ct.message import *
def loop():
while True:
try:
enable()
exec raw_input(ocarina.vars["$prompt"] + " ")
restore()
# Catch this so that we can use ctrl-d to exit
except EOFError:
@ -27,4 +31,4 @@ def loop():
print e
ocarina.events.invite("ocarina-start",loop)
#ocarina.events.invite("ocarina-start",loop)

View File

@ -8,6 +8,7 @@ __date__ ="$Mar 15, 2010 9:53:46 PM$"
import ocarina
from ct import path
from ct import opts
from ocarina import vars
@ -20,7 +21,13 @@ vars["$playonload"] = True
vars["$playing"] = False
ocarina.init()
import scripting
import manager
opts.parse()
path.mkdir(vars["$ocarina"])
# 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

View File

@ -2,4 +2,5 @@ __author__="bjschuma"
__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"]

View File

@ -1,33 +1,88 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
'''These are core Ocarina system calls that should help in both development
of future Ocarina features and in usage of ocarina-core'''
__author__="bjschuma"
__date__ ="$Mar 30, 2010 11:24:43 PM$"
import ocarina
from ct import message
from ct import times
from ct import path
def load(path):
'''Load the song located at path'''
import gstreamer
gstreamer.load(path)
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
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():
'''Begin playback of the loaded song'''
ocarina.events.start("ocarina-play")
def pause():
'''Pause playback of the current song'''
ocarina.events.start("ocarina-pause")
def stop():
'''Pause playback of the current song and seek to the beginning'''
pause()
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)

View File

@ -4,8 +4,11 @@ __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):
@ -17,9 +20,19 @@ def write(s,verbose=0):
def disable():
global enabled
global lastState
lastState = enabled
enabled = False
def enable():
global enabled
enabled = True
global lastState
lastState = enabled
enabled = True
def restore():
global enabled
global lastState
enabled = lastState

41
src/core/ct/times.py Normal file
View File

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

View File

@ -142,12 +142,13 @@ def seek(prcnt,fraction=False):
if fraction == False:
prcnt = float(prcnt)
if prcnt < 0:
return
return -1
elif prcnt > 100:
return
return -1
prcnt = prcnt / 100.0
newTime = duration() * prcnt
player.seek_simple(time,gst.SEEK_FLAG_FLUSH,newTime)
return 0
bus.add_signal_watch()

View File

@ -17,6 +17,8 @@ def main():
write("Welcome to Ocarina (core)", 1)
ocarina.events.start("ocarina-start")
ocarina.config()
cli.loop()
if __name__ == "__main__":main()

View File

@ -5,32 +5,27 @@ __date__ ="$Mar 13, 2010 4:19:39 PM$"
from ct.dict import Dict
from ct import opts
from ct import path
from ct import call
import event
global settings
global vars
global events
global plugins
global alias
settings = Dict()
#settings = Dict()
vars = Dict()
alias = Dict()
#alias = Dict()
events = event.Event()
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
def init():
opts.parse()
path.mkdir(vars["$ocarina"])
# 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"]
#config = "config.py"
#config = path.join(vars["$ocarina"],"config.py")
#from ct.call import pyfile
#pyfile(config)