scripts: Create an %APP-play for sending play commands

I'm currently using the "ocarina" script as a functions file, but this
will change eventually.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-05-27 23:16:56 -04:00
parent 62c3ef2684
commit d6dff5290f
5 changed files with 72 additions and 33 deletions

View File

@ -26,13 +26,14 @@ if ARGUMENTS.get('VERBOSE') != "1":
env.Append(LINKCOMSTR = "Linking $TARGET")
env.Append(CPPPATH = "include")
Export("env", "MAJOR", "MINOR", "BUG", "EXTRA")
Export("env", "MAJOR", "MINOR", "BUG", "EXTRA", "DEBUG")
def directory(dirs):
objs = []
for dir in dirs:
files = SConscript("%s/Sconscript" % dir)
objs.append(files)
if files:
objs.append(files)
return objs
def symlink(target, source, env):
@ -42,7 +43,8 @@ def symlink(target, source, env):
SConscript(['include/Sconscript'])
ocarina = env.Program('bin/ocarina-player', directory(["libsaria", "ocarina"]))
oc_link = env.Command("ocarina.bin", "bin/ocarina-player", symlink)
Default([ocarina, oc_link])
oc_scripts = directory(["scripts"])
Default([ocarina, oc_link, oc_scripts])
# Install Ocarina
scripts = os.listdir("scripts/")
@ -54,27 +56,6 @@ env.Install(lib, ocarina)
env.Alias("install", [lib, images, bin])
env.Command(images, "./images/", [Copy(images, "./images")])
def process_script(target, source, env):
f = open(target[0].rfile().abspath, "w")
ocarina="ocarina"
saria="saria"
if DEBUG == True:
ocarina = ocarina + "-debug"
saria = saria + "-debug"
for line in open(source[0].rfile().abspath):
line = line.replace("%%BIN%%", baselib + "/ocarina.bin")
line = line.replace("%%OCARINA%%", ocarina)
line = line.replace("%%SARIA%%", saria)
f.write(line)
f.close()
for script in scripts:
if script[0] == ".":
continue
src = "scripts/" + script
dst = bin + script.replace("ocarina", "ocarina" + POSTFIX)
env.Command(dst, src, [process_script, Chmod(dst, 0755)])
# Clean up the build directory
Clean(ocarina, ["include/version.h"])

3
scripts/%APP-play Normal file
View File

@ -0,0 +1,3 @@
#!/bin/bash
. `dirname $0`/ocarina
write_to_pipe "play"

33
scripts/Sconscript Normal file
View File

@ -0,0 +1,33 @@
#!/usr/bin/python
import os
import re
Import( "env", "DEBUG" )
bin = os.path.abspath("../bin/%s")
def create_script(target, source, env):
dst = str(target[0].rfile())
src = str(source[0].rfile())
f = open(dst, "w");
for line in open(src):
line = line.replace("%APP", "ocarina")
line = line.replace("%DEBUG", str(DEBUG))
f.write(line)
f.close()
os.chmod(dst, 0755)
files = []
for file in os.listdir("."):
# SConscript swap files and stuff
if re.search("Sconscript", file):
continue
elif file[0] == ".":
continue
dst = (bin % file).replace("%APP", "ocarina")
print dst
files.append(env.Command(dst, file, create_script))
Return('files')

View File

@ -1,9 +1,33 @@
#!/bin/bash
cmd=`which %%OCARINA%%-$1 2>/dev/null`
args="${@: +2}"
if [ "$cmd" ]; then
$cmd "$args"
else
%%BIN%% "$*"
fi
DEBUG=%DEBUG
function get_app_dir
{
dir="$HOME/.%APP"
if [ "$DEBUG" == "True" ]; then
dir="$dir-debug"
fi
echo $dir
}
function write_to_pipe
{
pipe=`get_app_dir`/pipe
if [ ! -p $pipe ]; then
exit 0
fi
file=`mktemp`
echo "$*" > $file
echo $file > $pipe
rm -f $file
}
#cmd=`which %%OCARINA%%-$1 2>/dev/null`
#args="${@: +2}"
#if [ "$cmd" ]; then
# $cmd "$args"
#else
# %%BIN%% "$*"
#fi

View File

@ -1,2 +0,0 @@
#!/bin/bash
%%OCARINA%%-write-pipe "play"