From d6dff5290f14d08a8231c9322be5faafc4de80c1 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sun, 27 May 2012 23:16:56 -0400 Subject: [PATCH] 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 --- Sconstruct | 29 +++++------------------------ scripts/%APP-play | 3 +++ scripts/Sconscript | 33 +++++++++++++++++++++++++++++++++ scripts/ocarina | 38 +++++++++++++++++++++++++++++++------- scripts/ocarina-play | 2 -- 5 files changed, 72 insertions(+), 33 deletions(-) create mode 100644 scripts/%APP-play create mode 100644 scripts/Sconscript delete mode 100644 scripts/ocarina-play diff --git a/Sconstruct b/Sconstruct index 75478a4f..50667236 100644 --- a/Sconstruct +++ b/Sconstruct @@ -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"]) diff --git a/scripts/%APP-play b/scripts/%APP-play new file mode 100644 index 00000000..ecc9a06b --- /dev/null +++ b/scripts/%APP-play @@ -0,0 +1,3 @@ +#!/bin/bash +. `dirname $0`/ocarina +write_to_pipe "play" diff --git a/scripts/Sconscript b/scripts/Sconscript new file mode 100644 index 00000000..1a8fc727 --- /dev/null +++ b/scripts/Sconscript @@ -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') diff --git a/scripts/ocarina b/scripts/ocarina index e22a5916..829507ee 100644 --- a/scripts/ocarina +++ b/scripts/ocarina @@ -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 diff --git a/scripts/ocarina-play b/scripts/ocarina-play deleted file mode 100644 index 13835a54..00000000 --- a/scripts/ocarina-play +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -%%OCARINA%%-write-pipe "play"