From 964bdd3a058670d0e3cf6f26dbd17d85e19c67f3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 31 Aug 2013 06:28:04 +0000 Subject: dtas-sourcedit: allow loading YAML from stdin This should make it easy to save/load sink profiles depending on the users mood. One could easily create different profiles depending on different listening criteria. dtas-ctl source cat sox > casual.yml dtas-sourceedit sox < critical.yml --- Documentation/dtas-sourceedit.txt | 10 +++++++++- bin/dtas-sourceedit | 31 +++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Documentation/dtas-sourceedit.txt b/Documentation/dtas-sourceedit.txt index 4a47107..9b9fe14 100644 --- a/Documentation/dtas-sourceedit.txt +++ b/Documentation/dtas-sourceedit.txt @@ -12,7 +12,10 @@ dtas-sourceedit {sox | av | ff} # DESCRIPTION dtas-sourceedit spawns an editor to allow editing of a source as a YAML file. -See dtas-player_protocol(7) for details on SOURCEARGS. +See dtas-player_protocol(7) for details on SOURCEARGS. If standard input is +a pipe or file, it is parsed as YAML and fed to the dtas-player(1) instance +non-interactively. This is useful for loading various profiles from the +filesystem. # EXAMPLES @@ -20,6 +23,11 @@ Invoking dtas-sourceedit will spawn your favorite text editor on "sox": $ dtas-sourceedit sox +To load an existing YAML profile for sox. saved.yml could be the output +of a previous "dtas-ctl source cat sox" invocation: + + $ dtas-sourceedit sox < saved.yml + To change the way dtas-player calls avconv (part of libav): $ dtas-sourceedit av diff --git a/bin/dtas-sourceedit b/bin/dtas-sourceedit index a511793..0c8aeb5 100755 --- a/bin/dtas-sourceedit +++ b/bin/dtas-sourceedit @@ -5,22 +5,33 @@ require 'dtas/edit_client' include DTAS::EditClient c = client_socket sources = c.req('source ls') || "(unknown)" -usage = "Usage: #{DTAS_PROGNAME} SOURCENAME\n" \ +usage = "Usage: #{DTAS_PROGNAME} [-n|--dry-run][-V|--verbose] SOURCENAME\n" \ "available SOURCENAME values: #{sources}" + +# use a real option parser if we have anything more complex +dry_run = !!(ARGV.delete('-n') || ARGV.delete('--dry-run')) +verbose = !!(ARGV.delete('-V') || ARGV.delete('--verbose')) + ARGV.size <= 1 or abort usage name = ARGV[0] || "sox" -tmp = tmpyaml +st_in = $stdin.stat + buf = c.req(%W(source cat #{name})) abort(buf) if buf =~ /\AERR/ orig = YAML.load(buf) -tmp.write(buf << DTAS_DISCLAIMER) -cmd = "#{editor} #{tmp.path}" -system(cmd) or abort "#{cmd} failed: #$?" -tmp.rewind -source = YAML.load(tmp.read) +if st_in.file? || st_in.pipe? + tmp = $stdin +else + tmp = tmpyaml + tmp.write(buf << DTAS_DISCLAIMER) + cmd = "#{editor} #{tmp.path}" + system(cmd) or abort "#{cmd} failed: #$?" + tmp.rewind +end +source = YAML.load(tmp.read) cmd = %W(source ed #{name}) update_cmd_env(cmd, orig, source) @@ -29,4 +40,8 @@ update_cmd_env(cmd, orig, source) cmd << "#{field}=#{source[field]}" end -c.req_ok(cmd) +if verbose || dry_run + warn Shellwords.join(cmd) +end + +c.req_ok(cmd) unless dry_run -- cgit v1.2.3-24-ge0c7